| @@ 21-37 (lines=17) @@ | ||
| 18 | ]); |
|
| 19 | } |
|
| 20 | ||
| 21 | public function testInstanceOf() |
|
| 22 | { |
|
| 23 | $this->loadData(); |
|
| 24 | ||
| 25 | $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p |
|
| 26 | WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person'; |
|
| 27 | $query = $this->_em->createQuery($dql); |
|
| 28 | $result = $query->getResult(); |
|
| 29 | ||
| 30 | $this->assertCount(1, $result); |
|
| 31 | ||
| 32 | foreach ($result as $r) { |
|
| 33 | $this->assertInstanceOf(Person::class, $r); |
|
| 34 | $this->assertInstanceOf(Employee::class, $r); |
|
| 35 | $this->assertSame('bar', $r->getName()); |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | private function loadData() |
|
| 40 | { |
|
| @@ 21-40 (lines=20) @@ | ||
| 18 | ]); |
|
| 19 | } |
|
| 20 | ||
| 21 | public function testInstanceOf() |
|
| 22 | { |
|
| 23 | $this->loadData(); |
|
| 24 | ||
| 25 | $dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfTest\Person p |
|
| 26 | WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfTest\Person'; |
|
| 27 | $query = $this->_em->createQuery($dql); |
|
| 28 | $result = $query->getResult(); |
|
| 29 | ||
| 30 | $this->assertCount(2, $result); |
|
| 31 | ||
| 32 | foreach ($result as $r) { |
|
| 33 | $this->assertInstanceOf(Person::class, $r); |
|
| 34 | if ($r instanceof Employee) { |
|
| 35 | $this->assertEquals('bar', $r->getName()); |
|
| 36 | } else { |
|
| 37 | $this->assertEquals('foo', $r->getName()); |
|
| 38 | } |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| 42 | private function loadData() |
|
| 43 | { |
|