Skip to content

Commit

Permalink
Add tests for handlers (data)
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed May 21, 2024
1 parent 299d16b commit a9487c6
Show file tree
Hide file tree
Showing 75 changed files with 964 additions and 24 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prefer-stable": true,
"require": {
"php": "^8.1",
"yiisoft/data": "dev-master",
"yiisoft/data": "dev-tests-reogranization",
"yiisoft/db": "^1.3"
},
"require-dev": {
Expand All @@ -56,7 +56,8 @@
},
"autoload-dev": {
"psr-4": {
"Yiisoft\\Data\\Db\\Tests\\": "tests"
"Yiisoft\\Data\\Db\\Tests\\": "tests",
"Yiisoft\\Data\\Tests\\": "vendor/yiisoft/data/tests"
},
"files": ["tests/bootstrap.php"]
},
Expand All @@ -76,4 +77,4 @@
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
}
}
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/AllHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\AllHandlerWithReaderTestTrait;

abstract class AllHandlerTest extends TestCase
{
use AllHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/AnyHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\AnyHandlerWithReaderTestTrait;

abstract class AnyHandlerTest extends TestCase
{
use AnyHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/BetweenHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\BetweenHandlerWithReaderTestTrait;

abstract class BetweenHandlerTest extends TestCase
{
use BetweenHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/EqualsHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\EqualsHandlerWithReaderTestTrait;

abstract class EqualsHandlerTest extends TestCase
{
use EqualsHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/EqualsNullHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\EqualsNullHandlerWithReaderTestTrait;

abstract class EqualsNullHandlerTest extends TestCase
{
use EqualsNullHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/GreaterThanHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\GreaterThanHandlerWithReaderTestTrait;

abstract class GreaterThanHandlerTest extends TestCase
{
use GreaterThanHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/GreaterThanOrEqualHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\GreaterThanOrEqualHandlerWithReaderTestTrait;

abstract class GreaterThanOrEqualHandlerTest extends TestCase
{
use GreaterThanOrEqualHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/LessThanHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\LessThanHandlerWithReaderTestTrait;

abstract class LessThanHandlerTest extends TestCase
{
use LessThanHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/LessThanOrEqualHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\LessThanOrEqualHandlerWithReaderTestTrait;

abstract class LessThanOrEqualHandlerTest extends TestCase
{
use LessThanOrEqualHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/LikeHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\LikeHandlerWithReaderTestTrait;

abstract class LikeHandlerTest extends TestCase
{
use LikeHandlerWithReaderTestTrait;
}
13 changes: 13 additions & 0 deletions tests/Base/FilterHandler/NotHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base\FilterHandler;

use Yiisoft\Data\Db\Tests\Base\TestCase;
use Yiisoft\Data\Tests\Common\Reader\FilterHandler\NotHandlerWithReaderTestTrait;

abstract class NotHandlerTest extends TestCase
{
use NotHandlerWithReaderTestTrait;
}
14 changes: 14 additions & 0 deletions tests/Base/ReaderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Base;

use Yiisoft\Data\Db\QueryDataReader;
use Yiisoft\Data\Reader\DataReaderInterface;
use Yiisoft\Db\Query\Query;

trait ReaderTrait
{

}
84 changes: 83 additions & 1 deletion tests/Base/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,91 @@

namespace Yiisoft\Data\Db\Tests\Base;

use Yiisoft\Data\Db\QueryDataReader;
use Yiisoft\Data\Reader\DataReaderInterface;
use Yiisoft\Data\Tests\Common\FixtureTrait;
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface;
use Yiisoft\Db\Query\Query;

abstract class TestCase extends \PHPUnit\Framework\TestCase
{
abstract protected function getConnection(): PdoConnectionInterface;
use FixtureTrait;

protected static ?PdoConnectionInterface $connection = null;

abstract protected function makeConnection(): PdoConnectionInterface;

protected function getConnection(): PdoConnectionInterface
{
if (self::$connection === null) {
self::$connection = $this->makeConnection();
}

return self::$connection;
}

protected function setUp(): void
{
$this->populateDatabase();
}

protected function tearDown(): void
{
$this->dropDatabase();
}

protected function getReader(): DataReaderInterface
{
/** @var PdoConnectionInterface $db */
$db = $this->getConnection();

return new QueryDataReader((new Query($db))->from('user'));
}

protected function populateDatabase(): void
{
/** @var PdoConnectionInterface $db */
$db = $this->getConnection();
if ($db->getSchema()->getTableSchema('user') !== null) {
return;
}

$db
->createCommand()
->createTable(
'user',
[
'id' => 'pk',
'number' => 'integer NOT NULL',
'email' => 'string(255) NOT NULL',
'balance' => 'float NOT NULL DEFAULT 0.0',
'born_at' => 'datetime',
],
)
->execute();


$fixtures = self::$fixtures;
foreach ($fixtures as $index => $fixture) {
$fixtures[$index]['balance'] = (string) $fixtures[$index]['balance'];
}

$db
->createCommand()
->batchInsert(
'user',
['number', 'email', 'balance', 'born_at'],
$fixtures,
)
->execute();
}

protected function dropDatabase(): void
{
/** @var PdoConnectionInterface $db */
$db = $this->getConnection();
$db
->createCommand()
->dropTable('{{%user}}');
}
}
2 changes: 1 addition & 1 deletion tests/Mssql/DatabaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

trait DatabaseTrait
{
protected function getConnection(): PdoConnectionInterface
protected function makeConnection(): PdoConnectionInterface
{
$database = getenv('YII_MSSQL_DATABASE');
$host = getenv('YII_MSSQL_HOST');
Expand Down
13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/AllHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class AllHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\AllHandlerTest
{
use DatabaseTrait;
}

13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/AnyHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class AnyHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\AnyHandlerTest
{
use DatabaseTrait;
}

13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/BetweenHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class BetweenHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\BetweenHandlerTest
{
use DatabaseTrait;
}

13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/EqualsHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class EqualsHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\EqualsHandlerTest
{
use DatabaseTrait;
}

13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/EqualsNullHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class EqualsNullHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\EqualsNullHandlerTest
{
use DatabaseTrait;
}

13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/GreaterThanHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class GreaterThanHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\GreaterThanHandlerTest
{
use DatabaseTrait;
}

13 changes: 13 additions & 0 deletions tests/Mssql/FilterHandler/GreaterThanOrEqualHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Data\Db\Tests\Mssql\FilterHandler;

use Yiisoft\Data\Db\Tests\Mssql\DatabaseTrait;

class GreaterThanOrEqualHandlerTest extends \Yiisoft\Data\Db\Tests\Base\FilterHandler\GreaterThanOrEqualHandlerTest
{
use DatabaseTrait;
}

Loading

0 comments on commit a9487c6

Please sign in to comment.