From d169edbfc0120b137ebc66fa4e4297f831c231c5 Mon Sep 17 00:00:00 2001 From: Riccardo Tempesta Date: Fri, 9 Feb 2018 18:08:01 +0100 Subject: [PATCH] Backward compatibility 2.1 --- Model/Monkey/DddCqrs.php | 18 +++++++++++++++ etc/module.xml | 2 +- templates/ddd-cqrs/Model/Model.template | 3 +++ .../ResourceModel/Model/Collection.template | 3 +++ .../Model/ResourceModel/Resource.template | 3 +++ .../Integration/Model/RepositoryTest.template | 10 ++++++--- .../Test/Integration/TestCaseWrapper.template | 22 +++++++++++++++++++ 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 templates/ddd-cqrs/Test/Integration/TestCaseWrapper.template diff --git a/Model/Monkey/DddCqrs.php b/Model/Monkey/DddCqrs.php index d8e20ca..b60e40a 100755 --- a/Model/Monkey/DddCqrs.php +++ b/Model/Monkey/DddCqrs.php @@ -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', ]); @@ -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 @@ -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, @@ -736,6 +753,7 @@ public function execute() $this->generateRepository(); if ($this->tests) { + $this->generateTestCaseWrapper(); $this->generateRepositoryTest(); } diff --git a/etc/module.xml b/etc/module.xml index cac93e2..a9eff07 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -21,7 +21,7 @@ --> - + diff --git a/templates/ddd-cqrs/Model/Model.template b/templates/ddd-cqrs/Model/Model.template index c551786..8832e79 100755 --- a/templates/ddd-cqrs/Model/Model.template +++ b/templates/ddd-cqrs/Model/Model.template @@ -7,6 +7,9 @@ namespace %namespace%; use Magento\Framework\Model\AbstractExtensibleModel; +/** + * @SuppressWarnings(PHPMD.CamelCaseMethodName) + */ class %class% extends AbstractExtensibleModel implements %data_interface% { diff --git a/templates/ddd-cqrs/Model/ResourceModel/Model/Collection.template b/templates/ddd-cqrs/Model/ResourceModel/Model/Collection.template index 05cbe1b..54cb0e7 100755 --- a/templates/ddd-cqrs/Model/ResourceModel/Model/Collection.template +++ b/templates/ddd-cqrs/Model/ResourceModel/Model/Collection.template @@ -14,6 +14,9 @@ class %class% extends AbstractCollection { protected $_idFieldName = %data_interface%::ID; + /** + * @inheritdoc + */ protected function _construct() { $this->_init( diff --git a/templates/ddd-cqrs/Model/ResourceModel/Resource.template b/templates/ddd-cqrs/Model/ResourceModel/Resource.template index d3d929d..89ba52f 100755 --- a/templates/ddd-cqrs/Model/ResourceModel/Resource.template +++ b/templates/ddd-cqrs/Model/ResourceModel/Resource.template @@ -14,6 +14,9 @@ class %class% extends AbstractDb { const TABLE_NAME = '%table%'; + /** + * @inheritdoc + */ protected function _construct() { $this->_init( diff --git a/templates/ddd-cqrs/Test/Integration/Model/RepositoryTest.template b/templates/ddd-cqrs/Test/Integration/Model/RepositoryTest.template index 76a4eb3..c7e82c8 100755 --- a/templates/ddd-cqrs/Test/Integration/Model/RepositoryTest.template +++ b/templates/ddd-cqrs/Test/Integration/Model/RepositoryTest.template @@ -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% @@ -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 diff --git a/templates/ddd-cqrs/Test/Integration/TestCaseWrapper.template b/templates/ddd-cqrs/Test/Integration/TestCaseWrapper.template new file mode 100644 index 0000000..0a59be4 --- /dev/null +++ b/templates/ddd-cqrs/Test/Integration/TestCaseWrapper.template @@ -0,0 +1,22 @@ +setExpectedException($className); + } + }; +} else { + class TestCaseWrapper extends \PHPUnit\Framework\TestCase {}; +} +// @codingStandardsIgnoreEnd \ No newline at end of file