Skip to content

Commit

Permalink
tests for #321
Browse files Browse the repository at this point in the history
  • Loading branch information
BelaRyc authored and roxblnfk committed Feb 5, 2024
1 parent 1232aea commit f04ae1d
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321;

use Cycle\ORM\Select;
use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest;
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 test1(): void
{
$user = new Entity\User1();

// Store changes and calc write queries
$this->captureWriteQueries();
$this->save($user);

// Check write queries count
$this->assertNumWrites(1);
}

public function test2(): void
{
$user = new Entity\User2();

// Store changes and calc write queries
$this->captureWriteQueries();
$this->save($user);

// Check write queries count
$this->assertNumWrites(1);
}

private function makeTables(): void
{
// Make tables
$this->makeTable('user1', [
'id' => 'primary', // autoincrement
]);

$this->makeTable('user2', [
'id' => 'primary', // autoincrement
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity;

class User1
{
public ?int $id = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity;

class User2
{
public int $id;
}
48 changes: 48 additions & 0 deletions tests/ORM/Functional/Driver/Common/Integration/Case321/schema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

use Cycle\ORM\Mapper\Mapper;
use Cycle\ORM\SchemaInterface as Schema;
use Cycle\ORM\Select\Source;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity\User1;
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\Entity\User2;

return [
'user1' => [
Schema::ENTITY => User1::class,
Schema::MAPPER => Mapper::class,
Schema::SOURCE => Source::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user1',
Schema::PRIMARY_KEY => ['id'],
Schema::FIND_BY_KEYS => ['id'],
Schema::COLUMNS => [
'id' => 'id',
],
Schema::RELATIONS => [],
Schema::SCOPE => null,
Schema::TYPECAST => [
'id' => 'int',
],
Schema::SCHEMA => [],
],
'user2' => [
Schema::ENTITY => User2::class,
Schema::MAPPER => Mapper::class,
Schema::SOURCE => Source::class,
Schema::DATABASE => 'default',
Schema::TABLE => 'user2',
Schema::PRIMARY_KEY => ['id'],
Schema::FIND_BY_KEYS => ['id'],
Schema::COLUMNS => [
'id' => 'id',
],
Schema::RELATIONS => [],
Schema::SCOPE => null,
Schema::TYPECAST => [
'id' => 'int',
],
Schema::SCHEMA => [],
],
];
17 changes: 17 additions & 0 deletions tests/ORM/Functional/Driver/MySQL/Integration/Case321/CaseTest.php
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\Case321;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\CaseTest as CommonClass;

/**
* @group driver
* @group driver-mysql
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'mysql';
}
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\Case321;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\CaseTest as CommonClass;

/**
* @group driver
* @group driver-postgres
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'postgres';
}
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\Case321;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlserver
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'sqlserver';
}
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\Case321;

// phpcs:ignore
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case321\CaseTest as CommonClass;

/**
* @group driver
* @group driver-sqlite
*/
class CaseTest extends CommonClass
{
public const DRIVER = 'sqlite';
}

0 comments on commit f04ae1d

Please sign in to comment.