Skip to content

Commit

Permalink
Backward compatibility 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Feb 9, 2018
1 parent 15eab59 commit d169edb
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 4 deletions.
18 changes: 18 additions & 0 deletions Model/Monkey/DddCqrs.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ private function prepare()
'command_delete' => 'Model\\' . $this->entityName . '\\Command\\Delete',
'command_list' => 'Model\\' . $this->entityName . '\\Command\\GetList',

'test_wrapper' => 'Test\\Integration\\' . $this->entityName . '\\TestCaseWrapper',
'test_repository' => 'Test\\Integration\\' . $this->entityName . '\\RepositoryTest',
]);

Expand Down Expand Up @@ -679,6 +680,20 @@ private function getRandomDataGeneratorByType($fieldType)
}
}

/**
* Create test wrapper
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function generateTestCaseWrapper()
{
$this->outFiles['test_wrapper'] = [
'file' => $this->classes['test_wrapper']['file'],
'code' => $this->template->getCodeFromTemplate('ddd-cqrs/Test/Integration/TestCaseWrapper', [
'namespace' => $this->classes['test_wrapper']['info']['namespace'],
]),
];
}

/**
* Build repository tests
* @throws \Magento\Framework\Exception\LocalizedException
Expand Down Expand Up @@ -708,6 +723,8 @@ private function generateRepositoryTest()
'code' => $this->template->getCodeFromTemplate('ddd-cqrs/Test/Integration/Model/RepositoryTest', [
'namespace' => $this->classes['test_repository']['info']['namespace'],
'class' => $this->classes['test_repository']['info']['class_name'],
'test_wrapper' => $this->classes['test_wrapper']['class'],
'test_wrapper_class' => $this->classes['test_wrapper']['info']['class'],
'repository_interface' => $this->classes['repository_interface']['class'],
'data_interface' => $this->classes['data_interface']['class'],
'entity_var' => $this->entityVar,
Expand Down Expand Up @@ -736,6 +753,7 @@ public function execute()
$this->generateRepository();

if ($this->tests) {
$this->generateTestCaseWrapper();
$this->generateRepositoryTest();
}

Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_CodeMonkey" setup_version="1.2.5">
<module name="MSP_CodeMonkey" setup_version="1.2.6">
<sequence>
<module name="MSP_Common"/>

Expand Down
3 changes: 3 additions & 0 deletions templates/ddd-cqrs/Model/Model.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace %namespace%;

use Magento\Framework\Model\AbstractExtensibleModel;

/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
class %class% extends AbstractExtensibleModel implements
%data_interface%
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class %class% extends AbstractCollection
{
protected $_idFieldName = %data_interface%::ID;

/**
* @inheritdoc
*/
protected function _construct()
{
$this->_init(
Expand Down
3 changes: 3 additions & 0 deletions templates/ddd-cqrs/Model/ResourceModel/Resource.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class %class% extends AbstractDb
{
const TABLE_NAME = '%table%';

/**
* @inheritdoc
*/
protected function _construct()
{
$this->_init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ namespace %namespace%;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\AbstractController;
use Magento\Framework\Exception\NoSuchEntityException;
use %test_wrapper%;

/**
* @magentoDbIsolation enabled
*/
class %class% extends AbstractController
class %class% extends %test_wrapper_class%
{
/**
* @var %repository_interface%
Expand All @@ -24,13 +25,16 @@ class %class% extends AbstractController
*/
private $factory;

/**
* @inheritdoc
*/
protected function setUp()
{
// @codingStandardsIgnoreStart
$this->repository = Bootstrap::getObjectManager()->create(
$this->repository = Bootstrap::getObjectManager()->get(
%repository_interface%::class
);
$this->factory = Bootstrap::getObjectManager()->create(
$this->factory = Bootstrap::getObjectManager()->get(
%data_interface%Factory::class
);
// @codingStandardsIgnoreEnd
Expand Down
22 changes: 22 additions & 0 deletions templates/ddd-cqrs/Test/Integration/TestCaseWrapper.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
%header%

declare(strict_types=1);

namespace %namespace%;

/**
* Backward compatibility wrapper for 2.1
*/

// @codingStandardsIgnoreStart
if (!class_exists('\PHPUnit\Framework\TestCase')) {
class TestCaseWrapper extends \PHPUnit_Framework_TestCase {
public function expectException($className) {
return $this->setExpectedException($className);
}
};
} else {
class TestCaseWrapper extends \PHPUnit\Framework\TestCase {};
}
// @codingStandardsIgnoreEnd

0 comments on commit d169edb

Please sign in to comment.