diff --git a/Application/views/admin/de/oxpsModuleGenerator_admin_de_lang.php b/Application/views/admin/de/oxpsModuleGenerator_admin_de_lang.php index 54d06f5..914857a 100644 --- a/Application/views/admin/de/oxpsModuleGenerator_admin_de_lang.php +++ b/Application/views/admin/de/oxpsModuleGenerator_admin_de_lang.php @@ -110,7 +110,7 @@ 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_MODULE_NAME' => '[TR - MyModule]', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_CONTROLLER_NAME' => '[TR - MyController]', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_MODEL_NAME' => '[TR - MyModel]', - 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_LIST_NAME' => '[TR - MyList]', + 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_LIST_NAME' => '[TR - MyModel]', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_WIDGET_NAME' => '[TR - MyWidget]', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_BLOCK_NAME' => '[TR - my_block_name@page/details/inc/myblockname.tpl]', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_SETTING_NAME' => '[TR - MySetting]', diff --git a/Application/views/admin/en/oxpsModuleGenerator_admin_en_lang.php b/Application/views/admin/en/oxpsModuleGenerator_admin_en_lang.php index 5c231b5..18fdebb 100644 --- a/Application/views/admin/en/oxpsModuleGenerator_admin_en_lang.php +++ b/Application/views/admin/en/oxpsModuleGenerator_admin_en_lang.php @@ -106,7 +106,7 @@ 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_MODULE_NAME' => 'MyModule', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_CONTROLLER_NAME' => 'MyController', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_MODEL_NAME' => 'MyModel', - 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_LIST_NAME' => 'MyList', + 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_LIST_NAME' => 'MyModel', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_WIDGET_NAME' => 'MyWidget', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_BLOCK_NAME' => 'my_block_name@page/details/inc/myblockname.tpl', 'OXPS_MODULEGENERATOR_JS_NOTIFICATION_EXAMPLE_SETTING_NAME' => 'MySetting', diff --git a/Core/Helper.php b/Core/Helper.php index a2b39ef..1932004 100644 --- a/Core/Helper.php +++ b/Core/Helper.php @@ -238,7 +238,12 @@ public function fillTestsFolder( protected function _getPathInsideModule($sModulePath, $mInnerPath) { //cutting the parent class directory (for example /Application/Model/) - $sClassPath = substr($mInnerPath, strpos($mInnerPath, 'source/') + strlen('source/'), strlen($mInnerPath)); + if( strpos($mInnerPath, 'source/') == 0){ + $sClassPath = $mInnerPath; + } + else { + $sClassPath = substr($mInnerPath, strpos($mInnerPath, 'source/') + strlen('source/'), strlen($mInnerPath)); + } if (!empty($sModulePath.$sClassPath) and $this->getFileSystemHelper()->isDir($sModulePath.$sClassPath)) { $sPathInsideModule = $sClassPath; diff --git a/Core/Validator.php b/Core/Validator.php index 4cf96bd..f485288 100644 --- a/Core/Validator.php +++ b/Core/Validator.php @@ -287,7 +287,7 @@ public function moduleExists($sModuleName) /** @var FileSystem $oFileSystemHelper */ $oFileSystemHelper = Registry::get(FileSystem::class); - + return $oFileSystemHelper->isDir($this->getOxModule()->getVendorPath() . $sModuleName) && !empty($sModuleName); } diff --git a/README.md b/README.md index 295c0cd..03b55bb 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,10 @@ Folders structure, empty classes and metadata generation for new OXID eShop modu ## Screenshots - Module generator - ![module generator](out/pictures/module_generator_zoom.png) + ![module generator](out/pictures/newModuleGenerator.png) - Edit mode - ![edit mode](out/pictures/edit_mode.png) + ![edit mode](out/pictures/editModeModuleGenerator.png) ## To do and nice to have features for future releases - Refactor longer classes to move some methods elsewhere diff --git a/out/pictures/editModeModuleGenerator.png b/out/pictures/editModeModuleGenerator.png new file mode 100644 index 0000000..d3b639d Binary files /dev/null and b/out/pictures/editModeModuleGenerator.png differ diff --git a/out/pictures/edit_mode.png b/out/pictures/edit_mode.png deleted file mode 100644 index 5314138..0000000 Binary files a/out/pictures/edit_mode.png and /dev/null differ diff --git a/out/pictures/moduleGenerator.png b/out/pictures/moduleGenerator.png deleted file mode 100644 index 22ee848..0000000 Binary files a/out/pictures/moduleGenerator.png and /dev/null differ diff --git a/out/pictures/module_generator.png b/out/pictures/module_generator.png deleted file mode 100644 index 74a9a3b..0000000 Binary files a/out/pictures/module_generator.png and /dev/null differ diff --git a/out/pictures/module_generator_zoom.png b/out/pictures/module_generator_zoom.png deleted file mode 100644 index c94fa6a..0000000 Binary files a/out/pictures/module_generator_zoom.png and /dev/null differ diff --git a/out/pictures/newModuleGenerator.png b/out/pictures/newModuleGenerator.png new file mode 100644 index 0000000..de9395a Binary files /dev/null and b/out/pictures/newModuleGenerator.png differ diff --git a/out/pictures/oxps_module_generator.png b/out/pictures/oxps_module_generator.png deleted file mode 100644 index bb967d9..0000000 Binary files a/out/pictures/oxps_module_generator.png and /dev/null differ diff --git a/tests/unit/modules/controllers/admin/Admin_oxpsModuleGeneratorTest.php b/tests/unit/modules/controllers/admin/Admin_oxpsModuleGeneratorTest.php index 8163751..0803385 100644 --- a/tests/unit/modules/controllers/admin/Admin_oxpsModuleGeneratorTest.php +++ b/tests/unit/modules/controllers/admin/Admin_oxpsModuleGeneratorTest.php @@ -65,7 +65,7 @@ public function setUp() parent::setUp(); $this->SUT = $this->getMock( - 'Admin_oxpsModuleGenerator', + Admin_oxpsModuleGenerator::class, array('_Admin_oxpsModuleGenerator_init_parent', '_Admin_oxpsModuleGenerator_render_parent') ); @@ -112,7 +112,7 @@ public function testInit() $oModule = $this->SUT->getModule(); - $this->assertInstanceOf('oxpsModuleGeneratorOxModule', $oModule); + $this->assertInstanceOf(OxModule::class, $oModule); $this->assertSame('test', $oModule->getVendorPrefix()); $this->assertSame( array( @@ -464,7 +464,7 @@ public function testGenerateModule_extendedClassesSet_generateModuleSkeletonWith { // Config mock $this->setRequestParameter('modulegenerator_module_name', 'Extended'); - $this->setRequestParameter('modulegenerator_extend_classes', 'oxArticle' . PHP_EOL . 'oxList'); + $this->setRequestParameter('modulegenerator_extend_classes', 'oxArticle'); $this->SUT->init(); $this->SUT->generateModule(); @@ -480,7 +480,6 @@ public function testGenerateModule_extendedClassesSet_generateModuleSkeletonWith $this->assertFileExists($this->_getTestPath('modules/test/Extended/Core/ExtendedModule.php')); $this->assertFileExists($this->_getTestPath('modules/test/Extended/Application/translations/de/testExtended_de_lang.php')); $this->assertFileExists($this->_getTestPath('modules/test/Extended/Application/Model/Article.php')); - $this->assertFileExists($this->_getTestPath('modules/test/Extended/Core/ListModel.php')); // Check metadata content include($this->_getTestPath('modules/test/Extended/metadata.php')); @@ -490,21 +489,16 @@ public function testGenerateModule_extendedClassesSet_generateModuleSkeletonWith $this->assertSame( array( 'OxidEsales\Eshop\Application\Model\Article' => 'Test\Extended\Application\Model\Article', - 'OxidEsales\Eshop\Core\Model\ListModel' => 'Test\Extended\Core\ListModel', ), $aModule['extend'] ); } // Get mock classes so generated classes has something to extend - $this->getMockBuilder(\Test\Extended\Core\ListModel_parent::class)->getMock(); $this->getMockBuilder(\Test\Extended\Application\Model\Article_parent::class)->getMock(); // Check extended class content - $this->assertFalse(class_exists('\Test\Extended\Core\ListModel')); $this->assertFalse(class_exists('\Test\Extended\Application\Model\Article')); - include($this->_getTestPath('modules/test/Extended/Core/ListModel.php')); include($this->_getTestPath('modules/test/Extended/Application/Model/Article.php')); - $this->assertTrue(class_exists('Test\Extended\Core\ListModel')); $this->assertTrue(class_exists('Test\Extended\Application\Model\Article')); } @@ -576,11 +570,10 @@ public function testGenerateModule_controllersSet_generateModuleSkeletonWithCont } // Check controller class content - $this->assertFalse(class_exists('Test\Ctrl1\Application\Controller\Page')); - include($this->_getTestPath('modules/test/Ctrl1/Application/Controller/Page.php')); + require_once($this->_getTestPath('modules/test/Ctrl1/Application/Controller/Page.php')); $this->assertTrue(class_exists('Test\Ctrl1\Application\Controller\Page')); - $oClass = new Test\Ctrl1\Application\Controller\Page(); - $this->assertTrue(method_exists($oClass, Render::class)); + $oClass = new \Test\Ctrl1\Application\Controller\Page(); + $this->assertTrue(method_exists($oClass, 'render')); } public function testGenerateModule_sameControllersSetMultipleTimes_generateModuleSkeletonWithUniqueControllersClasses() @@ -685,11 +678,10 @@ public function testGenerateModule_modelsSet_generateModuleSkeletonWithModelsCla // Check metadata content include($this->_getTestPath('modules/test/Special/metadata.php')); $this->assertTrue(isset($aModule)); - + // Check model class content - $this->assertFalse(class_exists('\Test\Special\Application\Model\Offer')); - include($this->_getTestPath('modules/test/Special/Application/Model/Offer.php')); - $this->assertTrue(class_exists('\Test\Special\Application\Model\Offer')); + require_once($this->_getTestPath('modules/test/Special/Application/Model/Offer.php')); + $this->assertTrue(class_exists('Test\Special\Application\Model\Offer')); $oClass = new \Test\Special\Application\Model\Offer(); $this->assertTrue(method_exists($oClass, '__construct')); } @@ -787,10 +779,9 @@ public function testGenerateModule_widgetsSet_generateModuleSkeletonWithWidgetsC } // Check widget class content - $this->assertFalse(class_exists('test\Wi\Application\Component\Widget\Bar')); - include($this->_getTestPath('modules/test/Wi/Application/Component/Widget/Bar.php')); + require_once($this->_getTestPath('modules/test/Wi/Application/Component/Widget/Bar.php')); $this->assertTrue(class_exists('Test\Wi\Application\Component\Widget\Bar')); - $oClass = new Test\Wi\Application\Component\Widget\Bar(); + $oClass = new \Test\Wi\Application\Component\Widget\Bar(); $this->assertTrue(method_exists($oClass, 'isCacheable')); } @@ -1193,7 +1184,7 @@ public function testGenerateModule_allOptionsSet_generateModuleSkeletonWithAllFe 'email' => 'test@example.com', 'extend' => array( 'OxidEsales\Eshop\Application\Model\Basket' => 'Test\AllThings\Application\Model\Basket', - 'OxidEsales\Eshop\Core\Model\ListModel' => 'Test\AllThings\Core\ListModel', + 'OxidEsales\Eshop\Core\Model\ListModel' => 'Test\AllThings\Core\Model\ListModel', ), 'controllers' => array( 'test_allthings_view' => 'Test\AllThings\Application\Controller\View', @@ -1255,7 +1246,7 @@ public function testGenerateModule_allOptionsSet_generateModuleSkeletonWithAllFe */ protected function _getTestPath($sPathSuffix = '') { - return Registry::getConfig()->getConfigParam('sCompileDir') . DIRECTORY_SEPARATOR . + return Registry::getConfig()->getConfigParam('sCompileDir') . 'test' . DIRECTORY_SEPARATOR . (string) $sPathSuffix; } } diff --git a/tests/unit/modules/core/HelperTest.php b/tests/unit/modules/core/HelperTest.php index 1a5e024..d2f0da0 100644 --- a/tests/unit/modules/core/HelperTest.php +++ b/tests/unit/modules/core/HelperTest.php @@ -57,14 +57,14 @@ public function setUp() { parent::setUp(); - $this->SUT = $this->getMock(Helper::class, array('__call', '_shellExec')); + $this->SUT = $this->getMock(Helper::class, array('_shellExec')); } public function testInit() { // Module instance mock - $oModule = $this->getMock(OxModule::class, array('__construct', '__call')); + $oModule = $this->getMock(OxModule::class, array('__construct')); $this->SUT->init($oModule); @@ -75,7 +75,7 @@ public function testInit() public function testGetModule() { // Module instance mock - $oModule = $this->getMock(OxModule::class, array('__construct', '__call')); + $oModule = $this->getMock(OxModule::class, array('__construct')); $this->SUT->setModule($oModule); @@ -85,7 +85,7 @@ public function testGetModule() public function testGetFileSystemHelper() { - $oFileSystem = $this->getMock(FileSystem::class, array('__call')); + $oFileSystem = $this->getMock(FileSystem::class); Registry::set(FileSystem::class, $oFileSystem); $this->assertSame($oFileSystem, $this->SUT->getFileSystemHelper()); @@ -95,7 +95,7 @@ public function testGetFileSystemHelper() public function testCreateVendorMetadata() { // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'createFolder', 'createFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('createFolder', 'createFile')); $oFileSystem->expects($this->once())->method('createFolder')->with('/path/to/modules/oxps'); $oFileSystem->expects($this->once())->method('createFile')->with( '/path/to/modules/oxps/vendormetadata.php', @@ -115,7 +115,7 @@ public function testCreateVendorMetadata() public function testCreateClassesToExtend_invalidTemplatePath_returnEmptyArray() { // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->once())->method('isFile')->with('/path/to/template.tpl')->will( $this->returnValue(false) ); @@ -126,7 +126,7 @@ public function testCreateClassesToExtend_invalidTemplatePath_returnEmptyArray() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getClassesToExtend', 'getFullPath', 'getModuleId') + array('__construct', 'getClassesToExtend', 'getFullPath', 'getModuleId') ); $oModule->expects($this->once())->method('getClassesToExtend')->will( $this->returnValue( @@ -148,7 +148,7 @@ public function testCreateClassesToExtend_invalidTemplatePath_returnEmptyArray() public function testCreateClassesToExtend_moduleFolderDoesNotExist_returnEmptyArray() { // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->once())->method('isFile')->with('/path/to/template.tpl')->will( $this->returnValue(true) ); @@ -156,12 +156,12 @@ public function testCreateClassesToExtend_moduleFolderDoesNotExist_returnEmptyAr $this->returnValue(false) ); $oFileSystem->expects($this->never())->method('copyFile'); - Registry::set('oxpsModuleGeneratorFileSystem', $oFileSystem); + Registry::set(FileSystem::class, $oFileSystem); // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getClassesToExtend', 'getFullPath', 'getModuleId') + array('__construct', 'getClassesToExtend', 'getFullPath', 'getModuleId') ); $oModule->expects($this->once())->method('getClassesToExtend')->will( $this->returnValue( @@ -183,7 +183,7 @@ public function testCreateClassesToExtend_moduleFolderDoesNotExist_returnEmptyAr public function testCreateClassesToExtend_noClassesToExtend_returnEmptyArray() { // File system helper mock - $oFileSystem = $this->getMock('oxpsModuleGeneratorFileSystem', array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock('oxpsModuleGeneratorFileSystem', array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->once())->method('isFile')->with('/path/to/template.tpl')->will( $this->returnValue(true) ); @@ -196,7 +196,7 @@ public function testCreateClassesToExtend_noClassesToExtend_returnEmptyArray() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getClassesToExtend', 'getFullPath', 'getModuleId') + array('__construct', 'getClassesToExtend', 'getFullPath', 'getModuleId') ); $oModule->expects($this->once())->method('getClassesToExtend')->will($this->returnValue(array())); $oModule->expects($this->once())->method('getFullPath')->will($this->returnValue('/path/to/modules/oxps/mymodule/')); @@ -210,7 +210,7 @@ public function testCreateClassesToExtend_noClassesToExtend_returnEmptyArray() public function testCreateClassesToExtend_templateAndModuleDirAndClassesToExtendAreValid_returnCreatedClassesArray() { // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->at(0))->method('isFile')->with('/path/to/template.tpl')->will( $this->returnValue(true) ); @@ -231,17 +231,17 @@ public function testCreateClassesToExtend_templateAndModuleDirAndClassesToExtend '/path/to/template.tpl', '/path/to/modules/oxps/mymodule/Core/ListModel.php' ); - Registry::set('oxpsModuleGeneratorFileSystem', $oFileSystem); + Registry::set(FileSystem::class, $oFileSystem); // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getClassesToExtend', 'getFullPath', 'getModuleId') + array('__construct', 'getClassesToExtend', 'getFullPath', 'getModuleId') ); $oModule->expects($this->once())->method('getClassesToExtend')->will( $this->returnValue( array( - 'oxarticle' => array( + 'oxArticle' => array( 'classPath' => 'Application/Model/', 'v6ClassName' => 'Article', 'v6Namespace' => 'OxidEsales\Eshop\Application\Model', @@ -281,7 +281,7 @@ public function testCreateNewClassesAndTemplates_noClassesData_returnEmptyArray( // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getClassesToCreate') + array('__construct', 'getClassesToCreate') ); $oModule->expects($this->once())->method('getClassesToCreate')->will($this->returnValue(array())); @@ -295,7 +295,7 @@ public function testCreateNewClassesAndTemplates_noClassesToCreate_returnEmptyAr // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getClassesToCreate') + array('__construct', 'getClassesToCreate') ); $oModule->expects($this->once())->method('getClassesToCreate')->will( $this->returnValue( @@ -336,7 +336,7 @@ public function testCreateNewClassesAndTemplates_thereAreClassesToCreate_returnC // File system helper mock $oFileSystem = $this->getMock( FileSystem::class, - array('__call', 'isFile', 'isDir', 'copyFile', 'createFile') + array('isFile', 'isDir', 'copyFile', 'createFile') ); // For faulty items "Faulty Class" $oFileSystem->expects($this->at(0))->method('isDir') @@ -416,8 +416,8 @@ public function testCreateNewClassesAndTemplates_thereAreClassesToCreate_returnC // Module instance mock $oModule = $this->getMock( - 'oxpsModuleGeneratorOxModule', - array('__construct', '__call', 'getClassesToCreate', 'getModuleId', 'getFullPath', 'getModuleClassName') + OxModule::class, + array('__construct', 'getClassesToCreate', 'getModuleId', 'getFullPath', 'getModuleClassName') ); $oModule->expects($this->once())->method('getClassesToCreate')->will( $this->returnValue( @@ -473,7 +473,7 @@ public function testCreateNewClassesAndTemplates_thereAreClassesToCreate_returnC public function testCreateBlock_noBlocksDefined_noTemplatesCreated() { // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isDir', 'createFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isDir', 'createFile')); $oFileSystem->expects($this->never())->method('isDir'); $oFileSystem->expects($this->never())->method('createFile'); Registry::set(FileSystem::class, $oFileSystem); @@ -481,7 +481,7 @@ public function testCreateBlock_noBlocksDefined_noTemplatesCreated() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getBlocks', 'getModuleId', 'getFullPath', 'getModuleClassName') + array('__construct', 'getBlocks', 'getModuleId', 'getFullPath', 'getModuleClassName') ); $oModule->expects($this->once())->method('getBlocks')->will($this->returnValue(array())); $oModule->expects($this->never())->method('getModuleId'); @@ -496,7 +496,7 @@ public function testCreateBlock_noBlocksDefined_noTemplatesCreated() public function testCreateBlock_blocksAreDefined_callBlockTemplatesCreation() { // File system helper mock - $oFileSystem = $this->getMock('oxpsModuleGeneratorFileSystem', array('__call', 'isDir', 'createFile')); + $oFileSystem = $this->getMock('oxpsModuleGeneratorFileSystem', array('isDir', 'createFile')); $oFileSystem->expects($this->at(0))->method('isDir') ->with('/path/to/modules/oxps/mymodule/Application/views/blocks/') ->will($this->returnValue(true)); @@ -508,12 +508,12 @@ public function testCreateBlock_blocksAreDefined_callBlockTemplatesCreation() '/path/to/modules/oxps/mymodule/Application/views/blocks/oxpsmymodule_footer.tpl', $this->stringContains('footer') ); - Registry::set('oxpsModuleGeneratorFileSystem', $oFileSystem); + Registry::set(FileSystem::class, $oFileSystem); // Module instance mock $oModule = $this->getMock( - 'oxpsModuleGeneratorOxModule', - array('__construct', '__call', 'getBlocks', 'getModuleId', 'getFullPath', 'getModuleClassName') + OxModule::class, + array('__construct', 'getBlocks', 'getModuleId', 'getFullPath', 'getModuleClassName') ); $oModule->expects($this->once())->method('getBlocks')->will( $this->returnValue( @@ -547,7 +547,7 @@ public function testFillTestsFolder_testsGitUrlNotSet_createNoTestClasses() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getFullPath') + array('__construct', 'getFullPath') ); $oModule->expects($this->any()) @@ -555,11 +555,11 @@ public function testFillTestsFolder_testsGitUrlNotSet_createNoTestClasses() ->will($this->returnValue('/path/to/modules/oxps/mymodule/')); // Render helper mock - $oRenderHelper = $this->getMock('render', array('__call', 'renderWithSmartyAndRename')); + $oRenderHelper = $this->getMock(Render::class, array('renderWithSmartyAndRename')); $oRenderHelper->expects($this->never())->method('renderWithSmartyAndRename'); // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); Registry::set(FileSystem::class, $oFileSystem); $this->SUT->init($oModule); @@ -582,7 +582,7 @@ public function testFillTestsFolder_testsFolderNotFetched_createNoTestClasses() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getFullPath') + array('__construct', 'getFullPath') ); $oModule->expects($this->any()) @@ -590,11 +590,11 @@ public function testFillTestsFolder_testsFolderNotFetched_createNoTestClasses() ->will($this->returnValue('/path/to/modules/oxps/mymodule/')); // Render helper mock - $oRenderHelper = $this->getMock(Render::class, array('__call', 'renderWithSmartyAndRename')); + $oRenderHelper = $this->getMock(Render::class, array('renderWithSmartyAndRename')); $oRenderHelper->expects($this->never())->method('renderWithSmartyAndRename'); // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->once())->method('isDir') ->with('/path/to/modules/oxps/mymodule/tests/Unit/') ->will($this->returnValue(false)); @@ -620,7 +620,7 @@ public function testFillTestsFolder_noNewFiles_createNoTestClasses() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getFullPath') + array('__construct', 'getFullPath') ); $oModule->expects($this->any()) @@ -628,11 +628,11 @@ public function testFillTestsFolder_noNewFiles_createNoTestClasses() ->will($this->returnValue('/path/to/modules/oxps/mymodule/')); // Render helper mock - $oRenderHelper = $this->getMock('render', array('__call', 'renderWithSmartyAndRename')); + $oRenderHelper = $this->getMock(Render::class, array('renderWithSmartyAndRename')); $oRenderHelper->expects($this->never())->method('renderWithSmartyAndRename'); // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->at(0))->method('isDir') ->with('/path/to/modules/oxps/mymodule/tests/Unit/') ->will($this->returnValue(true)); @@ -658,7 +658,7 @@ public function testFillTestsFolder_testClassTemplateIsInvalid_createNoTestClass // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getFullPath') + array('__construct', 'getFullPath') ); $oModule->expects($this->any()) @@ -666,11 +666,11 @@ public function testFillTestsFolder_testClassTemplateIsInvalid_createNoTestClass ->will($this->returnValue('/path/to/modules/oxps/mymodule/')); // Render helper mock - $oRenderHelper = $this->getMock('render', array('__call', 'renderWithSmartyAndRename')); + $oRenderHelper = $this->getMock(Render::class, array('renderWithSmartyAndRename')); $oRenderHelper->expects($this->never())->method('renderWithSmartyAndRename'); // File system helper mock - $oFileSystem = $this->getMock(FileSystem::class, array('__call', 'isFile', 'isDir', 'copyFile')); + $oFileSystem = $this->getMock(FileSystem::class, array('isFile', 'isDir', 'copyFile')); $oFileSystem->expects($this->at(0))->method('isDir') ->with('/path/to/modules/oxps/mymodule/tests/Unit/') ->will($this->returnValue(true)); @@ -699,7 +699,7 @@ public function testFillTestsFolder_testsFolderFetchedAllPathsAreValid_createAnd // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getFullPath') + array('__construct', 'getFullPath') ); $oModule->expects($this->any()) @@ -707,7 +707,7 @@ public function testFillTestsFolder_testsFolderFetchedAllPathsAreValid_createAnd ->will($this->returnValue('/path/to/modules/oxps/mymodule/')); // Render helper mock - $oRenderHelper = $this->getMock('render', array('__call', 'renderWithSmartyAndRename')); + $oRenderHelper = $this->getMock(Render::class, array('renderWithSmartyAndRename')); $oRenderHelper->expects($this->once())->method('renderWithSmartyAndRename')->with( array( 'tests/Unit/models/oxpsmymoduleoxarticleTest.php', @@ -724,7 +724,7 @@ public function testFillTestsFolder_testsFolderFetchedAllPathsAreValid_createAnd // File system helper mock $oFileSystem = $this->getMock( FileSystem::class, - array('__call', 'isFile', 'isDir', 'createFolder', 'copyFile', 'createFile', 'renameFile') + array('isFile', 'isDir', 'createFolder', 'copyFile', 'createFile', 'renameFile') ); $oFileSystem->expects($this->at(0))->method('isDir') ->with('/path/to/modules/oxps/mymodule/tests/Unit/') @@ -759,7 +759,7 @@ public function testFillTestsFolder_testsFolderFetchedAllPathsAreValid_createAnd '/path/to/modules/oxps/ModuleGenerator/Core/module.tpl/oxpsTestClass.php.tpl', '/path/to/modules/oxps/mymodule/tests/Unit/models/oxpsmymoduleitemTest.php' ); - Registry::set('oxpsModuleGeneratorFileSystem', $oFileSystem); + Registry::set(FileSystem::class, $oFileSystem); $this->SUT->init($oModule); diff --git a/tests/unit/modules/core/MetadataTest.php b/tests/unit/modules/core/MetadataTest.php index ac30425..3feb7a0 100644 --- a/tests/unit/modules/core/MetadataTest.php +++ b/tests/unit/modules/core/MetadataTest.php @@ -67,6 +67,11 @@ class MetadataTest extends UnitTestCase * @var string */ protected $_sModuleId = 'oxpstestmodule'; + + /** + * Full path to module + * @var string + */ protected $_sModulePath = '/var/www/oxideshop/source/modules/oxps/TestModule'; /** @@ -103,7 +108,7 @@ public function testParseMetadata_parseEmptyMetadata() $oModuleDir = vfsStream::setup($this->_sModuleName); vfsStream::create($aStructure, $oModuleDir); - + $this->assertSame( $aExpectedValue, $this->SUT->parseMetadata($aMetadata, $this->_sVendorPrefix, $this->_sModuleName, $oModuleDir->url()) ); @@ -132,7 +137,8 @@ public function testParseMetadata_parseExtendedClasses() 'OxidEsales\Eshop\Core\Module\Module' => [ 'classPath' =>'Core/', 'v6ClassName' =>'Module', - 'v6Namespace' => 'OxidEsales\Eshop\Core\Module' + 'v6Namespace' => 'OxidEsales\Eshop\Core\Module', + 'v6ModuleNamespace' => 'Core/Module/' ] ], 'aNewControllers' => [], diff --git a/tests/unit/modules/core/OxModuleTest.php b/tests/unit/modules/core/OxModuleTest.php index f3c1721..92660d3 100644 --- a/tests/unit/modules/core/OxModuleTest.php +++ b/tests/unit/modules/core/OxModuleTest.php @@ -33,6 +33,7 @@ use Oxps\ModuleGenerator\Core\Module; use Oxps\ModuleGenerator\Core\OxModule; use Oxps\ModuleGenerator\Core\Render; +use Oxps\ModuleGenerator\Core\Validator; /** * Class OxModuleTest @@ -115,7 +116,7 @@ public function testGetAuthorData_argumentMatchesDataKey_returnArrayValueByTheKe public function testGetValidator() { - $this->assertInstanceOf('oxpsModuleGeneratorValidator', $this->SUT->getValidator()); + $this->assertInstanceOf(Validator::class, $this->SUT->getValidator()); } @@ -526,19 +527,19 @@ public function testGenerateModule() Registry::set(Config::class, $oConfig); // The generator module main class mock - $oGeneratorModule = $this->getMock('oxpsModuleGeneratorModule', array('__construct', '__call', 'getPath')); + $oGeneratorModule = $this->getMock('oxpsModuleGeneratorModule', array('__construct', 'getPath')); Registry::set(Module::class, $oGeneratorModule); // File system helper mock - $oFileSystem = $this->getMock('oxpsModuleGeneratorFileSystem', array('__call', 'copyFolder')); + $oFileSystem = $this->getMock('oxpsModuleGeneratorFileSystem', array('copyFolder')); $oFileSystem->expects($this->once())->method('copyFolder')->with( '/path/to/modules/oxps/ModuleGenerator/Core/module.tpl/module/', '/path/to/modules/oxps/MyModule/' ); // Render helper mock - $oRenderHelper = $this->getMock(Render::class, array('__call', 'init', 'renderModuleFiles')); + $oRenderHelper = $this->getMock(Render::class, array('init', 'renderModuleFiles')); $oRenderHelper->expects($this->once())->method('init')->with($this->isInstanceOf(get_class($this->SUT))); $oRenderHelper->expects($this->once())->method('renderModuleFiles')->with( array('models/oxpsmymoduleoxarticle.php' => 'oxArticle'), @@ -550,7 +551,6 @@ public function testGenerateModule() $oHelper = $this->getMock( Helper::class, array( - '__call', 'init', 'createVendorMetadata', 'getFileSystemHelper', @@ -645,7 +645,7 @@ public function testValidateModuleName_moduleNameValidAndNew_returnTrue() */ public function testGetFileNameSuffix($sFilePath, $sExpectedSuffix) { - $SUT = $this->GetMock(OxModule::class, array('__call', 'getInfo')); + $SUT = $this->GetMock(OxModule::class, array('getInfo')); $SUT->expects($this->any())->method('getInfo') ->will($this->returnValue('oxpsmymodule')) ; @@ -671,7 +671,7 @@ public function filePathsDataProvider() public function testRenderFileComment() { // Render helper mock - $oHelper = $this->getMock(Render::class, array('__call', 'init', 'renderFileComment')); + $oHelper = $this->getMock(Render::class, array('init', 'renderFileComment')); $oHelper->expects($this->once())->method('init')->with($this->isInstanceOf(get_class($this->SUT))); $oHelper->expects($this->once())->method('renderFileComment')->with(''); Registry::set(Render::class, $oHelper); diff --git a/tests/unit/modules/core/RenderTest.php b/tests/unit/modules/core/RenderTest.php index 1b7556a..7ca6270 100644 --- a/tests/unit/modules/core/RenderTest.php +++ b/tests/unit/modules/core/RenderTest.php @@ -64,7 +64,7 @@ public function setUp() public function testInit() { // Module instance mock - $oModule = $this->getMock(OxModule::class, array('__construct', '__call')); + $oModule = $this->getMock(OxModule::class, array('__construct')); $this->SUT->init($oModule); @@ -75,7 +75,7 @@ public function testInit() public function testGetModule() { // Module instance mock - $oModule = $this->getMock(OxModule::class, array('__construct', '__call')); + $oModule = $this->getMock(OxModule::class, array('__construct')); $this->SUT->setModule($oModule); @@ -110,7 +110,7 @@ public function testRenderModuleFiles() // File system helper mock $oFileSystem = $this->getMock( FileSystem::class, - array('__call', 'createFile', 'renameFile', 'isFile') + array('createFile', 'renameFile', 'isFile') ); $oFileSystem->expects($this->any())->method('isFile')->willReturn(true); @@ -144,7 +144,7 @@ public function testRenderModuleFiles() // Module instance mock $oModule = $this->getMock( OxModule::class, - array('__construct', '__call', 'getModuleId', 'getFullPath') + array('__construct', 'getModuleId', 'getFullPath') ); $oModule->expects($this->once()) ->method('getModuleId') @@ -188,7 +188,7 @@ public function testRenderModuleFiles() ->will($this->returnValue('_processed_item_content_')); // View utils mock - $oViewUtils = $this->getMock(UtilsView::class, array('__call', 'getSmarty')); + $oViewUtils = $this->getMock(UtilsView::class, array('getSmarty')); $oViewUtils->expects($this->once())->method('getSmarty')->will($this->returnValue($oSmarty)); Registry::set(UtilsView::class, $oViewUtils, null); @@ -209,7 +209,7 @@ public function testRenderModuleFiles() public function testRenderFileComment_emptyArgument_rendersCommentWithNoSubPackageInfo() { // Module instance mock - $oModule = $this->getMock(OxModule::class, array('__construct', '__call')); + $oModule = $this->getMock(OxModule::class, array('__construct')); // Smarty mock $oSmarty = $this->getMock('Smarty', array('assign', 'fetch')); @@ -219,7 +219,7 @@ public function testRenderFileComment_emptyArgument_rendersCommentWithNoSubPacka ->will($this->returnValue('_processed_comment_content_')); // View utils mock - $oViewUtils = $this->getMock(UtilsView::class, array('__call', 'getSmarty')); + $oViewUtils = $this->getMock(UtilsView::class, array('getSmarty')); $oViewUtils->expects($this->once())->method('getSmarty')->will($this->returnValue($oSmarty)); Registry::set(UtilsView::class, $oViewUtils, null); @@ -231,7 +231,7 @@ public function testRenderFileComment_emptyArgument_rendersCommentWithNoSubPacka public function testRenderFileComment_argumentNotEmpty_rendersCommentWithSubPackageArgumentInfo() { // Module instance mock - $oModule = $this->getMock(OxModule::class, array('__construct', '__call')); + $oModule = $this->getMock(OxModule::class, array('__construct')); // Smarty mock $oSmarty = $this->getMock('Smarty', array('assign', 'fetch')); @@ -242,7 +242,7 @@ public function testRenderFileComment_argumentNotEmpty_rendersCommentWithSubPack ->will($this->returnValue('_processed_comment_content_')); // View utils mock - $oViewUtils = $this->getMock(UtilsView::class, array('__call', 'getSmarty')); + $oViewUtils = $this->getMock(UtilsView::class, array('getSmarty')); $oViewUtils->expects($this->once())->method('getSmarty')->will($this->returnValue($oSmarty)); Registry::set(UtilsView::class, $oViewUtils, null); diff --git a/tests/unit/modules/core/ValidatorTest.php b/tests/unit/modules/core/ValidatorTest.php index a96df71..4ed7bdd 100644 --- a/tests/unit/modules/core/ValidatorTest.php +++ b/tests/unit/modules/core/ValidatorTest.php @@ -27,6 +27,8 @@ namespace Oxps\ModuleGenerator\Tests\Unit\Modules\Core; use OxidEsales\TestingLibrary\UnitTestCase; +use Oxps\ModuleGenerator\Core\Module; +use Oxps\ModuleGenerator\Core\OxModule; use Oxps\ModuleGenerator\Core\Validator; use PHPUnit_Framework_MockObject_MockObject; @@ -38,7 +40,7 @@ */ class ValidatorTest extends UnitTestCase { - + /** * Subject under the test. * @@ -54,17 +56,17 @@ public function setUp() { parent::setUp(); - $this->SUT = $this->getMock('oxpsModuleGeneratorValidator', array('__call')); + $this->SUT = $this->getMock(Validator::class, array('__call')); } public function testGetOxModule() { - $this->assertInstanceOf('oxpsModuleGeneratorOxModule', $this->SUT->getOxModule()); + $this->assertInstanceOf(OxModule::class, $this->SUT->getOxModule()); } public function testGetModule() { - $this->assertInstanceOf('oxpsModuleGeneratorModule', $this->SUT->getModule()); + $this->assertInstanceOf(Module::class, $this->SUT->getModule()); } /** @@ -248,6 +250,8 @@ public function testValidateAndLinkClasses($sValue, $aExpectedResult) public function validateAndLinkClassesDataProvider() { + $path = substr(CORE_AUTOLOADER_PATH,0,strpos(CORE_AUTOLOADER_PATH, 'Core/Autoload')); + return [ // Invalid values ['oxNull', []], @@ -260,23 +264,26 @@ public function validateAndLinkClassesDataProvider() // Valid values ['Article', ['Article' => [ - 'classPath' => 'Application/Controller/Admin/', + 'classPath' => $path.'Application/Controller/Admin/', 'v6ClassName' => 'ArticleController', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Controller\Admin' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Controller\Admin', + 'v6ModuleNamespace' => 'Application/Controller/Admin/' ] ]], ['oxarticle', ['oxarticle' => [ - 'classPath' => 'Application/Model/', + 'classPath' => $path.'Application/Model/', 'v6ClassName' => 'Article', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Model' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Model', + 'v6ModuleNamespace' => 'Application/Model/' ] ]], ['oxArticle', ['oxArticle' => [ - 'classPath' => 'Application/Model/', + 'classPath' => $path.'Application/Model/', 'v6ClassName' => 'Article', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Model' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Model', + 'v6ModuleNamespace' => 'Application/Model/' ] ]], ['oxList', ['oxList' => @@ -284,35 +291,40 @@ public function validateAndLinkClassesDataProvider() 'classPath' => 'Core/', 'v6ClassName' => 'ListModel', 'v6Namespace' => 'OxidEsales\Eshop\Core\Model', + 'v6ModuleNamespace' => 'Core/Model/' ] ]], ['oxBasket', ['oxBasket' => [ - 'classPath' => 'Application/Model/', + 'classPath' => $path.'Application/Model/', 'v6ClassName' => 'Basket', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Model' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Model', + 'v6ModuleNamespace' => 'Application/Model/' ] ]], ['Basket', ['Basket' => [ - 'classPath' => 'Application/Controller/', + 'classPath' => $path.'Application/Controller/', 'v6ClassName' => 'BasketController', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Controller' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Controller', + 'v6ModuleNamespace' => 'Application/Controller/' ] ]], ['oxArticle' . PHP_EOL . 'oxBasket', [ 'oxArticle' => [ - 'classPath' => 'Application/Model/', + 'classPath' => $path.'Application/Model/', 'v6ClassName' => 'Article', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Model' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Model', + 'v6ModuleNamespace' => 'Application/Model/' ], 'oxBasket' => [ - 'classPath' => 'Application/Model/', + 'classPath' => $path.'Application/Model/', 'v6ClassName' => 'Basket', - 'v6Namespace' => 'OxidEsales\Eshop\Application\Model' + 'v6Namespace' => 'OxidEsales\Eshop\Application\Model', + 'v6ModuleNamespace' => 'Application/Model/' ], ] ], @@ -455,8 +467,8 @@ public function testModuleExists($sModuleName, $blExpectedValue) public function moduleExistsDataProvider() { return [ - ['oxps/ModuleGenerator', true], - ['oxps/modulegenerator', false], + ['ModuleGenerator', true], + ['modulegenerator', false], ['NotExistingModule', false], ['', false], [[], false],