-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [bugfix] fixes typo in eager loading
- Loading branch information
Showing
11 changed files
with
305 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\MySQL; | ||
|
||
class Eager2Test extends \Cycle\ORM\Tests\Eager2Test | ||
{ | ||
public const DRIVER = 'mysql'; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\MySQL; | ||
|
||
class ManyToManyPromiseEagerLoadTest extends \Cycle\ORM\Tests\ManyToManyPromiseEagerLoadTest | ||
{ | ||
public const DRIVER = 'mysql'; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\Postgres; | ||
|
||
class Eager2Test extends \Cycle\ORM\Tests\Eager2Test | ||
{ | ||
public const DRIVER = 'postgres'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Driver/Postgres/ManyToManyPromiseEagerLoadTest.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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\Postgres; | ||
|
||
class ManyToManyPromiseEagerLoadTest extends \Cycle\ORM\Tests\ManyToManyPromiseEagerLoadTest | ||
{ | ||
public const DRIVER = 'postgres'; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\SQLServer; | ||
|
||
class Eager2Test extends \Cycle\ORM\Tests\Eager2Test | ||
{ | ||
public const DRIVER = 'sqlserver'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Driver/SQLServer/ManyToManyPromiseEagerLoadTest.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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\SQLServer; | ||
|
||
class ManyToManyPromiseEagerLoadTest extends \Cycle\ORM\Tests\ManyToManyPromiseEagerLoadTest | ||
{ | ||
public const DRIVER = 'sqlserver'; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\SQLite; | ||
|
||
class Eager2Test extends \Cycle\ORM\Tests\Eager2Test | ||
{ | ||
public const DRIVER = 'sqlite'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Driver/SQLite/ManyToManyPromiseEagerLoadTest.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,17 @@ | ||
<?php | ||
|
||
/** | ||
* Cycle DataMapper ORM | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Driver\SQLite; | ||
|
||
class ManyToManyPromiseEagerLoadTest extends \Cycle\ORM\Tests\ManyToManyPromiseEagerLoadTest | ||
{ | ||
public const DRIVER = 'sqlite'; | ||
} |
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,164 @@ | ||
<?php | ||
|
||
/** | ||
* Spiral Framework. | ||
* | ||
* @license MIT | ||
* @author Anton Titov (Wolfy-J) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests; | ||
|
||
use Cycle\ORM\Mapper\Mapper; | ||
use Cycle\ORM\Relation; | ||
use Cycle\ORM\Schema; | ||
use Cycle\ORM\Select; | ||
use Cycle\ORM\Tests\Fixtures\Nested; | ||
use Cycle\ORM\Tests\Fixtures\Profile; | ||
use Cycle\ORM\Tests\Fixtures\User; | ||
use Cycle\ORM\Tests\Traits\TableTrait; | ||
|
||
abstract class Eager2Test extends BaseTest | ||
{ | ||
use TableTrait; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->makeTable('user', [ | ||
'id' => 'primary', | ||
'email' => 'string', | ||
'balance' => 'float' | ||
]); | ||
|
||
$this->makeTable('profile', [ | ||
'id' => 'primary', | ||
'user_id' => 'integer,nullable', | ||
'image' => 'string' | ||
]); | ||
|
||
$this->makeTable('nested', [ | ||
'id' => 'primary', | ||
'profile_id' => 'integer', | ||
'label' => 'string' | ||
]); | ||
|
||
$this->makeFK('profile', 'user_id', 'user', 'id'); | ||
$this->makeFK('nested', 'profile_id', 'profile', 'id'); | ||
|
||
$this->getDatabase()->table('user')->insertMultiple( | ||
['email', 'balance'], | ||
[ | ||
['hello@world.com', 100], | ||
['another@world.com', 200], | ||
] | ||
); | ||
|
||
$this->getDatabase()->table('profile')->insertMultiple( | ||
['user_id', 'image'], | ||
[ | ||
[1, 'image.png'], | ||
] | ||
); | ||
|
||
|
||
$this->getDatabase()->table('nested')->insertMultiple( | ||
['profile_id', 'label'], | ||
[ | ||
[1, 'nested-label'], | ||
] | ||
); | ||
|
||
$this->orm = $this->withSchema(new Schema([ | ||
User::class => [ | ||
Schema::ROLE => 'user', | ||
Schema::MAPPER => Mapper::class, | ||
Schema::DATABASE => 'default', | ||
Schema::TABLE => 'user', | ||
Schema::PRIMARY_KEY => 'id', | ||
Schema::COLUMNS => ['id', 'email', 'balance'], | ||
Schema::SCHEMA => [], | ||
Schema::RELATIONS => [ | ||
'profile' => [ | ||
Relation::TYPE => Relation::HAS_ONE, | ||
Relation::TARGET => Profile::class, | ||
Relation::LOAD => Relation::LOAD_PROMISE, | ||
Relation::SCHEMA => [ | ||
Relation::CASCADE => true, | ||
Relation::INNER_KEY => 'id', | ||
Relation::OUTER_KEY => 'user_id', | ||
], | ||
] | ||
] | ||
], | ||
Profile::class => [ | ||
Schema::ROLE => 'profile', | ||
Schema::MAPPER => Mapper::class, | ||
Schema::DATABASE => 'default', | ||
Schema::TABLE => 'profile', | ||
Schema::PRIMARY_KEY => 'id', | ||
Schema::COLUMNS => ['id', 'user_id', 'image'], | ||
Schema::SCHEMA => [], | ||
Schema::RELATIONS => [ | ||
'nested' => [ | ||
Relation::TYPE => Relation::HAS_ONE, | ||
Relation::TARGET => Nested::class, | ||
Relation::LOAD => Relation::LOAD_EAGER, | ||
Relation::SCHEMA => [ | ||
Relation::CASCADE => true, | ||
Relation::INNER_KEY => 'id', | ||
Relation::OUTER_KEY => 'profile_id', | ||
], | ||
] | ||
] | ||
], | ||
Nested::class => [ | ||
Schema::ROLE => 'nested', | ||
Schema::MAPPER => Mapper::class, | ||
Schema::DATABASE => 'default', | ||
Schema::TABLE => 'nested', | ||
Schema::PRIMARY_KEY => 'id', | ||
Schema::COLUMNS => ['id', 'profile_id', 'label'], | ||
Schema::SCHEMA => [], | ||
Schema::RELATIONS => [] | ||
] | ||
])); | ||
} | ||
|
||
public function testFetchEager(): void | ||
{ | ||
$selector = new Select($this->orm, User::class); | ||
|
||
$this->assertEquals([ | ||
[ | ||
'id' => 1, | ||
'email' => 'hello@world.com', | ||
'balance' => 100.0, | ||
], | ||
[ | ||
'id' => 2, | ||
'email' => 'another@world.com', | ||
'balance' => 200.0, | ||
], | ||
], $selector->fetchData()); | ||
} | ||
|
||
public function testFetchEager2(): void | ||
{ | ||
$selector = new Select($this->orm, User::class); | ||
$selector->where('profile.id', '>', 0); | ||
|
||
$this->assertCount(3, $selector->buildQuery()->getColumns()); | ||
|
||
$this->assertEquals([ | ||
[ | ||
'id' => 1, | ||
'email' => 'hello@world.com', | ||
'balance' => 100.0, | ||
], | ||
], $selector->fetchData()); | ||
} | ||
} |