/**
  * Sorts first by primary field, then sorts by property name alphabetically
  * @param Property $a
  * @param Property $b
  * @return int
  */
 protected static function sortByPrimaryAndPropertyNameValue(Property $a, Property $b)
 {
     if ($a->getPrimary() == $b->getPrimary()) {
         //primary field  is set to 1, all not-primary property objects have primary field set to 0.
         return $a->getPropertyName() < $b->getPropertyName() ? -1 : 1;
     }
     return $a->getPrimary() > $b->getPrimary() ? -1 : 1;
 }
 public function testMethodString2getStringFromStrategyOutput()
 {
     $property = new Property();
     $property->setPropertyName("testName");
     $property->setAssociation(2);
     $methodString2 = new MethodString2($property);
     $resultingMethodString = $methodString2->getStringFromStrategy();
     $expectedOutput = "\tpublic function setTestName(\$testName = null) {\n\t\t\$this->testName = \$testName;\n\t\treturn \$this;\n\t}\n\n\tpublic function getTestName() {\n\t\treturn \$this->testName;\n\t}\n\n";
     $this->assertEquals($expectedOutput, $resultingMethodString);
 }
 /**
  * @param Property $property
  * @return string
  */
 protected function makeORMStringForSingleProperty(Property $property)
 {
     $association = $property->getAssociation();
     if (!$association) {
         $association = 0;
     }
     $ormStringObjectName = __NAMESPACE__ . "\\ORMString" . $association;
     $ormStringObject = ORMStringObjectFactory::makeORMStringObject(new $ormStringObjectName(), $property);
     return $ormStringObject->buildString()->getORMString();
 }
 /**
  * @param Property $property
  * @return string
  */
 protected function makeMethodStringForSingleProperty(Property $property)
 {
     $association = $property->getAssociation();
     if (!$association) {
         $association = 0;
     }
     $objectName = __NAMESPACE__ . "\\MethodString" . $association;
     $methodStringObject = new $objectName($property);
     return $methodStringObject->getStringFromStrategy();
 }
 public function testMethodString4getStringFromStrategyOutput()
 {
     $property = new Property();
     $property->setPropertyName("testName");
     $property->setTargetEntity("Application\\Entity\\TestTargetEntity");
     $property->setAssociation(4);
     $methodString4 = new MethodString4($property);
     $resultingMethodString = $methodString4->getStringFromStrategy();
     $expectedOutput = "\tpublic function addToTestName(\\Application\\Entity\\TestTargetEntity \$singleEntity) {\n\t\t\$this->testName->add(\$singleEntity);\n\t\treturn \$this;\n\t}\n\n\tpublic function addTestName(Collection \$testName) {\n\t\tforeach(\$testName as \$singleEntity) {\n\t\t\t\$this->testName->add(\$singleEntity);\n\t\t}\n\t\treturn \$this;\n\t}\n\n\tpublic function removeFromTestName(\\Application\\Entity\\TestTargetEntity \$singleEntity) {\n\t\t\$this->testName->removeElement(\$singleEntity);\n\t\treturn \$this;\n\t}\n\n\tpublic function removeTestName(Collection \$testName) {\n\t\tforeach(\$testName as \$singleEntity) {\n\t\t\t\$this->testName->removeElement(\$singleEntity);\n\t\t}\n\t\treturn \$this;\n\t}\n\n\tpublic function clearTestName() {\n\t\t\$this->testName->clear();\n\t\treturn \$this;\n\t}\n\n\tpublic function getTestName() {\n\t\treturn \$this->testName;\n\t}\n\n\tpublic function setTestName(\$testName) {\n\t\t\$this->clearTestName();\n\t\tforeach(\$testName as \$singleEntity) {\n\t\t\t\$this->addToTestName(\$singleEntity);\n\t\t}\n\t\treturn \$this;\n\t}\n\n";
     $this->assertEquals($expectedOutput, $resultingMethodString);
 }
 public function testMethodString3getStringFromStrategyOutput()
 {
     $property = new Property();
     $property->setPropertyName("testName");
     $property->setTargetEntity("Application\\Entity\\TestTargetEntity");
     $property->setAssociation(3);
     $methodString3 = new MethodString3($property);
     $resultingMethodString = $methodString3->getStringFromStrategy();
     $expectedOutput = "\tpublic function setTestName(\\Application\\Entity\\TestTargetEntity \$testName = null) {\n\t\tif(\$testName == null) {\n\t\t\t\$this->testName->set(null);\n\t\t\t\$this->testName = \$testName;\n\t\t}else {\n\t\t\t\$this->testName = \$testName;\n\t\t\t\$this->testName->set(\$this);\n\t\t}\n\t\treturn \$this;\n\t}\n\n\tpublic function getTestName() {\n\t\treturn \$this->testName;\n\t}\n\n";
     $this->assertEquals($expectedOutput, $resultingMethodString);
 }
 public function testMethodString6getStringFromStrategyOutput()
 {
     $property = new Property();
     $property->setPropertyName("testName");
     $property->setTargetEntity("Application\\Entity\\TestTargetEntity");
     $property->setInverse("testInversedBy");
     $property->setAssociation(6);
     $methodString6 = new MethodString6($property);
     $resultingMethodString = $methodString6->getStringFromStrategy();
     $expectedOutput = "\tpublic function setTestName(\\Application\\Entity\\TestTargetEntity \$testName = null) {\n\t\t\$this->testName = \$testName;\n\t\t(\$this->testName) ? \$this->testName->addToTestInversedBy(\$this) : \$this->testName->removeFromTestInversedBy(\$this);\n\t\treturn \$this;\n\t}\n\n\tpublic function getTestName() {\n\t\treturn \$this->testName;\n\t}\n\n";
     $this->assertEquals($expectedOutput, $resultingMethodString);
 }
 public function __construct(Property $property)
 {
     $this->propertyName = $property->getPropertyName();
     $this->targetEntity = $property->getTargetEntity() ? "\\" . $property->getTargetEntity() . " " : "";
 }
 public function testGetClassDataStringWithPropertyNotBeingACollection()
 {
     $classDataStringCreator = new ClassDataStringCreator();
     $property = new Property();
     $property->setPropertyName("testName");
     $property->setAssociation(6);
     $postData = ['namespace' => 'Application\\Entity', 'classname' => 'Test', 'tablename' => 'tests', 'repositoryclass' => 'Application\\Repositories\\TestRepository', 'indexes' => [0 => ['index' => 'indexName', 'columns' => 'col1, col2, col3']]];
     $doctrineRelationsWithCollection = [4, 5, 8, 9, 10, 12, 14];
     $classDataStringCreator->consumePostData($postData);
     $classDataString = $classDataStringCreator->getClassDataString([0 => $property], $doctrineRelationsWithCollection);
     $expectedOutpuString = "namespace Application\\Entity;\n\nuse Doctrine\\ORM\\Mapping as ORM;\n\n/** \n* @ORM\\Entity(repositoryClass=\"Application\\Repositories\\TestRepository\")\n* @ORM\\Table(name=\"tests\", indexes={\n*\t@ORM\\Index(name=\"indexName\", columns={\"col1\", \"col2\", \"col3\"})\n* })\n*/\n\nclass Test {\n\n";
     $this->assertEquals($expectedOutpuString, $classDataString);
 }