1
0
mirror of synced 2025-01-19 06:51:40 +03:00

#1245 DDC-2504 - constants over string references

This commit is contained in:
Marco Pivetta 2015-01-12 21:37:53 +01:00
parent 7a0cb1c370
commit ec08286173
3 changed files with 23 additions and 15 deletions

View File

@ -7,4 +7,5 @@ namespace Doctrine\Tests\Models\DDC2504;
*/ */
class DDC2504ChildClass extends DDC2504RootClass class DDC2504ChildClass extends DDC2504RootClass
{ {
const CLASSNAME = __CLASS__;
} }

View File

@ -2,11 +2,15 @@
namespace Doctrine\Tests\Models\DDC2504; namespace Doctrine\Tests\Models\DDC2504;
use Doctrine\Common\Collections\ArrayCollection;
/** /**
* @Entity * @Entity
*/ */
class DDC2504OtherClass class DDC2504OtherClass
{ {
const CLASSNAME = __CLASS__;
/** /**
* @Column(type="integer") * @Column(type="integer")
* @Id @GeneratedValue * @Id @GeneratedValue
@ -14,14 +18,16 @@ class DDC2504OtherClass
public $id; public $id;
/** /**
* @var Doctrine\Tests\Models\DDC2504\DDC2504ChildClass * @var \Doctrine\Tests\Models\DDC2504\DDC2504ChildClass
* *
* @OneToMany(targetEntity="DDC2504ChildClass", mappedBy="other", fetch="EXTRA_LAZY") * @OneToMany(targetEntity="DDC2504ChildClass", mappedBy="other", fetch="EXTRA_LAZY")
*
* @var ArrayCollection|\Doctrine\ORM\PersistentCollection
*/ */
public $childClasses; public $childClasses;
public function __construct() public function __construct()
{ {
$this->childClasses = new \Doctrine\Common\Collections\ArrayCollection(); $this->childClasses = new ArrayCollection();
} }
} }

View File

@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Tests\Models\DDC2504\DDC2504ChildClass; use Doctrine\Tests\Models\DDC2504\DDC2504ChildClass;
use Doctrine\Tests\Models\DDC2504\DDC2504OtherClass;
/** /**
* Description of ExtraLazyCollectionTest * Description of ExtraLazyCollectionTest
@ -140,7 +141,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testCountOneToManyJoinedInheritance() public function testCountOneToManyJoinedInheritance()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$this->assertFalse($otherClass->childClasses->isInitialized(), "Pre-Condition"); $this->assertFalse($otherClass->childClasses->isInitialized(), "Pre-Condition");
$this->assertEquals(2, count($otherClass->childClasses)); $this->assertEquals(2, count($otherClass->childClasses));
@ -299,7 +300,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testLazyOneToManyJoinedInheritanceIsLazilyInitialized() public function testLazyOneToManyJoinedInheritanceIsLazilyInitialized()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.'); $this->assertFalse($otherClass->childClasses->isInitialized(), 'Collection is not initialized.');
} }
@ -309,10 +310,10 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWhenMatchingItemIsFound() public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWhenMatchingItemIsFound()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
// Test One to Many existence retrieved from DB // Test One to Many existence retrieved from DB
$childClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504ChildClass', $this->ddc2504ChildClassId); $childClass = $this->_em->find(DDC2504ChildClass::CLASSNAME, $this->ddc2504ChildClassId);
$queryCount = $this->getCurrentQueryCount(); $queryCount = $this->getCurrentQueryCount();
$this->assertTrue($otherClass->childClasses->contains($childClass)); $this->assertTrue($otherClass->childClasses->contains($childClass));
@ -325,7 +326,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testContainsOnOneToManyJoinedInheritanceWillNotCauseQueriesWhenNonPersistentItemIsMatched() public function testContainsOnOneToManyJoinedInheritanceWillNotCauseQueriesWhenNonPersistentItemIsMatched()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$queryCount = $this->getCurrentQueryCount(); $queryCount = $this->getCurrentQueryCount();
$this->assertFalse($otherClass->childClasses->contains(new DDC2504ChildClass())); $this->assertFalse($otherClass->childClasses->contains(new DDC2504ChildClass()));
@ -341,7 +342,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithClearStateMatchingItem() public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithClearStateMatchingItem()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$childClass = new DDC2504ChildClass(); $childClass = new DDC2504ChildClass();
// Test One to Many existence with state clear // Test One to Many existence with state clear
@ -359,7 +360,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithNewStateNotMatchingItem() public function testContainsOnOneToManyJoinedInheritanceWillNotInitializeCollectionWithNewStateNotMatchingItem()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$childClass = new DDC2504ChildClass(); $childClass = new DDC2504ChildClass();
$this->_em->persist($childClass); $this->_em->persist($childClass);
@ -376,7 +377,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testCountingOnOneToManyJoinedInheritanceWillNotInitializeCollection() public function testCountingOnOneToManyJoinedInheritanceWillNotInitializeCollection()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$this->assertEquals(2, count($otherClass->childClasses)); $this->assertEquals(2, count($otherClass->childClasses));
@ -514,11 +515,11 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
*/ */
public function testRemoveElementOneToManyJoinedInheritance() public function testRemoveElementOneToManyJoinedInheritance()
{ {
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$this->assertFalse($otherClass->childClasses->isInitialized(), "Pre-Condition: Collection is not initialized."); $this->assertFalse($otherClass->childClasses->isInitialized(), "Pre-Condition: Collection is not initialized.");
// Test One to Many removal with Entity retrieved from DB // Test One to Many removal with Entity retrieved from DB
$childClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504ChildClass', $this->ddc2504ChildClassId); $childClass = $this->_em->find(DDC2504ChildClass::CLASSNAME, $this->ddc2504ChildClassId);
$queryCount = $this->getCurrentQueryCount(); $queryCount = $this->getCurrentQueryCount();
$otherClass->childClasses->removeElement($childClass); $otherClass->childClasses->removeElement($childClass);
@ -744,10 +745,10 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
public function testContainsKeyIndexByOneToManyJoinedInheritance() public function testContainsKeyIndexByOneToManyJoinedInheritance()
{ {
$class = $this->_em->getClassMetadata('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass'); $class = $this->_em->getClassMetadata(DDC2504OtherClass::CLASSNAME);
$class->associationMappings['childClasses']['indexBy'] = 'id'; $class->associationMappings['childClasses']['indexBy'] = 'id';
$otherClass = $this->_em->find('Doctrine\Tests\Models\DDC2504\DDC2504OtherClass', $this->ddc2504OtherClassId); $otherClass = $this->_em->find(DDC2504OtherClass::CLASSNAME, $this->ddc2504OtherClassId);
$queryCount = $this->getCurrentQueryCount(); $queryCount = $this->getCurrentQueryCount();
@ -917,7 +918,7 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$user1->addPhonenumber($phonenumber1); $user1->addPhonenumber($phonenumber1);
// DDC-2504 // DDC-2504
$otherClass = new \Doctrine\Tests\Models\DDC2504\DDC2504OtherClass(); $otherClass = new DDC2504OtherClass();
$childClass1 = new DDC2504ChildClass(); $childClass1 = new DDC2504ChildClass();
$childClass2 = new DDC2504ChildClass(); $childClass2 = new DDC2504ChildClass();