-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
use PHPUnit\Framework\Attributes\RequiresPhp; | ||
|
||
#[RequiresPhp('8.1')] | ||
class GH11149Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpEntitySchema([ | ||
Locale::class, | ||
Product::class, | ||
ProductTranslation::class, | ||
]); | ||
} | ||
|
||
public function testEagerLoadAssociationIndexedByEntity(): void | ||
{ | ||
$this->_em->persist($product = new Product(11149)); | ||
$this->_em->persist($locale = new Locale('fr_FR')); | ||
$this->_em->persist(new ProductTranslation($product, $locale)); | ||
|
||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$product = $this->_em->find(Product::class, 11149); | ||
static::assertInstanceOf(Product::class, $product); | ||
static::assertCount(1, $product->translations); | ||
|
||
$translation = $product->translations->get('fr_FR'); | ||
static::assertInstanceOf(ProductTranslation::class, $translation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table('gh11149_locale')] | ||
class Locale | ||
{ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'string', enumType: LocaleCode::class)] | ||
public LocaleCode $code; | ||
|
||
public function __construct(string $code) | ||
{ | ||
$this->code = LocaleCode::from($code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
enum LocaleCode: string | ||
{ | ||
case French = 'fr_FR'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table('gh11149_product')] | ||
class Product | ||
{ | ||
#[ORM\Id] | ||
#[ORM\Column(type: 'integer')] | ||
public int $id; | ||
|
||
#[ORM\OneToMany( | ||
targetEntity: ProductTranslation::class, | ||
mappedBy: 'product', | ||
fetch: 'EAGER', | ||
indexBy: 'locale_code', | ||
)] | ||
public Collection $translations; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
$this->translations = new ArrayCollection(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Tests/ORM/Functional/Ticket/GH11149/ProductTranslation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11149; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table('gh11149_product_translation')] | ||
class ProductTranslation | ||
{ | ||
#[ORM\Id] | ||
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'translations')] | ||
#[ORM\JoinColumn(nullable: false)] | ||
public Product $product; | ||
|
||
#[ORM\Id] | ||
#[ORM\ManyToOne(targetEntity: Locale::class)] | ||
#[ORM\JoinColumn(name: 'locale_code', referencedColumnName: 'code', nullable: false)] | ||
public Locale $locale; | ||
|
||
public function __construct(Product $product, Locale $locale) | ||
{ | ||
$this->product = $product; | ||
$this->locale = $locale; | ||
} | ||
} |