/** * @test */ public function classBuilderGeneratesIsMethodForBooleanProperty() { $domainObject = $this->buildDomainObject($this->modelName, true, true); $property = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\BooleanProperty('blue'); $property->setRequired(true); $domainObject->addProperty($property); $modelClassObject = $this->classBuilder->generateModelClassFileObject($domainObject, $this->modelClassTemplatePath, false)->getFirstClass(); self::assertTrue($modelClassObject->methodExists('isBlue'), 'No method: isBlue'); }
/** * Generate the appropriate code for a simple model class * for a non aggregate root domain object with one boolean property * * @test */ function generateCodeForModelClassWithBooleanProperty() { $modelName = 'ModelCgt1'; $propertyName = 'blue'; $domainObject = $this->buildDomainObject($modelName); $property = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\BooleanProperty(); $property->setName($propertyName); $property->setRequired(TRUE); $domainObject->addProperty($property); $classFileContent = $this->fileGenerator->generateDomainObjectCode($domainObject, FALSE); $this->assertRegExp("/.*class ModelCgt1.*/", $classFileContent, 'Class declaration was not generated'); $this->assertRegExp('/.*protected \\$blue.*/', $classFileContent, 'protected boolean property was not generated'); $this->assertRegExp('/.*\\* \\@var boolean.*/', $classFileContent, 'var tag for boolean property was not generated'); $this->assertRegExp('/.*\\* \\@validate NotEmpty.*/', $classFileContent, 'validate tag for required property was not generated'); $this->assertRegExp('/.*public function getBlue\\(\\).*/', $classFileContent, 'Getter for boolean property was not generated'); $this->assertRegExp('/.*public function setBlue\\(\\$blue\\).*/', $classFileContent, 'Setter for boolean property was not generated'); $this->assertRegExp('/.*public function isBlue\\(\\).*/', $classFileContent, 'is method for boolean property was not generated'); }
/** * Write a simple model class for a non aggregate root domain obbject * @test */ public function relatedMethodsReflectRenamingAProperty() { $modelName = 'model7'; $this->generateInitialModelClassFile($modelName); // create an "old" domainObject $domainObject = $this->buildDomainObject($modelName); self::assertTrue(is_object($domainObject), 'No domain object'); $property = new StringProperty('prop1'); $uniqueIdentifier1 = md5(microtime() . 'prop1'); $property->setUniqueIdentifier($uniqueIdentifier1); $domainObject->addProperty($property); $uniqueIdentifier2 = md5(microtime() . 'model'); $domainObject->setUniqueIdentifier($uniqueIdentifier2); $this->roundTripService->_set('previousDomainObjects', array($domainObject->getUniqueIdentifier() => $domainObject)); $templateClass = $this->codeTemplateRootPath . 'Classes/Domain/Model/Model.phpt'; // create an "old" class object. $modelClassObject = $this->classBuilder->generateModelClassFileObject($domainObject, $templateClass, false)->getFirstClass(); self::assertTrue(is_object($modelClassObject), 'No class object'); // Check that the getter/methods exist self::assertTrue($modelClassObject->methodExists('getProp1')); self::assertTrue($modelClassObject->methodExists('setProp1')); // set the class object manually, this is usually parsed from an existing class file $this->roundTripService->_set('classObject', $modelClassObject); // build a new domain object with the same unique identifiers $newDomainObject = $this->buildDomainObject('Dummy'); $property = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\BooleanProperty('newProp1Name'); $property->setUniqueIdentifier($uniqueIdentifier1); $property->setRequired(true); $newDomainObject->addProperty($property); $newDomainObject->setUniqueIdentifier($uniqueIdentifier2); // now the slass object should be updated $this->roundTripService->_call('updateModelClassProperties', $domainObject, $newDomainObject); $classObject = $this->roundTripService->_get('classObject'); self::assertTrue($classObject->methodExists('getNewProp1Name')); self::assertTrue($classObject->methodExists('setNewProp1Name')); }
/** * This test is too generic, since it creates the required classes * with a whole fileGenerator->build call * * * @test */ function writeAggregateRootClassesFromDomainObject() { $domainObject = $this->buildDomainObject('ModelCgt7', true, true); $property = new \EBT\ExtensionBuilder\Domain\Model\DomainObject\BooleanProperty('blue'); $property->setRequired(true); $domainObject->addProperty($property); $this->extension->addDomainObject($domainObject); $this->fileGenerator->build($this->extension); $this->assertFileExists($this->extension->getExtensionDir() . 'Classes/Domain/Model/' . $domainObject->getName() . '.php'); $this->assertFileExists($this->extension->getExtensionDir() . 'Classes/Domain/Repository/' . $domainObject->getName() . 'Repository.php'); $this->assertFileExists($this->extension->getExtensionDir() . 'Classes/Controller/' . $domainObject->getName() . 'Controller.php'); }