1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\Tests\DbalTypes\CustomIdObject;
use Doctrine\Tests\DbalTypes\CustomIdObjectType;
use Doctrine\Tests\Models\CustomType\CustomIdObjectTypeChild;
use Doctrine\Tests\Models\CustomType\CustomIdObjectTypeParent;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\Group;
class CustomIdObjectTypeTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
if (DBALType::hasType(CustomIdObjectType::NAME)) {
DBALType::overrideType(CustomIdObjectType::NAME, CustomIdObjectType::class);
} else {
DBALType::addType(CustomIdObjectType::NAME, CustomIdObjectType::class);
}
$this->useModelSet('custom_id_object_type');
parent::setUp();
}
public function testFindByCustomIdObject(): void
{
$parent = new CustomIdObjectTypeParent(new CustomIdObject('foo'));
$this->_em->persist($parent);
$this->_em->flush();
$result = $this->_em->find(CustomIdObjectTypeParent::class, $parent->id);
self::assertSame($parent, $result);
}
#[Group('DDC-3622')]
#[Group('1336')]
public function testFetchJoinCustomIdObject(): void
{
$parent = new CustomIdObjectTypeParent(new CustomIdObject('foo'));
$parent->children->add(new CustomIdObjectTypeChild(new CustomIdObject('bar'), $parent));
$this->_em->persist($parent);
$this->_em->flush();
$result = $this
->_em
->createQuery(
'SELECT parent, children FROM '
. CustomIdObjectTypeParent::class
. ' parent LEFT JOIN parent.children children',
)
->getResult();
self::assertCount(1, $result);
self::assertSame($parent, $result[0]);
}
#[Group('DDC-3622')]
#[Group('1336')]
public function testFetchJoinWhereCustomIdObject(): void
{
$parent = new CustomIdObjectTypeParent(new CustomIdObject('foo'));
$parent->children->add(new CustomIdObjectTypeChild(new CustomIdObject('bar'), $parent));
$this->_em->persist($parent);
$this->_em->flush();
// note: hydration is willingly broken in this example:
$result = $this
->_em
->createQuery(
'SELECT parent, children FROM '
. CustomIdObjectTypeParent::class
. ' parent LEFT JOIN parent.children children '
. 'WHERE children.id = ?1',
)
->setParameter(1, $parent->children->first()->id)
->getResult();
self::assertCount(1, $result);
self::assertSame($parent, $result[0]);
}
}
|