/** * @expectedException Magento_Exception */ public function testGenerateClassWithError() { $this->_autoloader->staticExpects($this->once())->method('getFile')->will($this->returnValue(false)); $this->_generator->expects($this->once())->method('generate')->will($this->returnValue(false)); $this->_model = new Magento_Di_Generator($this->_generator, $this->_autoloader); $expectedEntities = array_values($this->_expectedEntities); $resultClassName = self::SOURCE_CLASS . ucfirst(array_shift($expectedEntities)); $this->_model->generateClass($resultClassName); }
/** * @param array $errors * @param bool $isGeneration * @param bool $classExistsFirst * @param bool $classExistsSecond * @param bool $makeGeneration * @param bool $makeResultFile * @param bool $fileExists * @param bool $isValid * * @dataProvider generateDataProvider * @covers Magento_Di_Generator_EntityAbstract::generate * @covers Magento_Di_Generator_EntityAbstract::getErrors * @covers Magento_Di_Generator_EntityAbstract::_getSourceClassName * @covers Magento_Di_Generator_EntityAbstract::_getResultClassName * @covers Magento_Di_Generator_EntityAbstract::_getDefaultResultClassName * @covers Magento_Di_Generator_EntityAbstract::_generateCode * @covers Magento_Di_Generator_EntityAbstract::_addError * @covers Magento_Di_Generator_EntityAbstract::_validateData * @covers Magento_Di_Generator_EntityAbstract::_getClassDocBlock * @covers Magento_Di_Generator_EntityAbstract::_getGeneratedCode * @covers Magento_Di_Generator_EntityAbstract::_fixCodeStyle */ public function testGenerate($errors = array(), $isGeneration = true, $classExistsFirst = true, $classExistsSecond = false, $makeGeneration = true, $makeResultFile = true, $fileExists = false, $isValid = true) { if ($isGeneration) { $arguments = $this->_prepareMocksForGenerateCode($isValid); } else { $arguments = $this->_prepareMocksForValidateData($classExistsFirst, $classExistsSecond, $makeGeneration, $makeResultFile, $fileExists); } $abstractGetters = array('_getClassProperties', '_getClassMethods'); $this->_model = $this->getMockForAbstractClass('Magento_Di_Generator_EntityAbstract', $arguments, '', true, true, true, $abstractGetters); // we need to mock abstract methods to set correct return value type foreach ($abstractGetters as $methodName) { $this->_model->expects($this->any())->method($methodName)->will($this->returnValue(array())); } $result = $this->_model->generate(); if ($errors) { $this->assertFalse($result); $this->assertEquals($errors, $this->_model->getErrors()); } else { $this->assertTrue($result); $this->assertEmpty($this->_model->getErrors()); } }