Beispiel #1
0
 protected function setUp()
 {
     $this->_generationDirectory = rtrim(self::GENERATION_DIRECTORY, '/') . '/';
     $this->_filesystemDriverMock = $this->getMock('Magento\\Framework\\Filesystem\\Driver\\File', array('isWritable', 'filePutContents', 'createDirectory', 'isExists'), array());
     $this->_autoLoaderMock = $this->getMock('Magento\\Framework\\Autoload\\IncludePath', array('getFilePath'), array(), '', false);
     $this->_autoLoaderMock->expects($this->any())->method('getFilePath')->with(self::CLASS_NAME)->will($this->returnValue(self::CLASS_FILE_NAME));
     $this->_object = new \Magento\Framework\Code\Generator\Io($this->_filesystemDriverMock, $this->_autoLoaderMock, self::GENERATION_DIRECTORY);
 }
Beispiel #2
0
 /**
  * @return bool
  */
 protected function _validateData()
 {
     $sourceClassName = $this->_getSourceClassName();
     $resultClassName = $this->_getResultClassName();
     $resultFileName = $this->_ioObject->getResultFileName($resultClassName);
     // @todo the controller handling logic below must be removed when controllers become PSR-0 compliant
     $controllerSuffix = 'Controller';
     $pathParts = explode('_', $sourceClassName);
     if (strrpos($sourceClassName, $controllerSuffix) === strlen($sourceClassName) - strlen($controllerSuffix) && isset($pathParts[2]) && !in_array($pathParts[2], array('Block', 'Helper', 'Model'))) {
         $controllerPath = preg_replace('/^([0-9A-Za-z]*)_([0-9A-Za-z]*)/', '\\1_\\2_controllers', $sourceClassName);
         $filePath = stream_resolve_include_path(str_replace('_', '/', $controllerPath) . '.php');
         $isSourceClassValid = !empty($filePath);
     } else {
         $isSourceClassValid = $this->_autoloader->getFile($sourceClassName);
     }
     if (!$isSourceClassValid) {
         $this->_addError('Source class ' . $sourceClassName . ' doesn\'t exist.');
         return false;
     } elseif ($this->_autoloader->getFile($resultClassName)) {
         $this->_addError('Result class ' . $resultClassName . ' already exists.');
         return false;
     } elseif (!$this->_ioObject->makeGenerationDirectory()) {
         $this->_addError('Can\'t create directory ' . $this->_ioObject->getGenerationDirectory() . '.');
         return false;
     } elseif (!$this->_ioObject->makeResultFileDirectory($resultClassName)) {
         $this->_addError('Can\'t create directory ' . $this->_ioObject->getResultFileDirectory($resultClassName) . '.');
         return false;
     } elseif ($this->_ioObject->fileExists($resultFileName)) {
         $this->_addError('Result file ' . $resultFileName . ' already exists.');
         return false;
     }
     return true;
 }
 /**
  * Create Object Manager
  *
  * @param array $sharedInstances
  * @return ObjectManager
  */
 public function create(array $sharedInstances = [])
 {
     if (!defined('MTF_BP')) {
         $basePath = str_replace('\\', '/', dirname(__DIR__));
         define('MTF_BP', $basePath);
     }
     if (!defined('MTF_TESTS_PATH')) {
         define('MTF_TESTS_PATH', MTF_BP . '/tests/app/');
     }
     if (!defined('MTF_STATES_PATH')) {
         define('MTF_STATES_PATH', MTF_BP . '/Mtf/App/State/');
     }
     $diConfig = new $this->configClassName();
     $systemConfig = new SystemConfig();
     $configuration = $systemConfig->getConfigParam();
     $diConfig->extend($configuration);
     $directories = isset($arguments[\Magento\Framework\App\Filesystem::PARAM_APP_DIRS]) ? $arguments[\Magento\Framework\App\Filesystem::PARAM_APP_DIRS] : array();
     $directoryList = new \Magento\Framework\App\Filesystem\DirectoryList(realpath(MTF_BP . '../../../../'), $directories);
     \Magento\Framework\Autoload\IncludePath::addIncludePath(array($directoryList->getDir(\Magento\Framework\App\Filesystem::GENERATION_DIR)));
     $factory = new Factory($diConfig);
     $argInterpreter = $this->createArgumentInterpreter(new BooleanUtils());
     $argumentMapper = new \Magento\Framework\ObjectManager\Config\Mapper\Dom($argInterpreter);
     $sharedInstances['Magento\\Framework\\ObjectManager\\Config\\Mapper\\Dom'] = $argumentMapper;
     $objectManager = new $this->locatorClassName($factory, $diConfig, $sharedInstances);
     $factory->setObjectManager($objectManager);
     ObjectManager::setInstance($objectManager);
     self::configure($objectManager);
     return $objectManager;
 }
Beispiel #4
0
 /**
  * Load specified class name and generate it if necessary
  *
  * @param string $className
  * @return void
  */
 public function load($className)
 {
     if (!class_exists($className)) {
         if (Generator::GENERATION_SUCCESS === $this->_generator->generateClass($className)) {
             \Magento\Framework\Autoload\IncludePath::load($className);
         }
     }
 }
Beispiel #5
0
 /**
  * @expectedException \Magento\Framework\Exception
  */
 public function testGenerateClassWithError()
 {
     $this->autoloader->expects($this->once())->method('getFile')->will($this->returnValue(false));
     $this->model = new \Magento\Framework\Code\Generator($this->autoloader, $this->ioObjectMock, array('factory' => '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\Factory', 'proxy' => '\\Magento\\Framework\\ObjectManager\\Code\\Generator\\Proxy', 'interceptor' => '\\Magento\\Framework\\Interception\\Code\\Generator\\Interceptor'));
     $expectedEntities = array_values($this->expectedEntities);
     $resultClassName = self::SOURCE_CLASS . ucfirst(array_shift($expectedEntities));
     $this->model->generateClass($resultClassName);
 }