function it_generates_a_class_with_created_generator() { $this->entityGenerator->init('Some\\Class', 'Some\\ClassEntity')->shouldBeCalled(); $this->entityGenerator->generate()->willReturn('path/to/SomeClassEntity.php')->shouldBeCalled(); $this->beConstructedWith($this->entityFactoryClosure(), 'entity'); $this->generate('Some\\ClassEntity')->shouldReturn('path/to/SomeClassEntity.php'); }
/** * generate repository name */ public function testGenerate() { $generatedCode = 'Generated code'; $resultFileName = $this->getOutputFileName(); //Mocking _validateData call $this->mockDefinedClassesCall(); $this->ioObjectMock->expects($this->once())->method('makeResultFileDirectory')->with($this->getResultClassName())->willReturn(true); //Mocking _generateCode call $this->classGenerator->expects($this->once())->method('setName')->with($this->getResultClassName())->willReturnSelf(); $this->classGenerator->expects($this->once())->method('addProperties')->willReturnSelf(); $this->classGenerator->expects($this->once())->method('addMethods')->willReturnSelf(); $this->classGenerator->expects($this->once())->method('setClassDocBlock')->willReturnSelf(); $this->classGenerator->expects($this->once())->method('generate')->willReturn($generatedCode); //Mocking generation $this->ioObjectMock->expects($this->any())->method('getResultFileName')->with($this->getResultClassName())->willReturn($resultFileName); $this->ioObjectMock->expects($this->once())->method('writeResultFile')->with($resultFileName, $generatedCode); $this->assertEquals($resultFileName, $this->generator->generate(), implode("\n", $this->generator->getErrors())); }
public function testGenerate() { $generatedCode = 'Generated code'; $resultFileName = 'SampleConverter.php'; //Mocking _validateData call $this->definedClassesMock->expects($this->at(0))->method('isClassLoadable')->will($this->returnValue(true)); $this->ioObjectMock->expects($this->once())->method('makeResultFileDirectory')->with(self::RESULT_CLASS_NAME)->will($this->returnValue(true)); //Mocking _generateCode call $this->classGenerator->expects($this->once())->method('setName')->with(self::RESULT_CLASS_NAME)->willReturnSelf(); $this->classGenerator->expects($this->once())->method('addProperties')->willReturnSelf(); $this->classGenerator->expects($this->once())->method('addMethods')->willReturnSelf(); $this->classGenerator->expects($this->once())->method('setClassDocBlock')->willReturnSelf(); $this->classGenerator->expects($this->once())->method('generate')->will($this->returnValue($generatedCode)); //Mocking generation $this->ioObjectMock->expects($this->any())->method('generateResultFileName')->with(self::RESULT_CLASS_NAME)->will($this->returnValue($resultFileName)); $this->ioObjectMock->expects($this->once())->method('writeResultFile')->with($resultFileName, $generatedCode); $this->assertEquals($resultFileName, $this->generator->generate()); }
/** * generate repository name */ public function testGenerate() { $generatedCode = 'Generated code'; $sourceFileName = 'Sample.php'; $resultFileName = self::OUTPUT_FILE_NAME; //Mocking _validateData call $this->autoloaderMock->expects($this->at(0))->method('getFile')->with(self::SOURCE_CLASS_NAME)->will($this->returnValue($sourceFileName)); $this->autoloaderMock->expects($this->at(1))->method('getFile')->with(self::RESULT_CLASS_NAME)->will($this->returnValue(false)); $this->ioObjectMock->expects($this->once())->method('makeGenerationDirectory')->will($this->returnValue(true)); $this->ioObjectMock->expects($this->once())->method('makeResultFileDirectory')->with(self::RESULT_CLASS_NAME)->will($this->returnValue(true)); $this->ioObjectMock->expects($this->once())->method('fileExists')->with($resultFileName)->will($this->returnValue(false)); //Mocking _generateCode call $this->classGenerator->expects($this->once())->method('setName')->with(self::RESULT_CLASS_NAME)->will($this->returnSelf()); $this->classGenerator->expects($this->once())->method('setExtendedClass')->with(SearchResults::SEARCH_RESULT)->will($this->returnSelf()); $this->classGenerator->expects($this->once())->method('addMethods')->will($this->returnSelf()); $this->classGenerator->expects($this->once())->method('generate')->will($this->returnValue($generatedCode)); //Mocking generation $this->ioObjectMock->expects($this->any())->method('getResultFileName')->with(self::RESULT_CLASS_NAME)->will($this->returnValue($resultFileName)); $this->ioObjectMock->expects($this->once())->method('writeResultFile')->with($resultFileName, $generatedCode); $this->assertTrue($this->generator->generate()); }
/** * @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\Framework\Code\Generator\EntityAbstract::generate * @covers \Magento\Framework\Code\Generator\EntityAbstract::getErrors * @covers \Magento\Framework\Code\Generator\EntityAbstract::_getSourceClassName * @covers \Magento\Framework\Code\Generator\EntityAbstract::_getResultClassName * @covers \Magento\Framework\Code\Generator\EntityAbstract::_getDefaultResultClassName * @covers \Magento\Framework\Code\Generator\EntityAbstract::_generateCode * @covers \Magento\Framework\Code\Generator\EntityAbstract::_addError * @covers \Magento\Framework\Code\Generator\EntityAbstract::_validateData * @covers \Magento\Framework\Code\Generator\EntityAbstract::_getClassDocBlock * @covers \Magento\Framework\Code\Generator\EntityAbstract::_getGeneratedCode * @covers \Magento\Framework\Code\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\\Framework\\Code\\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()); } }