-
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.
Failed getting entity with fetch eager property
- Loading branch information
Showing
7 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
<?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"}) | ||
* @ORM\Table(name="test_control") | ||
*/ | ||
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 | ||
{ | ||
} |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table(name="test_user") | ||
*/ | ||
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; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
<?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"}) | ||
* @ORM\Table(name="test_control") | ||
*/ | ||
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 | ||
{ | ||
} |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\AbstractFetchEager\WithoutFetchEager; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity() | ||
* @ORM\Table(name="test_user") | ||
*/ | ||
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; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/Doctrine/Tests/ORM/Functional/AbstractFetchEagerTest.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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
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 Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
final class AbstractFetchEagerTest extends OrmFunctionalTestCase | ||
{ | ||
public function testWithAbstractFetchEager(): void | ||
{ | ||
$this->createSchemaForModels( | ||
AbstractRemoveControl::class, | ||
User::class | ||
); | ||
|
||
$control = new MobileRemoteControl('smart'); | ||
$user = new User($control); | ||
|
||
$this->_em->persist($control); | ||
$this->_em->persist($user); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$user = $this->_em->find(User::class, $user->id); | ||
|
||
self::assertNotNull($user); | ||
self::assertEquals('smart', $user->remoteControl->name); | ||
} | ||
|
||
public function testWithoutAbstractFetchEager(): void | ||
{ | ||
$this->createSchemaForModels( | ||
AbstractRemoveControlWithoutFetchEager::class, | ||
UserWithoutFetchEager::class | ||
); | ||
|
||
$control = new MobileRemoteControlWithoutFetchEager('smart'); | ||
$user = new UserWithoutFetchEager($control); | ||
|
||
$this->_em->persist($control); | ||
$this->_em->persist($user); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$user = $this->_em->find(UserWithoutFetchEager::class, $user->id); | ||
|
||
self::assertNotNull($user); | ||
self::assertEquals('smart', $user->remoteControl->name); | ||
} | ||
} |