-
-
Notifications
You must be signed in to change notification settings - Fork 74
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
7 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
tests/ORM/Functional/Driver/Common/Integration/Case428/CaseTest.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 Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428; | ||
|
||
use Cycle\ORM\EntityManager; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\Entity\User; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait; | ||
use Cycle\ORM\Tests\Traits\TableTrait; | ||
|
||
abstract class CaseTest extends BaseTest | ||
{ | ||
use IntegrationTestTrait; | ||
use TableTrait; | ||
|
||
public function setUp(): void | ||
{ | ||
// Init DB | ||
parent::setUp(); | ||
$this->makeTables(); | ||
|
||
$this->loadSchema(__DIR__ . '/schema.php'); | ||
} | ||
|
||
public function testSave(): void | ||
{ | ||
$this->captureWriteQueries(); | ||
$em = new EntityManager($this->orm); | ||
|
||
$user = new User(); | ||
|
||
$em->persist($user); | ||
$em->run(); | ||
|
||
// Check write queries count | ||
$this->assertNumWrites(1); | ||
} | ||
|
||
private function makeTables(): void | ||
{ | ||
// Make tables | ||
$this->makeTable(User::ROLE, [ | ||
'id' => 'primary', // autoincrement | ||
'user_id' => 'int', | ||
]); | ||
$this->makeFK(User::ROLE, 'user_id', User::ROLE, 'id', 'CASCADE', 'CASCADE'); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ORM/Functional/Driver/Common/Integration/Case428/Entity/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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\Entity; | ||
|
||
class User | ||
{ | ||
public const ROLE = 'user'; | ||
|
||
public ?int $id = null; | ||
public ?self $user = null; | ||
public iterable $users = []; | ||
} |
61 changes: 61 additions & 0 deletions
61
tests/ORM/Functional/Driver/Common/Integration/Case428/schema.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,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Cycle\ORM\Mapper\Mapper; | ||
use Cycle\ORM\Relation; | ||
use Cycle\ORM\SchemaInterface as Schema; | ||
use Cycle\ORM\Select\Repository; | ||
use Cycle\ORM\Select\Source; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\Entity\User; | ||
|
||
return [ | ||
'user' => [ | ||
Schema::ENTITY => User::class, | ||
Schema::SOURCE => Source::class, | ||
Schema::MAPPER => Mapper::class, | ||
Schema::REPOSITORY => Repository::class, | ||
Schema::DATABASE => 'default', | ||
Schema::TABLE => 'user', | ||
Schema::PRIMARY_KEY => ['id'], | ||
Schema::FIND_BY_KEYS => ['id'], | ||
Schema::COLUMNS => [ | ||
'id' => 'id', | ||
'user_id' => 'user_id', | ||
], | ||
Schema::RELATIONS => [ | ||
'user' => [ | ||
Relation::TYPE => Relation::BELONGS_TO, | ||
Relation::TARGET => 'user', | ||
Relation::LOAD => Relation::LOAD_PROMISE, | ||
Relation::SCHEMA => [ | ||
Relation::CASCADE => true, | ||
Relation::NULLABLE => true, | ||
Relation::INNER_KEY => 'user_id', | ||
Relation::OUTER_KEY => ['id'], | ||
Relation::INVERSION => 'users', | ||
], | ||
], | ||
'users' => [ | ||
Relation::TYPE => Relation::HAS_MANY, | ||
Relation::TARGET => 'user', | ||
Relation::LOAD => Relation::LOAD_PROMISE, | ||
Relation::SCHEMA => [ | ||
Relation::CASCADE => true, | ||
Relation::NULLABLE => false, | ||
Relation::WHERE => [], | ||
Relation::ORDER_BY => [], | ||
Relation::INNER_KEY => ['id'], | ||
Relation::OUTER_KEY => 'user_id', | ||
Relation::INVERSION => 'user', | ||
], | ||
], | ||
], | ||
Schema::SCOPE => null, | ||
Schema::TYPECAST => [ | ||
'id' => 'int', | ||
'user_id' => 'int', | ||
], | ||
Schema::SCHEMA => [], | ||
], | ||
]; |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/MySQL/Integration/Case428/CaseTest.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\MySQL\Integration\Case428; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-mysql | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'mysql'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/Postgres/Integration/Case428/CaseTest.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\Postgres\Integration\Case428; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-postgres | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'postgres'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/SQLServer/Integration/Case428/CaseTest.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\SQLServer\Integration\Case428; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-sqlserver | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'sqlserver'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/SQLite/Integration/Case428/CaseTest.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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\SQLite\Integration\Case428; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case428\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-sqlite | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'sqlite'; | ||
} |