forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doctrine#11090 - Fix obtaining an identifier in cases where the hydra…
…tion has not yet fully completed on eagerLoadCollections
- Loading branch information
Showing
8 changed files
with
268 additions
and
1 deletion.
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
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/Models/AbstractFetchEager/WithFetchEager/AbstractRemoveControl.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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\InheritanceType("SINGLE_TABLE") | ||
* @ORM\DiscriminatorColumn(name="type", type="string") | ||
* @ORM\DiscriminatorMap({"mobile"="MobileRemoteControl"}) | ||
*/ | ||
abstract class AbstractRemoveControl | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* /** | ||
* | ||
* @ORM\Column(type="string") | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="User", mappedBy="remoteControl", fetch="EAGER") | ||
* | ||
* @var Collection<User> | ||
*/ | ||
public $users; | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
$this->users = new ArrayCollection(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Doctrine/Tests/Models/AbstractFetchEager/WithFetchEager/MobileRemoteControl.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class MobileRemoteControl extends AbstractRemoveControl | ||
{ | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Doctrine/Tests/Models/AbstractFetchEager/WithFetchEager/User.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class User | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="AbstractRemoveControl", inversedBy="users") | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var AbstractRemoveControl | ||
*/ | ||
public $remoteControl; | ||
|
||
public function __construct(AbstractRemoveControl $control) | ||
{ | ||
$this->remoteControl = $control; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/Models/AbstractFetchEager/WithoutFetchEager/AbstractRemoveControl.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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\InheritanceType("SINGLE_TABLE") | ||
* @ORM\DiscriminatorColumn(name="type", type="string") | ||
* @ORM\DiscriminatorMap({"mobile"="MobileRemoteControl"}) | ||
*/ | ||
abstract class AbstractRemoveControl | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* /** | ||
* | ||
* @ORM\Column(type="string") | ||
* | ||
* @var string | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @ORM\OneToMany(targetEntity="User", mappedBy="remoteControl") | ||
* | ||
* @var Collection<User> | ||
*/ | ||
public $users; | ||
|
||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
$this->users = new ArrayCollection(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/Doctrine/Tests/Models/AbstractFetchEager/WithoutFetchEager/MobileRemoteControl.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class MobileRemoteControl extends AbstractRemoveControl | ||
{ | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/Doctrine/Tests/Models/AbstractFetchEager/WithoutFetchEager/User.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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
*/ | ||
class User | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\GeneratedValue | ||
* @ORM\Column(type="integer") | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="AbstractRemoveControl", inversedBy="users") | ||
* @ORM\JoinColumn(nullable=false) | ||
* | ||
* @var AbstractRemoveControl | ||
*/ | ||
public $remoteControl; | ||
|
||
public function __construct(AbstractRemoveControl $control) | ||
{ | ||
$this->remoteControl = $control; | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\Performance\EntityManagerFactory; | ||
use Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager\AbstractRemoveControl; | ||
use Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager\MobileRemoteControl; | ||
use Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager\User; | ||
use Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager\AbstractRemoveControl as AbstractRemoveControlWithoutFetchEager; | ||
use Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager\MobileRemoteControl as MobileRemoteControlWithoutFetchEager; | ||
use Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager\User as UserWithoutFetchEager; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AbstractFetchEagerTest extends TestCase | ||
{ | ||
public function testWithAbstractFetchEager(): void | ||
{ | ||
$entityManager = EntityManagerFactory::getEntityManager([ | ||
AbstractRemoveControl::class, | ||
User::class, | ||
]); | ||
|
||
$control = new MobileRemoteControl('smart'); | ||
$user = new User($control); | ||
|
||
$entityManager->persist($control); | ||
$entityManager->persist($user); | ||
$entityManager->flush(); | ||
$entityManager->clear(); | ||
|
||
$user = $entityManager->find(User::class, $user->id); | ||
|
||
self::assertNotNull($user); | ||
self::assertEquals('smart', $user->remoteControl->name); | ||
self::assertTrue($user->remoteControl->users->contains($user)); | ||
} | ||
|
||
public function testWithoutAbstractFetchEager(): void | ||
{ | ||
$entityManager = EntityManagerFactory::getEntityManager([ | ||
AbstractRemoveControlWithoutFetchEager::class, | ||
UserWithoutFetchEager::class, | ||
]); | ||
|
||
$control = new MobileRemoteControlWithoutFetchEager('smart'); | ||
$user = new UserWithoutFetchEager($control); | ||
|
||
$entityManager->persist($control); | ||
$entityManager->persist($user); | ||
$entityManager->flush(); | ||
$entityManager->clear(); | ||
|
||
$user = $entityManager->find(UserWithoutFetchEager::class, $user->id); | ||
|
||
self::assertNotNull($user); | ||
self::assertEquals('smart', $user->remoteControl->name); | ||
self::assertTrue($user->remoteControl->users->contains($user)); | ||
} | ||
} |