generated from yiisoft/package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tests for handlers (data) * Apply fixes from StyleCI * Fix mssql (certificate) and dropping table * WIP * Fix psalm * WIP * WIP * WIP * Apply fixes from StyleCI * Fix mssql * An attempt to fix Oracle * An attempt to fix Oracle * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix * Fix --------- Co-authored-by: StyleCI Bot <[email protected]>
- Loading branch information
1 parent
2674b0a
commit b3e1b3f
Showing
89 changed files
with
1,145 additions
and
26 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
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Exception; | ||
|
||
use InvalidArgumentException; | ||
use Throwable; | ||
|
||
final class NotSupportedFilterOptionException extends InvalidArgumentException | ||
{ | ||
/** | ||
* @param string $optionName Option name in filter. | ||
* @param string $driverName Driver name of database. | ||
*/ | ||
public function __construct(string $optionName, string $driverName, int $code = 0, ?Throwable $previous = null) | ||
{ | ||
parent::__construct("\$$optionName option is not supported when using $driverName driver.", $code, $previous); | ||
} | ||
} |
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,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base; | ||
|
||
use DateTime; | ||
use Yiisoft\Data\Db\QueryDataReader; | ||
use Yiisoft\Data\Reader\DataReaderInterface; | ||
use Yiisoft\Data\Tests\Common\FixtureTrait; | ||
use Yiisoft\Db\Connection\ConnectionInterface; | ||
use Yiisoft\Db\Driver\Pdo\PdoConnectionInterface; | ||
use Yiisoft\Db\Expression\Expression; | ||
use Yiisoft\Db\Query\Query; | ||
|
||
trait DataTrait | ||
{ | ||
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 assertFixtures(array $expectedFixtureIndexes, array $actualFixtures): void | ||
{ | ||
$processedActualFixtures = []; | ||
foreach ($actualFixtures as $fixture) { | ||
if (is_object($fixture)) { | ||
$fixture = json_decode(json_encode($fixture), associative: true); | ||
} | ||
|
||
unset($fixture['id']); | ||
$fixture['number'] = (int) $fixture['number']; | ||
$fixture['balance'] = (float) $fixture['balance']; | ||
|
||
if ($fixture['born_at'] !== null && $this->getConnection()->getDriverName() === 'oci') { | ||
$fixture['born_at'] = DateTime::createFromFormat('d-M-y', $fixture['born_at'])->format('Y-m-d'); | ||
} | ||
|
||
$processedActualFixtures[$fixture['number'] - 1] = $fixture; | ||
} | ||
|
||
parent::assertFixtures($expectedFixtureIndexes, $processedActualFixtures); | ||
} | ||
|
||
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 DEFAULT 0.0 NOT NULL', | ||
'born_at' => 'date', | ||
], | ||
) | ||
->execute(); | ||
|
||
$db->transaction(static function (ConnectionInterface $database): void { | ||
foreach (self::$fixtures as $fixture) { | ||
if ($fixture['born_at'] !== null && $database->getDriverName() === 'oci') { | ||
$fixture['born_at'] = new Expression( | ||
"TO_DATE(:born_at, 'yyyy-mm-dd')", | ||
[':born_at' => $fixture['born_at']], | ||
); | ||
} | ||
|
||
$database->createCommand()->insert('{{%user}}', $fixture)->execute(); | ||
} | ||
}); | ||
} | ||
|
||
protected function dropDatabase(): void | ||
{ | ||
/** @var PdoConnectionInterface $db */ | ||
$db = $this->getConnection(); | ||
$db->createCommand()->dropTable('{{%user}}')->execute(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithAllTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithAllTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithAllTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithAnyTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithAnyTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithAnyTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithBetweenTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithBetweenTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithBetweenTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithEqualsNullTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithEqualsNullTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithEqualsNullTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithEqualsTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithEqualsTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithEqualsTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithGreaterThanOrEqualTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithGreaterThanOrEqualTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithGreaterThanOrEqualTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithGreaterThanTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithGreaterThanTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithGreaterThanTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithInTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithInTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithInTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithLessThanOrEqualTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithLessThanOrEqualTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithLessThanOrEqualTestCase | ||
{ | ||
use DataTrait; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithLessThanTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithLessThanTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithLessThanTestCase | ||
{ | ||
use DataTrait; | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Base/Reader/ReaderWithFilter/BaseReaderWithLikeTestCase.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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithLikeTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithLikeTestCase | ||
{ | ||
use DataTrait; | ||
|
||
public static function dataWithReader(): array | ||
{ | ||
$data = parent::dataWithReader(); | ||
$data['search: contains, different case, case sensitive: null'] = ['email', 'SEED@', null, [2]]; | ||
|
||
return $data; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Base/Reader/ReaderWithFilter/BaseReaderWithNotTestCase.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Data\Db\Tests\Base\Reader\ReaderWithFilter; | ||
|
||
use Yiisoft\Data\Db\Tests\Base\DataTrait; | ||
|
||
abstract class BaseReaderWithNotTestCase extends \Yiisoft\Data\Tests\Common\Reader\ReaderWithFilter\BaseReaderWithNotTestCase | ||
{ | ||
use DataTrait; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.