2009-05-21 08:53:40 +00:00
< ? php
namespace Doctrine\Tests\ORM\Functional ;
2017-05-31 07:59:04 +02:00
use Doctrine\Common\Collections\Criteria ;
2016-12-08 18:01:04 +01:00
use Doctrine\ORM\PersistentCollection ;
use Doctrine\ORM\Proxy\Proxy ;
2017-05-31 07:59:04 +02:00
use Doctrine\Tests\Models\Company\CompanyAuction ;
use Doctrine\Tests\Models\Company\CompanyEmployee ;
use Doctrine\Tests\Models\Company\CompanyEvent ;
use Doctrine\Tests\Models\Company\CompanyManager ;
use Doctrine\Tests\Models\Company\CompanyOrganization ;
use Doctrine\Tests\Models\Company\CompanyPerson ;
use Doctrine\Tests\Models\Company\CompanyRaffle ;
2016-05-11 02:41:26 +07:00
use Doctrine\Tests\OrmFunctionalTestCase ;
2012-06-19 00:01:03 +02:00
2009-05-21 08:53:40 +00:00
/**
2009-05-26 11:30:07 +00:00
* Functional tests for the Class Table Inheritance mapping strategy .
2009-05-21 08:53:40 +00:00
*
* @ author robo
*/
2016-05-11 02:41:26 +07:00
class ClassTableInheritanceTest extends OrmFunctionalTestCase
2009-05-21 08:53:40 +00:00
{
2016-05-11 02:41:26 +07:00
protected function setUp ()
{
2009-05-21 08:53:40 +00:00
$this -> useModelSet ( 'company' );
2017-05-31 07:59:04 +02:00
2009-05-21 08:53:40 +00:00
parent :: setUp ();
}
public function testCRUD ()
2010-03-29 13:20:41 +00:00
{
2009-05-21 08:53:40 +00:00
$person = new CompanyPerson ;
$person -> setName ( 'Roman S. Borschel' );
2011-12-19 22:56:19 +01:00
2009-07-19 16:54:53 +00:00
$this -> _em -> persist ( $person );
2009-05-21 08:53:40 +00:00
$employee = new CompanyEmployee ;
$employee -> setName ( 'Roman S. Borschel' );
$employee -> setSalary ( 100000 );
$employee -> setDepartment ( 'IT' );
2009-07-19 16:54:53 +00:00
$this -> _em -> persist ( $employee );
2009-05-21 08:53:40 +00:00
$employee -> setName ( 'Guilherme Blanco' );
$this -> _em -> flush ();
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
$query = $this -> _em -> createQuery ( 'select p from ' . CompanyPerson :: class . ' p order by p.name desc' );
2009-05-21 08:53:40 +00:00
2009-08-03 17:18:37 +00:00
$entities = $query -> getResult ();
2009-05-21 08:53:40 +00:00
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 2 , $entities );
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyPerson :: class , $entities [ 0 ]);
$this -> assertInstanceOf ( CompanyEmployee :: class , $entities [ 1 ]);
2009-05-21 08:53:40 +00:00
$this -> assertTrue ( is_numeric ( $entities [ 0 ] -> getId ()));
$this -> assertTrue ( is_numeric ( $entities [ 1 ] -> getId ()));
$this -> assertEquals ( 'Roman S. Borschel' , $entities [ 0 ] -> getName ());
$this -> assertEquals ( 'Guilherme Blanco' , $entities [ 1 ] -> getName ());
$this -> assertEquals ( 100000 , $entities [ 1 ] -> getSalary ());
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
$query = $this -> _em -> createQuery ( 'select p from ' . CompanyEmployee :: class . ' p' );
2009-05-21 08:53:40 +00:00
2009-08-03 17:18:37 +00:00
$entities = $query -> getResult ();
2009-05-21 08:53:40 +00:00
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $entities );
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyEmployee :: class , $entities [ 0 ]);
2009-05-21 08:53:40 +00:00
$this -> assertTrue ( is_numeric ( $entities [ 0 ] -> getId ()));
$this -> assertEquals ( 'Guilherme Blanco' , $entities [ 0 ] -> getName ());
$this -> assertEquals ( 100000 , $entities [ 0 ] -> getSalary ());
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2016-12-07 23:33:41 +01:00
$guilherme = $this -> _em -> getRepository ( get_class ( $employee )) -> findOneBy ([ 'name' => 'Guilherme Blanco' ]);
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyEmployee :: class , $guilherme );
2010-03-18 11:40:43 +00:00
$this -> assertEquals ( 'Guilherme Blanco' , $guilherme -> getName ());
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
$query = $this -> _em -> createQuery ( " update " . CompanyEmployee :: class . " p set p.name = ?1, p.department = ?2 where p.name='Guilherme Blanco' and p.salary = ?3 " );
2010-03-29 13:20:41 +00:00
$query -> setParameter ( 1 , 'NewName' , 'string' );
2009-06-23 17:50:13 +00:00
$query -> setParameter ( 2 , 'NewDepartment' );
$query -> setParameter ( 3 , 100000 );
2016-05-11 02:41:26 +07:00
$query -> getSQL ();
2009-06-23 17:50:13 +00:00
$numUpdated = $query -> execute ();
$this -> assertEquals ( 1 , $numUpdated );
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
$query = $this -> _em -> createQuery ( 'delete from ' . CompanyPerson :: class . ' p' );
2009-06-22 18:48:42 +00:00
$numDeleted = $query -> execute ();
$this -> assertEquals ( 2 , $numDeleted );
2009-05-21 08:53:40 +00:00
}
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
public function testMultiLevelUpdateAndFind ()
{
2009-05-26 11:30:07 +00:00
$manager = new CompanyManager ;
$manager -> setName ( 'Roman S. Borschel' );
$manager -> setSalary ( 100000 );
$manager -> setDepartment ( 'IT' );
$manager -> setTitle ( 'CTO' );
2009-07-19 16:54:53 +00:00
$this -> _em -> persist ( $manager );
2009-05-26 11:30:07 +00:00
$this -> _em -> flush ();
2011-12-19 22:56:19 +01:00
2009-05-26 11:30:07 +00:00
$manager -> setName ( 'Roman B.' );
$manager -> setSalary ( 119000 );
$manager -> setTitle ( 'CEO' );
2009-07-19 16:54:53 +00:00
$this -> _em -> persist ( $manager );
2009-05-26 11:30:07 +00:00
$this -> _em -> flush ();
2011-12-19 22:56:19 +01:00
2009-05-26 11:30:07 +00:00
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2016-12-08 18:01:04 +01:00
$manager = $this -> _em -> find ( CompanyManager :: class , $manager -> getId ());
2011-12-19 22:56:19 +01:00
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyManager :: class , $manager );
2009-05-26 11:30:07 +00:00
$this -> assertEquals ( 'Roman B.' , $manager -> getName ());
$this -> assertEquals ( 119000 , $manager -> getSalary ());
$this -> assertEquals ( 'CEO' , $manager -> getTitle ());
$this -> assertTrue ( is_numeric ( $manager -> getId ()));
}
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
public function testFindOnBaseClass ()
{
2009-10-22 19:12:00 +00:00
$manager = new CompanyManager ;
$manager -> setName ( 'Roman S. Borschel' );
$manager -> setSalary ( 100000 );
$manager -> setDepartment ( 'IT' );
$manager -> setTitle ( 'CTO' );
$this -> _em -> persist ( $manager );
$this -> _em -> flush ();
2011-12-19 22:56:19 +01:00
2009-10-22 19:12:00 +00:00
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2016-12-08 18:01:04 +01:00
$person = $this -> _em -> find ( CompanyPerson :: class , $manager -> getId ());
2011-12-19 22:56:19 +01:00
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyManager :: class , $person );
2009-10-22 19:12:00 +00:00
$this -> assertEquals ( 'Roman S. Borschel' , $person -> getName ());
$this -> assertEquals ( 100000 , $person -> getSalary ());
$this -> assertEquals ( 'CTO' , $person -> getTitle ());
$this -> assertTrue ( is_numeric ( $person -> getId ()));
}
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
public function testSelfReferencingOneToOne ()
{
2009-05-26 11:30:07 +00:00
$manager = new CompanyManager ;
$manager -> setName ( 'John Smith' );
$manager -> setSalary ( 100000 );
$manager -> setDepartment ( 'IT' );
$manager -> setTitle ( 'CTO' );
2011-12-19 22:56:19 +01:00
2009-05-26 11:30:07 +00:00
$wife = new CompanyPerson ;
$wife -> setName ( 'Mary Smith' );
$wife -> setSpouse ( $manager );
2011-12-19 22:56:19 +01:00
2009-05-26 11:30:07 +00:00
$this -> assertSame ( $manager , $wife -> getSpouse ());
$this -> assertSame ( $wife , $manager -> getSpouse ());
2011-12-19 22:56:19 +01:00
2009-07-19 16:54:53 +00:00
$this -> _em -> persist ( $manager );
$this -> _em -> persist ( $wife );
2009-05-26 11:30:07 +00:00
$this -> _em -> flush ();
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
$query = $this -> _em -> createQuery ( 'select p, s from ' . CompanyPerson :: class . ' p join p.spouse s where p.name=\'Mary Smith\'' );
2011-12-19 22:56:19 +01:00
2009-08-03 17:18:37 +00:00
$result = $query -> getResult ();
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $result );
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyPerson :: class , $result [ 0 ]);
2009-05-26 11:30:07 +00:00
$this -> assertEquals ( 'Mary Smith' , $result [ 0 ] -> getName ());
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyEmployee :: class , $result [ 0 ] -> getSpouse ());
2009-05-26 15:42:54 +00:00
$this -> assertEquals ( 'John Smith' , $result [ 0 ] -> getSpouse () -> getName ());
$this -> assertSame ( $result [ 0 ], $result [ 0 ] -> getSpouse () -> getSpouse ());
2009-05-26 11:30:07 +00:00
}
2011-12-19 22:56:19 +01:00
2009-06-14 17:34:28 +00:00
public function testSelfReferencingManyToMany ()
{
$person1 = new CompanyPerson ;
$person1 -> setName ( 'Roman' );
2011-12-19 22:56:19 +01:00
2009-06-14 17:34:28 +00:00
$person2 = new CompanyPerson ;
$person2 -> setName ( 'Jonathan' );
2011-12-19 22:56:19 +01:00
2009-06-14 17:34:28 +00:00
$person1 -> addFriend ( $person2 );
2011-12-19 22:56:19 +01:00
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $person1 -> getFriends ());
$this -> assertCount ( 1 , $person2 -> getFriends ());
2011-12-19 22:56:19 +01:00
2009-07-19 16:54:53 +00:00
$this -> _em -> persist ( $person1 );
$this -> _em -> persist ( $person2 );
2011-12-19 22:56:19 +01:00
2009-06-14 17:34:28 +00:00
$this -> _em -> flush ();
2011-12-19 22:56:19 +01:00
2009-06-14 17:34:28 +00:00
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2017-05-31 07:59:04 +02:00
$query = $this -> _em -> createQuery ( 'select p, f from ' . CompanyPerson :: class . ' p join p.friends f where p.name=?1' );
2009-06-14 17:34:28 +00:00
$query -> setParameter ( 1 , 'Roman' );
2011-12-19 22:56:19 +01:00
2009-08-03 17:18:37 +00:00
$result = $query -> getResult ();
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $result );
$this -> assertCount ( 1 , $result [ 0 ] -> getFriends ());
2009-06-14 17:34:28 +00:00
$this -> assertEquals ( 'Roman' , $result [ 0 ] -> getName ());
2011-12-19 22:56:19 +01:00
2009-06-14 17:34:28 +00:00
$friends = $result [ 0 ] -> getFriends ();
$this -> assertEquals ( 'Jonathan' , $friends [ 0 ] -> getName ());
}
2011-12-19 22:56:19 +01:00
2009-09-15 12:24:38 +00:00
public function testLazyLoading1 ()
{
$org = new CompanyOrganization ;
$event1 = new CompanyAuction ;
$event1 -> setData ( 'auction' );
$org -> addEvent ( $event1 );
$event2 = new CompanyRaffle ;
$event2 -> setData ( 'raffle' );
$org -> addEvent ( $event2 );
2011-12-19 22:56:19 +01:00
2009-09-15 12:24:38 +00:00
$this -> _em -> persist ( $org );
$this -> _em -> flush ();
$this -> _em -> clear ();
2011-12-19 22:56:19 +01:00
2009-09-15 12:24:38 +00:00
$orgId = $org -> getId ();
2011-12-19 22:56:19 +01:00
2009-09-15 12:24:38 +00:00
$q = $this -> _em -> createQuery ( 'select a from Doctrine\Tests\Models\Company\CompanyOrganization a where a.id = ?1' );
$q -> setParameter ( 1 , $orgId );
2011-12-19 22:56:19 +01:00
2009-09-15 12:24:38 +00:00
$result = $q -> getResult ();
2011-12-19 22:56:19 +01:00
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $result );
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyOrganization :: class , $result [ 0 ]);
2009-11-03 18:30:21 +00:00
$this -> assertNull ( $result [ 0 ] -> getMainEvent ());
2011-12-19 22:56:19 +01:00
2009-09-15 12:24:38 +00:00
$events = $result [ 0 ] -> getEvents ();
2011-12-19 22:56:19 +01:00
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( PersistentCollection :: class , $events );
2009-09-15 12:24:38 +00:00
$this -> assertFalse ( $events -> isInitialized ());
2011-12-19 22:56:19 +01:00
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 2 , $events );
2009-09-15 12:24:38 +00:00
if ( $events [ 0 ] instanceof CompanyAuction ) {
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyRaffle :: class , $events [ 1 ]);
2009-09-15 12:24:38 +00:00
} else {
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyRaffle :: class , $events [ 0 ]);
$this -> assertInstanceOf ( CompanyAuction :: class , $events [ 1 ]);
2009-09-15 12:24:38 +00:00
}
}
2009-11-03 18:30:21 +00:00
public function testLazyLoading2 ()
{
$org = new CompanyOrganization ;
$event1 = new CompanyAuction ;
$event1 -> setData ( 'auction' );
$org -> setMainEvent ( $event1 );
$this -> _em -> persist ( $org );
$this -> _em -> flush ();
$this -> _em -> clear ();
2017-05-31 07:59:04 +02:00
$q = $this -> _em -> createQuery ( 'select a from ' . CompanyEvent :: class . ' a where a.id = ?1' );
2009-11-03 18:30:21 +00:00
$q -> setParameter ( 1 , $event1 -> getId ());
$result = $q -> getResult ();
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $result );
2017-05-31 07:59:04 +02:00
$this -> assertInstanceOf ( CompanyAuction :: class , $result [ 0 ], sprintf ( " Is of class %s " , get_class ( $result [ 0 ])));
2009-11-03 18:30:21 +00:00
$this -> _em -> clear ();
2017-05-31 07:59:04 +02:00
$q = $this -> _em -> createQuery ( 'select a from ' . CompanyOrganization :: class . ' a where a.id = ?1' );
2009-11-03 18:30:21 +00:00
$q -> setParameter ( 1 , $org -> getId ());
$result = $q -> getResult ();
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $result );
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyOrganization :: class , $result [ 0 ]);
2009-11-03 18:30:21 +00:00
$mainEvent = $result [ 0 ] -> getMainEvent ();
// mainEvent should have been loaded because it can't be lazy
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( CompanyAuction :: class , $mainEvent );
$this -> assertNotInstanceOf ( Proxy :: class , $mainEvent );
2009-11-03 18:30:21 +00:00
}
2011-12-19 22:56:19 +01:00
2010-02-24 22:05:40 +00:00
/**
* @ group DDC - 368
*/
public function testBulkUpdateIssueDDC368 ()
{
2017-05-31 07:59:04 +02:00
$this -> _em -> createQuery ( 'UPDATE ' . CompanyEmployee :: class . ' AS p SET p.salary = 1' )
-> execute ();
2010-02-24 22:05:40 +00:00
2017-05-31 14:05:43 +02:00
$result = $this -> _em -> createQuery ( 'SELECT count(p.id) FROM ' . CompanyEmployee :: class . ' p WHERE p.salary = 1' )
-> getResult ();
$this -> assertGreaterThan ( 0 , count ( $result ));
2011-08-28 13:48:15 -03:00
}
2011-12-19 22:56:19 +01:00
2011-08-28 13:48:15 -03:00
/**
* @ group DDC - 1341
*/
public function testBulkUpdateNonScalarParameterDDC1341 ()
{
2017-05-31 07:59:04 +02:00
$this -> _em -> createQuery ( 'UPDATE ' . CompanyEmployee :: class . ' AS p SET p.startDate = ?0 WHERE p.department = ?1' )
-> setParameter ( 0 , new \DateTime ())
-> setParameter ( 1 , 'IT' )
-> execute ();
2011-08-28 13:48:15 -03:00
2017-05-31 08:05:01 +02:00
$this -> addToAssertionCount ( 1 );
2010-02-24 22:05:40 +00:00
}
2010-07-09 22:55:30 +02:00
/**
* @ group DDC - 130
*/
public function testDeleteJoinTableRecords ()
{
$employee1 = new CompanyEmployee ();
$employee1 -> setName ( 'gblanco' );
$employee1 -> setSalary ( 0 );
$employee1 -> setDepartment ( 'IT' );
$employee2 = new CompanyEmployee ();
$employee2 -> setName ( 'jwage' );
$employee2 -> setSalary ( 0 );
$employee2 -> setDepartment ( 'IT' );
$employee1 -> addFriend ( $employee2 );
$this -> _em -> persist ( $employee1 );
$this -> _em -> persist ( $employee2 );
$this -> _em -> flush ();
2010-07-10 14:04:32 +02:00
$employee1Id = $employee1 -> getId ();
2010-07-09 22:55:30 +02:00
$this -> _em -> remove ( $employee1 );
$this -> _em -> flush ();
2010-07-10 14:04:32 +02:00
$this -> assertNull ( $this -> _em -> find ( get_class ( $employee1 ), $employee1Id ));
2010-07-09 22:55:30 +02:00
}
2010-08-08 14:23:57 +02:00
/**
* @ group DDC - 728
*/
public function testQueryForInheritedSingleValuedAssociation ()
{
$manager = new CompanyManager ();
$manager -> setName ( 'gblanco' );
$manager -> setSalary ( 1234 );
$manager -> setTitle ( 'Awesome!' );
$manager -> setDepartment ( 'IT' );
$person = new CompanyPerson ();
$person -> setName ( 'spouse' );
$manager -> setSpouse ( $person );
$this -> _em -> persist ( $manager );
$this -> _em -> persist ( $person );
$this -> _em -> flush ();
$this -> _em -> clear ();
2017-05-31 07:59:04 +02:00
$dqlManager = $this -> _em -> createQuery ( 'SELECT m FROM ' . CompanyManager :: class . ' m WHERE m.spouse = ?1' )
-> setParameter ( 1 , $person -> getId ())
-> getSingleResult ();
2010-08-08 14:23:57 +02:00
$this -> assertEquals ( $manager -> getId (), $dqlManager -> getId ());
$this -> assertEquals ( $person -> getId (), $dqlManager -> getSpouse () -> getId ());
}
2010-09-27 22:13:14 +02:00
/**
* @ group DDC - 817
*/
public function testFindByAssociation ()
{
$manager = new CompanyManager ();
$manager -> setName ( 'gblanco' );
$manager -> setSalary ( 1234 );
$manager -> setTitle ( 'Awesome!' );
$manager -> setDepartment ( 'IT' );
$person = new CompanyPerson ();
$person -> setName ( 'spouse' );
$manager -> setSpouse ( $person );
$this -> _em -> persist ( $manager );
$this -> _em -> persist ( $person );
$this -> _em -> flush ();
$this -> _em -> clear ();
2016-12-08 18:01:04 +01:00
$repos = $this -> _em -> getRepository ( CompanyManager :: class );
2016-12-07 23:33:41 +01:00
$pmanager = $repos -> findOneBy ([ 'spouse' => $person -> getId ()]);
2010-09-27 22:13:14 +02:00
$this -> assertEquals ( $manager -> getId (), $pmanager -> getId ());
2016-12-08 18:01:04 +01:00
$repos = $this -> _em -> getRepository ( CompanyPerson :: class );
2016-12-07 23:33:41 +01:00
$pmanager = $repos -> findOneBy ([ 'spouse' => $person -> getId ()]);
2010-09-27 22:13:14 +02:00
$this -> assertEquals ( $manager -> getId (), $pmanager -> getId ());
}
2010-10-11 20:11:23 +02:00
/**
* @ group DDC - 834
*/
public function testGetReferenceEntityWithSubclasses ()
{
$manager = new CompanyManager ();
$manager -> setName ( 'gblanco' );
$manager -> setSalary ( 1234 );
$manager -> setTitle ( 'Awesome!' );
$manager -> setDepartment ( 'IT' );
$this -> _em -> persist ( $manager );
$this -> _em -> flush ();
$this -> _em -> clear ();
2016-12-08 18:01:04 +01:00
$ref = $this -> _em -> getReference ( CompanyPerson :: class , $manager -> getId ());
$this -> assertNotInstanceOf ( Proxy :: class , $ref , " Cannot Request a proxy from a class that has subclasses. " );
$this -> assertInstanceOf ( CompanyPerson :: class , $ref );
$this -> assertInstanceOf ( CompanyEmployee :: class , $ref , " Direct fetch of the reference has to load the child class Employee directly. " );
2010-10-11 20:11:23 +02:00
$this -> _em -> clear ();
2016-12-08 18:01:04 +01:00
$ref = $this -> _em -> getReference ( CompanyManager :: class , $manager -> getId ());
$this -> assertInstanceOf ( Proxy :: class , $ref , " A proxy can be generated only if no subclasses exists for the requested reference. " );
2010-10-11 20:11:23 +02:00
}
2011-03-20 17:07:19 +01:00
/**
* @ group DDC - 992
*/
public function testGetSubClassManyToManyCollection ()
{
$manager = new CompanyManager ();
$manager -> setName ( 'gblanco' );
$manager -> setSalary ( 1234 );
$manager -> setTitle ( 'Awesome!' );
$manager -> setDepartment ( 'IT' );
$person = new CompanyPerson ();
$person -> setName ( 'friend' );
$manager -> addFriend ( $person );
$this -> _em -> persist ( $manager );
$this -> _em -> persist ( $person );
$this -> _em -> flush ();
$this -> _em -> clear ();
2016-12-08 18:01:04 +01:00
$manager = $this -> _em -> find ( CompanyManager :: class , $manager -> getId ());
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $manager -> getFriends ());
2011-03-20 17:07:19 +01:00
}
2012-05-27 17:11:21 +02:00
/**
* @ group DDC - 1777
*/
public function testExistsSubclass ()
{
$manager = new CompanyManager ();
$manager -> setName ( 'gblanco' );
$manager -> setSalary ( 1234 );
$manager -> setTitle ( 'Awesome!' );
$manager -> setDepartment ( 'IT' );
$this -> assertFalse ( $this -> _em -> getUnitOfWork () -> getEntityPersister ( get_class ( $manager )) -> exists ( $manager ));
$this -> _em -> persist ( $manager );
$this -> _em -> flush ();
$this -> assertTrue ( $this -> _em -> getUnitOfWork () -> getEntityPersister ( get_class ( $manager )) -> exists ( $manager ));
}
2012-06-19 00:01:03 +02:00
/**
* @ group DDC - 1637
*/
public function testMatching ()
{
$manager = new CompanyManager ();
$manager -> setName ( 'gblanco' );
$manager -> setSalary ( 1234 );
$manager -> setTitle ( 'Awesome!' );
$manager -> setDepartment ( 'IT' );
$this -> _em -> persist ( $manager );
$this -> _em -> flush ();
2016-12-08 18:01:04 +01:00
$repository = $this -> _em -> getRepository ( CompanyEmployee :: class );
2012-06-19 00:01:03 +02:00
$users = $repository -> matching ( new Criteria (
2012-08-01 21:37:22 +02:00
Criteria :: expr () -> eq ( 'department' , 'IT' )
2012-06-19 00:01:03 +02:00
));
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $users );
2012-06-19 00:01:03 +02:00
2016-12-08 18:01:04 +01:00
$repository = $this -> _em -> getRepository ( CompanyManager :: class );
2012-06-19 00:01:03 +02:00
$users = $repository -> matching ( new Criteria (
2012-08-01 21:37:22 +02:00
Criteria :: expr () -> eq ( 'department' , 'IT' )
2012-06-19 00:01:03 +02:00
));
2017-05-31 14:05:43 +02:00
$this -> assertCount ( 1 , $users );
2012-06-19 00:01:03 +02:00
}
2009-05-21 08:53:40 +00:00
}