-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ClosureHydrator
now will try to load relation from Heap; also it wi…
…ll write Reference into `mixed` property instead of relation loading (#429)
- Loading branch information
Showing
3 changed files
with
72 additions
and
14 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
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
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 |
---|---|---|
|
@@ -24,7 +24,7 @@ public function setUp(): void | |
{ | ||
parent::setUp(); | ||
|
||
$this->makeTable('user', ['id' => 'primary', 'email' => 'string']); | ||
$this->makeTable('user', ['id' => 'primary', 'email' => 'string', 'friend_id' => 'integer,nullable']); | ||
$this->makeTable('profile', ['id' => 'primary', 'name' => 'string', 'user_id' => 'integer']); | ||
$this->makeTable('tag', ['id' => 'primary', 'name' => 'string',]); | ||
$this->makeTable('tag_user', ['user_id' => 'integer', 'tag_id' => 'integer',]); | ||
|
@@ -210,10 +210,38 @@ public function setUp(): void | |
], | ||
], | ||
], | ||
EntityWithMixedTypeRelation::class => [ | ||
Schema::ROLE => 'mixed_type', | ||
Schema::MAPPER => Mapper::class, | ||
Schema::DATABASE => 'default', | ||
Schema::TABLE => 'user', | ||
Schema::PRIMARY_KEY => 'id', | ||
Schema::COLUMNS => [ | ||
'id' => 'id', | ||
'email' => 'email', | ||
'friend_id' => 'friend_id', | ||
], | ||
Schema::TYPECAST => ['id' => 'int', 'friend_id' => 'int'], | ||
Schema::SCHEMA => [], | ||
Schema::RELATIONS => [ | ||
'friend' => [ | ||
Relation::TYPE => Relation::BELONGS_TO, | ||
Relation::TARGET => EntityWithMixedTypeRelation::class, | ||
Relation::LOAD => Relation::LOAD_PROMISE, | ||
|
||
Relation::SCHEMA => [ | ||
Relation::NULLABLE => false, | ||
Relation::CASCADE => true, | ||
Relation::OUTER_KEY => 'id', | ||
Relation::INNER_KEY => 'friend_id', | ||
], | ||
], | ||
], | ||
], | ||
])); | ||
} | ||
|
||
public function testPrivateBelongsToRelationPropertyWithoutProxyShouldBeFilled() | ||
public function testPrivateBelongsToRelationPropertyWithoutProxyShouldBeFilled(): void | ||
{ | ||
$profile = new EntityWithRelationHydrationProfile('test'); | ||
$profile->user_id = 1; | ||
|
@@ -224,7 +252,30 @@ public function testPrivateBelongsToRelationPropertyWithoutProxyShouldBeFilled() | |
// $this->assertInstanceOf(ReferenceInterface::class, $profile->getRefersUser()); | ||
} | ||
|
||
public function testPrivateHasManyRelationPropertyWithoutProxyShouldBeFilled() | ||
public function testRelationWithMixedTypeShouldBeFilledAsReference(): void | ||
{ | ||
$user = new EntityWithMixedTypeRelation(); | ||
$user->email = '[email protected]'; | ||
$user->friend_id = 1; | ||
|
||
$this->save($user); | ||
|
||
$this->assertInstanceOf(ReferenceInterface::class, $user->friend); | ||
} | ||
|
||
public function testRelationExistedInHeapMustFilledAsEntity(): void | ||
{ | ||
$user = new EntityWithMixedTypeRelation(); | ||
$user->email = '[email protected]'; | ||
$user->friend_id = 1; | ||
|
||
$this->orm->getRepository(EntityWithMixedTypeRelation::class)->findByPK(1); | ||
|
||
$this->save($user); | ||
$this->assertInstanceOf(EntityWithMixedTypeRelation::class, $user->friend); | ||
} | ||
|
||
public function testPrivateHasManyRelationPropertyWithoutProxyShouldBeFilled(): void | ||
{ | ||
$profile = new EntityWithRelationHydrationProfile('test'); | ||
$user = new EntityWithRelationHydrationUser('[email protected]'); | ||
|
@@ -235,7 +286,7 @@ public function testPrivateHasManyRelationPropertyWithoutProxyShouldBeFilled() | |
$this->assertSame($user, $profile->getUser()); | ||
} | ||
|
||
public function testPrivateManyToManyRelationPropertyWithoutProxyShouldBeFilled() | ||
public function testPrivateManyToManyRelationPropertyWithoutProxyShouldBeFilled(): void | ||
{ | ||
$tagContext = new EntityWithRelationHydrationTagContext(); | ||
$tagContext->user_id = 1; | ||
|
@@ -250,7 +301,7 @@ public function testPrivateManyToManyRelationPropertyWithoutProxyShouldBeFilled( | |
/** | ||
* TODO: error with shadow belongs to | ||
*/ | ||
public function testPrivatMorphBelongsToRelationPropertyWithoutProxyShouldBeFilled() | ||
public function testPrivateMorphBelongsToRelationPropertyWithoutProxyShouldBeFilled(): void | ||
{ | ||
$profile = new EntityWithRelationHydrationProfile('test'); | ||
$profile->user_id = 1; | ||
|
@@ -307,7 +358,7 @@ public function testChangeLazyOverloadedArray(): void | |
$this->assertContains('test-value', $user->profiles); | ||
} | ||
|
||
public function testGetLinkValueFromLazyOverloadedRelation() | ||
public function testGetLinkValueFromLazyOverloadedRelation(): void | ||
{ | ||
$user = (new Select($this->orm, EntityWithRelationHydrationUser::class)) | ||
->fetchOne(); | ||
|
@@ -433,3 +484,11 @@ public function setParent($parent): void | |
$this->parent = $parent; | ||
} | ||
} | ||
|
||
class EntityWithMixedTypeRelation | ||
{ | ||
public int $id; | ||
public string $email; | ||
public ?int $friend_id = null; | ||
public mixed $friend; | ||
} |