protected function setUp()
 {
     parent::setUp();
     $this->classBuilder = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\ClassBuilder::class, array('dummy'));
     $parserService = new \EBT\ExtensionBuilder\Service\Parser(new \PhpParser\Lexer());
     $printerService = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\Printer::class, array('dummy'));
     $nodeFactory = new \EBT\ExtensionBuilder\Parser\NodeFactory();
     $printerService->_set('nodeFactory', $nodeFactory);
     $configurationManager = new \EBT\ExtensionBuilder\Configuration\ConfigurationManager();
     $this->classBuilder->_set('parserService', $parserService);
     $this->classBuilder->_set('printerService', $printerService);
     $this->classBuilder->_set('configurationManager', $configurationManager);
     $this->classBuilder->initialize($this->extension);
 }
 protected function setUp($settingFile = '')
 {
     if (!class_exists('PHPParser_Parser')) {
         \EBT\ExtensionBuilder\Parser\AutoLoader::register();
     }
     if (!class_exists('PHPParser_Parser')) {
         die('Parser not found!!');
     }
     $this->fixturesPath = PATH_typo3conf . 'ext/extension_builder/Tests/Fixtures/';
     $this->extension = $this->getMock('EBT\\ExtensionBuilder\\Domain\\Model\\Extension', array('getExtensionDir'));
     $extensionKey = 'dummy';
     vfsStream::setup('testDir');
     $dummyExtensionDir = vfsStream::url('testDir') . '/';
     $this->extension->setVendorName('EBT');
     $this->extension->setExtensionKey($extensionKey);
     $this->extension->expects($this->any())->method('getExtensionDir')->will($this->returnValue($dummyExtensionDir));
     if (is_dir($dummyExtensionDir)) {
         GeneralUtility::mkdir($dummyExtensionDir, TRUE);
     }
     $yamlParser = new \EBT\ExtensionBuilder\Utility\SpycYAMLParser();
     $settings = $yamlParser->YAMLLoadString(file_get_contents($this->fixturesPath . 'Settings/settings1.yaml'));
     $this->extension->setSettings($settings);
     $configurationManager = GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Configuration\\ConfigurationManager');
     $this->roundTripService = $this->getMock($this->buildAccessibleProxy('EBT\\ExtensionBuilder\\Service\\RoundTrip'), array('dummy'));
     $this->classBuilder = GeneralUtility::makeInstance('EBT\\ExtensionBuilder\\Service\\ClassBuilder');
     $this->classBuilder->injectConfigurationManager($configurationManager);
     $this->roundTripService->injectClassBuilder($this->classBuilder);
     $this->roundTripService->injectConfigurationManager($configurationManager);
     $this->templateParser = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser'), array('dummy'));
     $this->fileGenerator = $this->getMock($this->buildAccessibleProxy('EBT\\ExtensionBuilder\\Service\\FileGenerator'), array('dummy'));
     $objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
     $this->objectManager = clone $objectManager;
     $this->parserService = new \EBT\ExtensionBuilder\Service\Parser(new \PHPParser_Lexer());
     $this->printerService = new \EBT\ExtensionBuilder\Service\Printer();
     $this->printerService->injectNodeFactory(new \EBT\ExtensionBuilder\Parser\NodeFactory());
     $localizationService = $this->objectManager->get('EBT\\ExtensionBuilder\\Service\\LocalizationService');
     $this->fileGenerator->injectObjectManager($this->objectManager);
     $this->fileGenerator->injectPrinterService($this->printerService);
     $this->fileGenerator->injectLocalizationService($localizationService);
     $this->roundTripService->injectParserService($this->parserService);
     $this->roundTripService->initialize($this->extension);
     $this->classBuilder->injectRoundtripService($this->roundTripService);
     $this->classBuilder->injectParserService($this->parserService);
     $this->classBuilder->injectPrinterService($this->printerService);
     $this->classBuilder->injectClassFactory(new \EBT\ExtensionBuilder\Parser\ClassFactory());
     $this->classBuilder->initialize($this->fileGenerator, $this->extension, TRUE);
     $this->fileGenerator->injectClassBuilder($this->classBuilder);
     $this->codeTemplateRootPath = PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/';
     $this->modelClassTemplatePath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt';
     $this->fileGenerator->setSettings(array('codeTemplateRootPath' => $this->codeTemplateRootPath, 'extConf' => array('enableRoundtrip' => '1')));
     $this->fileGenerator->_set('codeTemplateRootPath', PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/');
     $this->fileGenerator->_set('enableRoundtrip', true);
     $this->fileGenerator->_set('extension', $this->extension);
 }
 public function setUp()
 {
     parent::setUp();
     $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
     if (!class_exists('PhpParser\\Parser')) {
         throw new UnknownClassException('PhpParser not found!!');
     }
     $this->fixturesPath = __DIR__ . '/Fixtures/';
     $testTargetDir = 'testDir';
     vfsStream::setup($testTargetDir);
     $dummyExtensionDir = vfsStream::url($testTargetDir) . '/';
     $yamlParser = new \EBT\ExtensionBuilder\Utility\SpycYAMLParser();
     $settings = $yamlParser->YAMLLoadString(file_get_contents($this->fixturesPath . 'Settings/settings1.yaml'));
     $this->extension = $this->getMock(\EBT\ExtensionBuilder\Domain\Model\Extension::class, array('getExtensionDir'));
     $this->extension->setVendorName('EBT');
     $this->extension->setExtensionKey('dummy');
     $this->extension->expects($this->any())->method('getExtensionDir')->will($this->returnValue($dummyExtensionDir));
     if (is_dir($dummyExtensionDir)) {
         GeneralUtility::mkdir($dummyExtensionDir, TRUE);
     }
     $this->extension->setSettings($settings);
     // get instances to inject in Mocks
     $configurationManager = $this->objectManager->get(\EBT\ExtensionBuilder\Configuration\ConfigurationManager::class);
     $this->parserService = new \EBT\ExtensionBuilder\Service\Parser(new \PhpParser\Lexer());
     $this->printerService = $this->objectManager->get(\EBT\ExtensionBuilder\Service\Printer::class);
     $localizationService = $this->objectManager->get(\EBT\ExtensionBuilder\Service\LocalizationService::class);
     $this->classBuilder = $this->objectManager->get(\EBT\ExtensionBuilder\Service\ClassBuilder::class);
     $this->classBuilder->initialize($this->extension);
     $this->roundTripService = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\RoundTrip::class, array('dummy'));
     $this->inject($this->roundTripService, 'configurationManager', $configurationManager);
     $this->inject($this->roundTripService, 'parserService', $this->parserService);
     $this->roundTripService->initialize($this->extension);
     $this->fileGenerator = $this->getAccessibleMock(\EBT\ExtensionBuilder\Service\FileGenerator::class, array('dummy'));
     $this->inject($this->fileGenerator, 'objectManager', $this->objectManager);
     $this->inject($this->fileGenerator, 'printerService', $this->printerService);
     $this->inject($this->fileGenerator, 'localizationService', $localizationService);
     $this->inject($this->fileGenerator, 'classBuilder', $this->classBuilder);
     $this->inject($this->fileGenerator, 'roundTripService', $this->roundTripService);
     $this->codeTemplateRootPath = PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/';
     $this->modelClassTemplatePath = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt';
     $this->fileGenerator->setSettings(array('codeTemplateRootPath' => $this->codeTemplateRootPath, 'extConf' => array('enableRoundtrip' => '1')));
     $this->fileGenerator->_set('codeTemplateRootPath', __DIR__ . '/../Resources/Private/CodeTemplates/Extbase/');
     $this->fileGenerator->_set('enableRoundtrip', true);
     $this->fileGenerator->_set('extension', $this->extension);
 }
Beispiel #4
0
 /**
  * generate all domainObject related
  * files like PHP class files, templates etc.
  *
  * @throws \Exception
  */
 protected function generateDomainObjectRelatedFiles()
 {
     if (count($this->extension->getDomainObjects()) > 0) {
         $this->classBuilder->initialize($this->extension);
         // Generate Domain Model
         try {
             $domainModelDirectory = 'Classes/Domain/Model/';
             $this->mkdir_deep($this->extensionDirectory, $domainModelDirectory);
             $domainRepositoryDirectory = 'Classes/Domain/Repository/';
             $this->mkdir_deep($this->extensionDirectory, $domainRepositoryDirectory);
             $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Domain/Model');
             $domainModelTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Domain/Model/';
             $this->mkdir_deep($this->extensionDirectory, 'Tests/Unit/Controller');
             $crudEnabledControllerTestsDirectory = $this->extensionDirectory . 'Tests/Unit/Controller/';
             foreach ($this->extension->getDomainObjects() as $domainObject) {
                 /**
                  * @var \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject
                  */
                 $destinationFile = $domainModelDirectory . $domainObject->getName() . '.php';
                 if ($this->fileShouldBeMerged($destinationFile)) {
                     $mergeWithExistingClass = true;
                 } else {
                     $mergeWithExistingClass = false;
                 }
                 $fileContents = $this->generateDomainObjectCode($domainObject, $mergeWithExistingClass);
                 $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                 GeneralUtility::devlog('Generated ' . $domainObject->getName() . '.php', 'extension_builder', 0);
                 $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 if ($domainObject->isAggregateRoot()) {
                     $iconFileName = 'aggregate_root.gif';
                 } elseif ($domainObject->isEntity()) {
                     $iconFileName = 'entity.gif';
                 } else {
                     $iconFileName = 'value_object.gif';
                 }
                 $this->upload_copy_move(ExtensionManagementUtility::extPath('extension_builder') . 'Resources/Private/Icons/' . $iconFileName, $this->iconsDirectory . $domainObject->getDatabaseTableName() . '.gif');
                 if ($domainObject->isAggregateRoot()) {
                     $destinationFile = $domainRepositoryDirectory . $domainObject->getName() . 'Repository.php';
                     if ($this->fileShouldBeMerged($destinationFile)) {
                         $mergeWithExistingClass = true;
                     } else {
                         $mergeWithExistingClass = false;
                     }
                     $fileContents = $this->generateDomainRepositoryCode($domainObject, $mergeWithExistingClass);
                     $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                     GeneralUtility::devlog('Generated ' . $domainObject->getName() . 'Repository.php', 'extension_builder', 0);
                     $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 }
                 // Generate basic UnitTests
                 $fileContents = $this->generateDomainModelTests($domainObject);
                 $this->writeFile($domainModelTestsDirectory . $domainObject->getName() . 'Test.php', $fileContents);
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not generate domain model, error: ' . $e->getMessage());
         }
         // Generate Action Controller
         try {
             $this->mkdir_deep($this->extensionDirectory, 'Classes/Controller');
             $controllerDirectory = 'Classes/Controller/';
             foreach ($this->extension->getDomainObjectsForWhichAControllerShouldBeBuilt() as $domainObject) {
                 $destinationFile = $controllerDirectory . $domainObject->getName() . 'Controller.php';
                 if ($this->fileShouldBeMerged($destinationFile)) {
                     $mergeWithExistingClass = true;
                 } else {
                     $mergeWithExistingClass = false;
                 }
                 $fileContents = $this->generateActionControllerCode($domainObject, $mergeWithExistingClass);
                 $this->writeFile($this->extensionDirectory . $destinationFile, $fileContents);
                 GeneralUtility::devlog('Generated ' . $domainObject->getName() . 'Controller.php', 'extension_builder', 0);
                 $this->extension->setMD5Hash($this->extensionDirectory . $destinationFile);
                 // Generate basic UnitTests
                 $fileContents = $this->generateControllerTests($domainObject->getName() . 'Controller', $domainObject);
                 $this->writeFile($crudEnabledControllerTestsDirectory . $domainObject->getName() . 'ControllerTest.php', $fileContents);
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not generate action controller, error: ' . $e->getMessage());
         }
         // Generate Domain Templates
         try {
             if ($this->extension->getPlugins()) {
                 $this->generateTemplateFiles();
             }
             if ($this->extension->getBackendModules()) {
                 $this->generateTemplateFiles('Backend/');
             }
         } catch (\Exception $e) {
             throw new \Exception('Could not generate domain templates, error: ' . $e->getMessage());
         }
         try {
             $settings = $this->extension->getSettings();
         } catch (\Exception $e) {
             throw new \Exception('Could not generate ext_autoload.php, error: ' . $e->getMessage());
         }
     } else {
         GeneralUtility::devlog('No domainObjects in this extension', 'extension_builder', 3, (array) $this->extension);
     }
 }