Skip to content

Commit

Permalink
Better naming classes with PDO - part 1. (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Apr 5, 2023
1 parent 2564b68 commit 8212162
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 81 deletions.
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
"yiisoft/translator": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"roave/infection-static-analysis-plugin": "^1.16",
"phpunit/phpunit": "^9.6|^10.0",
"roave/infection-static-analysis-plugin": "^1.25|^1.29",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"yiisoft/db-sqlite": "3.0.x-dev",
"vimeo/psalm": "^4.8|^5.8",
"yiisoft/di": "^1.0",
"yiisoft/psr-dummy-provider": "^1.0",
"yiisoft/yii-db-migration": "1.0.x-dev"
"yiisoft/yii-db-migration": "dev-better-naming-classes as 1.0.x-dev"
},
"autoload": {
"psr-4": {
Expand Down
68 changes: 26 additions & 42 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
executionOrder="random"
failOnRisky="true"
failOnWarning="true"
resolveDependencies="true"
stopOnFailure="false"
verbose="true"
>

<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Yii Translator DB Message Storage tests">
<directory>./tests</directory>
</testsuite>
<testsuite name="Mssql">
<directory>./tests/Mssql</directory>
</testsuite>
<testsuite name="Mysql">
<directory>./tests/Mysql</directory>
</testsuite>
<testsuite name="Pgsql">
<directory>./tests/Pgsql</directory>
</testsuite>
<testsuite name="Sqlite">
<directory>./tests/Sqlite</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" executionOrder="random" failOnRisky="true" failOnWarning="true" resolveDependencies="true" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd">
<php>
<ini name="error_reporting" value="-1"/>
</php>
<testsuites>
<testsuite name="Yii Translator DB Message Storage tests">
<directory>./tests</directory>
</testsuite>
<testsuite name="Mssql">
<directory>./tests/Mssql</directory>
</testsuite>
<testsuite name="Mysql">
<directory>./tests/Mysql</directory>
</testsuite>
<testsuite name="Pgsql">
<directory>./tests/Pgsql</directory>
</testsuite>
<testsuite name="Sqlite">
<directory>./tests/Sqlite</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
23 changes: 13 additions & 10 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
12 changes: 6 additions & 6 deletions src/Migrations/M201104110256CreateMessageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function up(MigrationBuilder $b): void
{
$tableOptions = null;

if ($b->getDb()->getName() === 'mysql') {
if ($b->getDb()->getDriverName() === 'mysql') {
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_bin ENGINE=InnoDB';
}

$columnsMessage = match ($b->getDb()->getName()) {
$columnsMessage = match ($b->getDb()->getDriverName()) {
'sqlite' => [
'id' => 'integer NOT NULL REFERENCES `source_message` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE',
'locale' => $b->string(16)->notNull(),
Expand All @@ -49,18 +49,18 @@ public function up(MigrationBuilder $b): void

$b->createTable('{{%message}}', $columnsMessage, $tableOptions);

if ($b->getDb()->getName() !== 'sqlite') {
if ($b->getDb()->getDriverName() !== 'sqlite') {
$b->addPrimaryKey('{{%message}}', 'pk_message_id_locale', ['id', 'locale']);
}

$onUpdateConstraint = 'RESTRICT';

if ($b->getDb()->getName() === 'sqlsrv') {
if ($b->getDb()->getDriverName() === 'sqlsrv') {
// 'NO ACTION' is equivalent to 'RESTRICT' in MSSQL
$onUpdateConstraint = 'NO ACTION';
}

if ($b->getDb()->getName() !== 'sqlite') {
if ($b->getDb()->getDriverName() !== 'sqlite') {
$b->addForeignKey(
'{{%message}}',
'fk_message_source_message',
Expand All @@ -82,7 +82,7 @@ public function up(MigrationBuilder $b): void
*/
public function down(MigrationBuilder $b): void
{
if ($b->getDb()->getName() !== 'sqlite') {
if ($b->getDb()->getDriverName() !== 'sqlite') {
$b->dropForeignKey('{{%message}}', 'fk_message_source_message');
}

Expand Down
4 changes: 2 additions & 2 deletions tests/AbstractMessageSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function testReadMessages(string $category, string $locale, array $data):
/**
* @psalm-return array<array{0: string, 1: string, 2: array<string, array<string, string>>}>
*/
public function generateTranslationsData(): array
public static function generateTranslationsData(): array
{
return [
[
Expand Down Expand Up @@ -195,7 +195,7 @@ public function generateTranslationsData(): array
/**
* @psalm-return array<array{0: string, 1: string, 2: array<string, array<string, string|int>>}>
*/
public function generateFailTranslationsData(): array
public static function generateFailTranslationsData(): array
{
return [
[
Expand Down
8 changes: 4 additions & 4 deletions tests/Support/MssqlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use Yiisoft\Cache\Cache;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Mssql\ConnectionPDO;
use Yiisoft\Db\Mssql\Connection;
use Yiisoft\Db\Mssql\Driver;
use Yiisoft\Db\Mssql\Dsn;
use Yiisoft\Db\Mssql\PDODriver;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
Expand Down Expand Up @@ -109,9 +109,9 @@ private function getDefinitions(): array
],

ConnectionInterface::class => [
'class' => ConnectionPDO::class,
'class' => Connection::class,
'__construct()' => [
new PDODriver($this->getDsn(), 'SA', 'YourStrong!Passw0rd'),
new Driver($this->getDsn(), 'SA', 'YourStrong!Passw0rd'),
],
],

Expand Down
8 changes: 4 additions & 4 deletions tests/Support/MysqlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use Yiisoft\Cache\Cache;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Mysql\ConnectionPDO;
use Yiisoft\Db\Mysql\Connection;
use Yiisoft\Db\Mysql\Driver;
use Yiisoft\Db\Mysql\Dsn;
use Yiisoft\Db\Mysql\PDODriver;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
Expand Down Expand Up @@ -109,9 +109,9 @@ private function getDefinitions(): array
],

ConnectionInterface::class => [
'class' => ConnectionPDO::class,
'class' => Connection::class,
'__construct()' => [
new PDODriver($this->getDsn(), 'root', ''),
new Driver($this->getDsn(), 'root', ''),
],
],

Expand Down
8 changes: 4 additions & 4 deletions tests/Support/PgsqlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use Yiisoft\Cache\Cache;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Pgsql\ConnectionPDO;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Driver;
use Yiisoft\Db\Pgsql\Dsn;
use Yiisoft\Db\Pgsql\PDODriver;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
Expand Down Expand Up @@ -109,9 +109,9 @@ private function getDefinitions(): array
],

ConnectionInterface::class => [
'class' => ConnectionPDO::class,
'class' => Connection::class,
'__construct()' => [
new PDODriver($this->getDsn(), 'root', 'root'),
new Driver($this->getDsn(), 'root', 'root'),
],
],

Expand Down
8 changes: 4 additions & 4 deletions tests/Support/SqliteHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
use Yiisoft\Cache\Cache;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\ConnectionPDO;
use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Db\Sqlite\Driver;
use Yiisoft\Db\Sqlite\Dsn;
use Yiisoft\Db\Sqlite\PDODriver;
use Yiisoft\Definitions\Exception\CircularReferenceException;
use Yiisoft\Definitions\Exception\InvalidConfigException;
use Yiisoft\Definitions\Exception\NotInstantiableException;
Expand Down Expand Up @@ -109,9 +109,9 @@ private function getDefinitions(): array
],

ConnectionInterface::class => [
'class' => ConnectionPDO::class,
'class' => Connection::class,
'__construct()' => [
new PDODriver($this->getDsn()),
new Driver($this->getDsn()),
],
],

Expand Down

0 comments on commit 8212162

Please sign in to comment.