diff --git a/src/Console/Color.php b/src/Console/Color.php index e46bf10..efc74b4 100644 --- a/src/Console/Color.php +++ b/src/Console/Color.php @@ -67,9 +67,9 @@ final class Color public const AT_STRIKE = 9; /** - * @var array Map of supported foreground colors + * Map of supported foreground colors */ - private static $fg = [ + private static array $fg = [ self::FG_BLACK => '0;30', self::FG_DARK_GRAY => '1;30', self::FG_RED => '0;31', @@ -89,9 +89,9 @@ final class Color ]; /** - * @var array Map of supported background colors + * Map of supported background colors */ - private static $bg = [ + private static array $bg = [ self::BG_BLACK => '40', self::BG_RED => '41', self::BG_GREEN => '42', @@ -103,9 +103,9 @@ final class Color ]; /** - * @var array Map of supported attributes + * Map of supported attributes */ - private static $at = [ + private static array $at = [ self::AT_NORMAL => '0', self::AT_BOLD => '1', self::AT_ITALIC => '3', @@ -119,8 +119,6 @@ final class Color /** * Identify if console supports colors - * - * @return bool */ public static function isSupportedShell(): bool { @@ -133,15 +131,6 @@ public static function isSupportedShell(): bool /** * Colorizes the string using provided colors. - * - * @static - * - * @param string $string - * @param null|integer $fg - * @param null|integer $at - * @param null|integer $bg - * - * @return string */ public static function colorize(string $string, int $fg = null, int $at = null, int $bg = null): string { @@ -173,25 +162,13 @@ public static function colorize(string $string, int $fg = null, int $at = null, return $colored; } - /** - * @param string $msg - * - * @return string - */ public static function head(string $msg): string { - return static::colorize($msg, Color::FG_BROWN); + return Color::colorize($msg, Color::FG_BROWN); } /** * Color style for error messages. - * - * @static - * - * @param string $msg - * @param string $prefix - * - * @return string */ public static function error(string $msg, string $prefix = 'Error: '): string { @@ -206,13 +183,6 @@ public static function error(string $msg, string $prefix = 'Error: '): string /** * Color style for fatal error messages. - * - * @static - * - * @param string $msg - * @param string $prefix - * - * @return string */ public static function fatal(string $msg, string $prefix = 'Fatal Error: '): string { @@ -227,12 +197,6 @@ public static function fatal(string $msg, string $prefix = 'Fatal Error: '): str /** * Color style for success messages. - * - * @static - * - * @param string $msg - * - * @return string */ public static function success(string $msg): string { @@ -247,12 +211,6 @@ public static function success(string $msg): string /** * Color style for info messages. - * - * @static - * - * @param string $msg - * - * @return string */ public static function info(string $msg): string { @@ -269,11 +227,6 @@ public static function info(string $msg): string * Output tab space * * Depending on length of string. - * - * @param string $string - * @param int $tabSize - * - * @return int */ protected static function tabSpaces(string $string, int $tabSize = 4): int { diff --git a/src/Console/Commands/CommandsException.php b/src/Console/Commands/CommandsException.php index 73f2dd8..7f88d0f 100644 --- a/src/Console/Commands/CommandsException.php +++ b/src/Console/Commands/CommandsException.php @@ -15,9 +15,6 @@ use Exception; -/** - * Commands Exception - */ class CommandsException extends Exception { } diff --git a/src/Console/Commands/CommandsInterface.php b/src/Console/Commands/CommandsInterface.php index bce66e9..fa78e71 100644 --- a/src/Console/Commands/CommandsInterface.php +++ b/src/Console/Commands/CommandsInterface.php @@ -22,15 +22,11 @@ interface CommandsInterface { /** * Executes the command. - * - * @return mixed */ - public function run(); + public function run(): void; /** * Prints help on the usage of the command. - * - * @return void */ public function getHelp(): void; @@ -40,8 +36,6 @@ public function getHelp(): void; * This method returns a list of available parameters for the current command. * The list must be represented as pairs key-value. * Where key is the parameter name and value is the short description. - * - * @return array */ public function getPossibleParams(): array; } diff --git a/src/Console/Commands/Migration.php b/src/Console/Commands/Migration.php index 7fad1ad..9aa5377 100644 --- a/src/Console/Commands/Migration.php +++ b/src/Console/Commands/Migration.php @@ -47,22 +47,10 @@ */ class Migration implements CommandsInterface { - /** - * @var Parser - */ - protected $parser; - - /** - * @param Parser $parser - */ - final public function __construct(Parser $parser) + final public function __construct(protected Parser $parser) { - $this->parser = $parser; } - /** - * @return array - */ public function getPossibleParams(): array { return [ @@ -208,8 +196,6 @@ public function run(): void /** * Print Help information - * - * @return void */ public function getHelp(): void { @@ -232,12 +218,7 @@ public function getHelp(): void $this->printParameters($this->getPossibleParams()); } - /** - * @param mixed $config - * - * @return array - */ - protected function exportFromTables($config): array + protected function exportFromTables(Config $config): array { $tables = []; $application = $config->get('application') ?? []; @@ -261,6 +242,7 @@ protected function exportFromTables($config): array * * @return Config * @throws CommandsException + * @throws \Phalcon\Config\Exception */ protected function getConfig(string $path): Config { @@ -280,10 +262,8 @@ protected function getConfig(string $path): Config * Determines correct adapter by file name * and load config * - * @param string $fileName Config file name - * - * @return Config * @throws CommandsException + * @throws \Phalcon\Config\Exception */ protected function loadConfig(string $fileName): Config { diff --git a/src/Console/OptionStack.php b/src/Console/OptionStack.php index 9a60c2a..da6b1f8 100644 --- a/src/Console/OptionStack.php +++ b/src/Console/OptionStack.php @@ -25,19 +25,8 @@ */ class OptionStack implements ArrayAccess { - /** - * Parameters received by the script. - * - * @var array - */ - protected array $options = []; - - /** - * @param array $options - */ - public function __construct(array $options = []) + public function __construct(protected array $options = []) { - $this->options = $options; } /** diff --git a/src/Exception/Db/UnknownColumnTypeException.php b/src/Exception/Db/UnknownColumnTypeException.php index 36b79a9..6fbf64b 100644 --- a/src/Exception/Db/UnknownColumnTypeException.php +++ b/src/Exception/Db/UnknownColumnTypeException.php @@ -18,15 +18,8 @@ class UnknownColumnTypeException extends Exception { - /** - * @var ColumnInterface - */ - protected ColumnInterface $column; - - public function __construct(ColumnInterface $column) + public function __construct(protected ColumnInterface $column) { - $this->column = $column; - $message = sprintf( 'Unrecognized data type "%s" for column "%s".', $column->getType(), @@ -36,9 +29,6 @@ public function __construct(ColumnInterface $column) parent::__construct($message, 0); } - /** - * @return ColumnInterface - */ public function getColumn(): ColumnInterface { return $this->column; diff --git a/src/Migration/Action/Generate.php b/src/Migration/Action/Generate.php index 955afca..8506610 100644 --- a/src/Migration/Action/Generate.php +++ b/src/Migration/Action/Generate.php @@ -22,9 +22,7 @@ use Phalcon\Db\Enum; use Phalcon\Db\Exception; use Phalcon\Db\Index; -use Phalcon\Db\IndexInterface; use Phalcon\Db\Reference; -use Phalcon\Db\ReferenceInterface; use Phalcon\Migrations\Exception\Db\UnknownColumnTypeException; use Phalcon\Migrations\Exception\RuntimeException; use Phalcon\Migrations\Generator\Snippet; @@ -143,31 +141,6 @@ class Generate */ private ?ClassType $class = null; - /** - * SQL Adapter Name - */ - private string $adapter; - - /** - * Table columns - */ - protected array $columns; - - /** - * Table indexes - */ - protected array $indexes; - - /** - * Table foreign keys and another references - */ - protected array $references; - - /** - * Table options - */ - protected array $options; - protected ?string $primaryColumnName = null; /** @@ -182,27 +155,13 @@ class Generate */ protected array $quoteWrappedColumns = []; - /** - * Generate constructor. - * - * @param string $adapter - * @param array|ColumnInterface[] $columns - * @param array|IndexInterface[] $indexes - * @param array|ReferenceInterface[] $references - * @param array $options - */ public function __construct( - string $adapter, - array $columns = [], - array $indexes = [], - array $references = [], - array $options = [] + private string $adapter, + protected array $columns = [], + protected array $indexes = [], + protected array $references = [], + protected array $options = [] ) { - $this->adapter = $adapter; - $this->columns = $columns; - $this->indexes = $indexes; - $this->references = $references; - $this->options = $options; } public function getEntity(): PhpFile @@ -565,11 +524,6 @@ public function getAdapter(): string /** * Just wrap string with single quotes - * - * @param string $columnName - * @param string $quote - * - * @return string */ public function wrapWithQuotes(string $columnName, string $quote = "'"): string { diff --git a/src/Migrations.php b/src/Migrations.php index 782203c..ab8ec94 100644 --- a/src/Migrations.php +++ b/src/Migrations.php @@ -102,13 +102,10 @@ public static function isConsole(): bool /** * Generate migrations * - * @param array $options - * - * @return bool|void * @throws Exception * @throws RuntimeException */ - public static function generate(array $options) + public static function generate(array $options): void { $helper = new Helper(); $optionStack = new OptionStack($options); @@ -193,20 +190,16 @@ public static function generate(array $options) print Color::info('Nothing to generate. You should create tables first.') . PHP_EOL; } } - - return true; } /** * Run migrations * - * @param array $options - * * @throws DbException * @throws RuntimeException * @throws Exception */ - public static function run(array $options) + public static function run(array $options): void { $optionStack = new OptionStack($options); $listTables = new ListTablesIterator(); @@ -424,8 +417,6 @@ public static function run(array $options) /** * List migrations along with statuses * - * @param array $options - * * @throws Exception * @throws RuntimeException */ @@ -504,8 +495,6 @@ public static function listAll(array $options): void /** * Initialize migrations log storage * - * @param array $options Applications options - * * @throws RuntimeException */ private static function connectionSetup(array $options): void @@ -514,7 +503,7 @@ private static function connectionSetup(array $options): void return; } - if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) { + if (isset($options['migrationsInDb']) && $options['migrationsInDb']) { /** @var Config $database */ $database = $options['config']['database']; @@ -591,15 +580,13 @@ private static function connectionSetup(array $options): void /** * Get latest completed migration version * - * @param array $options Applications options - * * @return IncrementalItem|TimestampedItem */ public static function getCurrentVersion(array $options) { self::connectionSetup($options); - if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) { + if (isset($options['migrationsInDb']) && $options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; $query = 'SELECT * FROM ' . self::MIGRATION_LOG_TABLE . ' ORDER BY version DESC LIMIT 1'; @@ -638,13 +625,10 @@ public static function addCurrentVersion(array $options, string $version, ?strin { self::connectionSetup($options); - if ($startTime === null) { - $startTime = date('Y-m-d H:i:s'); - } - + $startTime = $startTime === null ? date('Y-m-d H:i:s') : $startTime; $endTime = date('Y-m-d H:i:s'); - if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) { + if (isset($options['migrationsInDb']) && $options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; $connection->insert( @@ -671,7 +655,7 @@ public static function removeCurrentVersion(array $options, string $version): vo { self::connectionSetup($options); - if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) { + if (isset($options['migrationsInDb']) && $options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; $connection->execute('DELETE FROM ' . self::MIGRATION_LOG_TABLE . ' WHERE version=\'' . $version . '\''); @@ -686,16 +670,12 @@ public static function removeCurrentVersion(array $options, string $version): vo /** * Scan $storage for all completed versions - * - * @param array $options Applications options - * - * @return array */ public static function getCompletedVersions(array $options): array { self::connectionSetup($options); - if (isset($options['migrationsInDb']) && (bool) $options['migrationsInDb']) { + if (isset($options['migrationsInDb']) && $options['migrationsInDb']) { /** @var AdapterInterface $connection */ $connection = self::$storage; $query = 'SELECT version FROM ' . self::MIGRATION_LOG_TABLE . ' ORDER BY version DESC'; diff --git a/src/Mvc/Model/Migration.php b/src/Mvc/Model/Migration.php index e26ba06..aab2384 100644 --- a/src/Mvc/Model/Migration.php +++ b/src/Mvc/Model/Migration.php @@ -146,12 +146,12 @@ public static function setup(Config $database, bool $verbose = false): void self::$connection = $connection; self::$databaseConfig = $database; - // Connection custom dialect Dialect/DialectMysql + // Connection custom Dialect/DialectMysql if ($dbAdapter === self::DB_ADAPTER_MYSQL) { self::$connection->setDialect(new DialectMysql()); } - // Connection custom dialect Dialect/DialectPostgresql + // Connection custom Dialect/DialectPostgresql if ($dbAdapter === self::DB_ADAPTER_POSTGRESQL) { self::$connection->setDialect(new DialectPostgresql()); } diff --git a/src/Mvc/Model/Migration/TableAware/ListTablesDb.php b/src/Mvc/Model/Migration/TableAware/ListTablesDb.php index cd7bc8f..aad7421 100644 --- a/src/Mvc/Model/Migration/TableAware/ListTablesDb.php +++ b/src/Mvc/Model/Migration/TableAware/ListTablesDb.php @@ -39,9 +39,7 @@ public function listTablesForPrefix(string $tablePrefix, DirectoryIterator $iter throw new InvalidArgumentException("Parameters weren't defined in " . __METHOD__); } - $tablesList = (new ModelMigration())->getConnection() - ->listTables() - ; + $tablesList = (new ModelMigration())->getConnection()->listTables(); if (empty($tablesList)) { return ''; } diff --git a/src/Mvc/Model/Migration/TableAware/ListTablesInterface.php b/src/Mvc/Model/Migration/TableAware/ListTablesInterface.php index 58894e7..d69b2a7 100644 --- a/src/Mvc/Model/Migration/TableAware/ListTablesInterface.php +++ b/src/Mvc/Model/Migration/TableAware/ListTablesInterface.php @@ -19,11 +19,6 @@ interface ListTablesInterface { /** * Get list table from prefix - * - * @param string $tablePrefix Table prefix - * @param DirectoryIterator|null $iterator - * - * @return string */ public function listTablesForPrefix(string $tablePrefix, DirectoryIterator $iterator = null): string; } diff --git a/src/Mvc/Model/Migration/TableAware/ListTablesIterator.php b/src/Mvc/Model/Migration/TableAware/ListTablesIterator.php index b0ee1e6..8b5a1c4 100644 --- a/src/Mvc/Model/Migration/TableAware/ListTablesIterator.php +++ b/src/Mvc/Model/Migration/TableAware/ListTablesIterator.php @@ -26,11 +26,6 @@ class ListTablesIterator implements ListTablesInterface { /** * Get table names with prefix for running migration - * - * @param string $tablePrefix - * @param DirectoryIterator|null $iterator - * - * @return string */ public function listTablesForPrefix(string $tablePrefix, DirectoryIterator $iterator = null): string { diff --git a/src/Version/IncrementalItem.php b/src/Version/IncrementalItem.php index 784bbcb..de1d38b 100644 --- a/src/Version/IncrementalItem.php +++ b/src/Version/IncrementalItem.php @@ -36,13 +36,11 @@ class IncrementalItem implements ItemInterface private string $path = ''; - private string $version; - private int $versionStamp = 0; private array $parts; - public function __construct(string $version, int $numberParts = 3) + public function __construct(private string $version, int $numberParts = 3) { $version = trim($version); $this->parts = explode('.', $version); diff --git a/tests/mysql/ColumnTypesCest.php b/tests/mysql/ColumnTypesCest.php index 4e2c530..0c31e7b 100644 --- a/tests/mysql/ColumnTypesCest.php +++ b/tests/mysql/ColumnTypesCest.php @@ -14,14 +14,13 @@ namespace Phalcon\Migrations\Tests\Mysql; use Codeception\Example; -use Exception; use MysqlTester; use PDO; use Phalcon\Config\Config; use Phalcon\Db\Adapter\Pdo\AbstractPdo; use Phalcon\Db\Column; +use Phalcon\Db\Exception; use Phalcon\Migrations\Migrations; -use Phalcon\Migrations\Script\ScriptException; /** * @method Config getMigrationsConfig() @@ -37,20 +36,20 @@ protected function columnsDataProvider(): array [ 'column_int', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 10, + 'type' => Column::TYPE_INTEGER, + 'size' => 10, 'unsigned' => true, - 'notNull' => true, - 'first' => true, + 'notNull' => true, + 'first' => true, ], [0, 1, 123, 9000], ], [ 'column_int_primary', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 11, - 'first' => true, + 'type' => Column::TYPE_INTEGER, + 'size' => 11, + 'first' => true, 'primary' => true, ], [1, 2, 3, 4], @@ -58,10 +57,10 @@ protected function columnsDataProvider(): array [ 'column_int_pri_inc', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 11, - 'first' => true, - 'primary' => true, + 'type' => Column::TYPE_INTEGER, + 'size' => 11, + 'first' => true, + 'primary' => true, 'autoIncrement' => true, ], [1, 2, 3, 4], @@ -69,7 +68,7 @@ protected function columnsDataProvider(): array [ 'column_time', [ - 'type' => Column::TYPE_TIME, + 'type' => Column::TYPE_TIME, 'notNull' => false, ], ['00:00:00', '23:59:55', '12:00:12'], @@ -77,7 +76,7 @@ protected function columnsDataProvider(): array [ 'column_json', [ - 'type' => Column::TYPE_JSON, + 'type' => Column::TYPE_JSON, 'notNull' => true, ], ['{}', '{"type": "json"}', '{"random": 123, "is_true": false}'], @@ -85,8 +84,8 @@ protected function columnsDataProvider(): array [ 'column_enum_not_null', [ - 'type' => Column::TYPE_ENUM, - 'size' => "'Y','N','D', ''", + 'type' => Column::TYPE_ENUM, + 'size' => "'Y','N','D', ''", 'notNull' => true, ], ['Y', 'N', 'D', ''], @@ -94,9 +93,9 @@ protected function columnsDataProvider(): array [ 'column_decimal', [ - 'type' => Column::TYPE_DECIMAL, - 'size' => 10, - 'scale' => 2, + 'type' => Column::TYPE_DECIMAL, + 'size' => 10, + 'scale' => 2, 'notNull' => true, ], [0, 1, 2.3, 4.56, 12345678.12], @@ -108,26 +107,24 @@ protected function columnsDataProvider(): array * @dataProvider columnsDataProvider * * @param MysqlTester $I - * @param Example $example + * @param Example $example * - * @throws ScriptException - * @throws \Phalcon\Mvc\Model\Exception * @throws Exception + * @throws \Exception */ public function columnDefinition(MysqlTester $I, Example $example): void { list($columnName, $definition, $values) = $example; - $tableName = $example[0] . '_test'; + $tableName = $example[0] . '_test'; $migrationsDir = codecept_output_dir('tests/var/output/' . __FUNCTION__); $I->getPhalconDb() - ->createTable($tableName, $_ENV['MYSQL_TEST_DB_DATABASE'], [ - 'columns' => [ - new Column($columnName, $definition), - ], - ]) - ; + ->createTable($tableName, $_ENV['MYSQL_TEST_DB_DATABASE'], [ + 'columns' => [ + new Column($columnName, $definition), + ], + ]); /** * Generate | Drop | Run @@ -135,15 +132,13 @@ public function columnDefinition(MysqlTester $I, Example $example): void ob_start(); Migrations::generate([ 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), - 'tableName' => $tableName, + 'config' => $I->getMigrationsConfig(), + 'tableName' => $tableName, ]); - $I->getPhalconDb() - ->dropTable($tableName) - ; + $I->getPhalconDb()->dropTable($tableName); Migrations::run([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); @@ -152,18 +147,15 @@ public function columnDefinition(MysqlTester $I, Example $example): void * Insert values */ foreach ($values as $value) { - $I->getPhalconDb() - ->insert($tableName, [$value], [$columnName]) - ; + $I->getPhalconDb()->insert($tableName, [$value], [$columnName]); } Migrations::resetStorage(); $I->removeDir($migrationsDir); /** @var Column $column */ - $column = $I->getPhalconDb() - ->describeColumns($tableName)[0]; - $rows = $I->grabColumnFromDatabase($tableName, $columnName); + $column = $I->getPhalconDb()->describeColumns($tableName)[0]; + $rows = $I->grabColumnFromDatabase($tableName, $columnName); $I->assertSame($definition['type'], $column->getType()); $I->assertSame($definition['notNull'] ?? true, $column->isNotNull()); diff --git a/tests/mysql/Issue76Cest.php b/tests/mysql/Issue76Cest.php index e472072..c707c0f 100644 --- a/tests/mysql/Issue76Cest.php +++ b/tests/mysql/Issue76Cest.php @@ -35,18 +35,16 @@ public function normalRun(MysqlTester $I): void ob_start(); Migrations::run([ - 'migrationsDir' => codecept_data_dir('issues/76'), - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => codecept_data_dir('issues/76'), + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); $query1 = 'SELECT COUNT(*) cnt FROM user_details WHERE user_id = 62 AND last_name IS NULL'; - $I->assertTrue($I->getPhalconDb() - ->tableExists('user_details')); + $I->assertTrue($I->getPhalconDb()->tableExists('user_details')); $I->canSeeNumRecords(2363, 'user_details'); - $I->assertEquals(1, $I->getPhalconDb() - ->fetchOne($query1)['cnt']); + $I->assertEquals(1, $I->getPhalconDb()->fetchOne($query1)['cnt']); } } diff --git a/tests/mysql/Issue94Cest.php b/tests/mysql/Issue94Cest.php index f07dbe1..f224ae5 100644 --- a/tests/mysql/Issue94Cest.php +++ b/tests/mysql/Issue94Cest.php @@ -26,15 +26,13 @@ public function testIssue94(MysqlTester $I): void ob_start(); Migrations::run([ - 'migrationsDir' => codecept_data_dir('issues/94'), - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => codecept_data_dir('issues/94'), + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); - $options = $I->getPhalconDb() - ->tableOptions('memory_table') - ; + $options = $I->getPhalconDb()->tableOptions('memory_table'); $I->assertSame('MEMORY', $options['engine']); } @@ -48,30 +46,29 @@ public function testGenerateIssue94(MysqlTester $I): void { $I->wantToTest('Issue #94 - Correct options generation case (uppercase)'); - $engine = 'MyISAM'; - $tableName = 'options_uppercase'; + $engine = 'MyISAM'; + $tableName = 'options_uppercase'; $migrationsDir = codecept_output_dir(__FUNCTION__); $I->getPhalconDb() - ->createTable($tableName, '', [ - 'columns' => [ - new Column('id', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 20, - 'notNull' => true, - 'autoIncrement' => true, - ]), - ], - 'indexes' => [ - new Index('PRIMARY', ['id'], 'PRIMARY') - ], - 'options' => [ - 'TABLE_TYPE' => 'BASE TABLE', - 'ENGINE' => $engine, - 'TABLE_COLLATION' => 'utf8mb4_general_ci', - ], - ]) - ; + ->createTable($tableName, '', [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 20, + 'notNull' => true, + 'autoIncrement' => true, + ]), + ], + 'indexes' => [ + new Index('PRIMARY', ['id'], 'PRIMARY') + ], + 'options' => [ + 'TABLE_TYPE' => 'BASE TABLE', + 'ENGINE' => $engine, + 'TABLE_COLLATION' => 'utf8mb4_general_ci', + ], + ]); /** * Generate | Drop | Run @@ -79,20 +76,17 @@ public function testGenerateIssue94(MysqlTester $I): void ob_start(); Migrations::generate([ 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), - 'tableName' => $tableName, + 'config' => $I->getMigrationsConfig(), + 'tableName' => $tableName, ]); - $I->getPhalconDb() - ->dropTable($tableName) - ; + $I->getPhalconDb()->dropTable($tableName); Migrations::run([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); - $I->assertSame($engine, $I->getPhalconDb() - ->tableOptions($tableName)['engine']); + $I->assertSame($engine, $I->getPhalconDb()->tableOptions($tableName)['engine']); } } diff --git a/tests/postgresql/ColumnTypesCest.php b/tests/postgresql/ColumnTypesCest.php index d08b34f..a2139da 100644 --- a/tests/postgresql/ColumnTypesCest.php +++ b/tests/postgresql/ColumnTypesCest.php @@ -15,9 +15,8 @@ use Codeception\Example; use Phalcon\Db\Column; +use Phalcon\Db\Exception; use Phalcon\Migrations\Migrations; -use Phalcon\Migrations\Script\ScriptException; -use Phalcon\Mvc\Model\Exception; use PostgresqlTester; final class ColumnTypesCest @@ -26,10 +25,9 @@ final class ColumnTypesCest * @dataProvider columnsDataProvider * * @param PostgresqlTester $I - * @param Example $example + * @param Example $example * * @throws Exception - * @throws ScriptException * @throws \Exception */ public function columnDefinition(PostgresqlTester $I, Example $example): void @@ -39,12 +37,12 @@ public function columnDefinition(PostgresqlTester $I, Example $example): void $tableName = $columnName . '_test'; $migrationsDir = codecept_output_dir(__FUNCTION__ . $columnName); - $created = $I->getPhalconDb() - ->createTable($tableName, $I->getDefaultSchema(), [ - 'columns' => [ - new Column($columnName, $definition), - ], - ]) + $I->getPhalconDb() + ->createTable($tableName, $I->getDefaultSchema(), [ + 'columns' => [ + new Column($columnName, $definition), + ], + ]) ; /** @@ -70,16 +68,13 @@ public function columnDefinition(PostgresqlTester $I, Example $example): void * Insert values */ foreach ($values as $value) { - $I->getPhalconDb() - ->insert($tableName, [$value], [$columnName]) - ; + $I->getPhalconDb()->insert($tableName, [$value], [$columnName]); } $I->removeDir($migrationsDir); /** @var Column $column */ - $column = $I->getPhalconDb() - ->describeColumns($tableName, $I->getDefaultSchema())[0]; + $column = $I->getPhalconDb()->describeColumns($tableName, $I->getDefaultSchema())[0]; $rows = $I->grabColumnFromDatabase($I->getDefaultSchema() . '.' . $tableName, $columnName); $I->assertSame($definition['type'], $column->getType()); diff --git a/tests/postgresql/Issue104Cest.php b/tests/postgresql/Issue104Cest.php index 0d2ee9a..c441bd5 100644 --- a/tests/postgresql/Issue104Cest.php +++ b/tests/postgresql/Issue104Cest.php @@ -25,17 +25,13 @@ class Issue104Cest { /** - * @param PostgresqlTester $I - * * @throws Exception */ public function normalRun(PostgresqlTester $I): void { $I->wantToTest('Issue #104 - Disable foreign keys'); - $I->getPhalconDb() - ->execute("SET session_replication_role = 'replica';") - ; + $I->getPhalconDb()->execute("SET session_replication_role = 'replica';"); ob_start(); Migrations::run([ @@ -51,11 +47,8 @@ public function normalRun(PostgresqlTester $I): void $schema = $_ENV['POSTGRES_TEST_DB_SCHEMA']; - $I->assertTrue($I->getPhalconDb() - ->tableExists('phalcon_migrations', $schema)); - $I->assertTrue($I->getPhalconDb() - ->tableExists('foreign_keys_table1', $schema)); - $I->assertTrue($I->getPhalconDb() - ->tableExists('foreign_keys_table2', $schema)); + $I->assertTrue($I->getPhalconDb()->tableExists('phalcon_migrations', $schema)); + $I->assertTrue($I->getPhalconDb()->tableExists('foreign_keys_table1', $schema)); + $I->assertTrue($I->getPhalconDb()->tableExists('foreign_keys_table2', $schema)); } } diff --git a/tests/postgresql/Issue76Cest.php b/tests/postgresql/Issue76Cest.php index 5a01543..7e83c80 100644 --- a/tests/postgresql/Issue76Cest.php +++ b/tests/postgresql/Issue76Cest.php @@ -25,8 +25,6 @@ class Issue76Cest { /** - * @param PostgresqlTester $I - * * @throws Exception */ public function normalRun(PostgresqlTester $I): void @@ -44,10 +42,8 @@ public function normalRun(PostgresqlTester $I): void $schema = $_ENV['POSTGRES_TEST_DB_SCHEMA']; $query1 = "SELECT COUNT(*) cnt FROM $schema.user_details WHERE user_id = 62 AND last_name IS NULL"; - $I->assertTrue($I->getPhalconDb() - ->tableExists('user_details', $schema)); + $I->assertTrue($I->getPhalconDb()->tableExists('user_details', $schema)); $I->canSeeNumRecords(2363, $schema . '.user_details'); - $I->assertEquals(1, $I->getPhalconDb() - ->fetchOne($query1)['cnt']); + $I->assertEquals(1, $I->getPhalconDb()->fetchOne($query1)['cnt']); } } diff --git a/tests/postgresql/IssuesCest.php b/tests/postgresql/IssuesCest.php index f84656e..d54c9ad 100644 --- a/tests/postgresql/IssuesCest.php +++ b/tests/postgresql/IssuesCest.php @@ -26,21 +26,20 @@ public function issue1(PostgresqlTester $I): void { $I->wantToTest('Issue #1 - Primary key was created'); - $tableName = 'table_primary_test'; + $tableName = 'table_primary_test'; $migrationsDir = codecept_output_dir(__FUNCTION__); $I->getPhalconDb() - ->createTable($tableName, $I->getDefaultSchema(), [ - 'columns' => [ - new Column('id', [ - 'type' => Column::TYPE_INTEGER, - 'notNull' => true, - 'first' => true, - 'primary' => true, - ]), - ], - ]) - ; + ->createTable($tableName, $I->getDefaultSchema(), [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'notNull' => true, + 'first' => true, + 'primary' => true, + ]), + ], + ]); /** * Generate | Drop | Run @@ -48,22 +47,18 @@ public function issue1(PostgresqlTester $I): void ob_start(); Migrations::generate([ 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), - 'tableName' => $tableName, + 'config' => $I->getMigrationsConfig(), + 'tableName' => $tableName, ]); - $I->getPhalconDb() - ->dropTable($tableName) - ; + $I->getPhalconDb()->dropTable($tableName); Migrations::run([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); - $indexes = $I->getPhalconDb() - ->describeIndexes($tableName, $I->getDefaultSchema()) - ; + $indexes = $I->getPhalconDb()->describeIndexes($tableName, $I->getDefaultSchema()); $I->assertSame(1, count($indexes)); } @@ -75,24 +70,23 @@ public function testIssue111Fail(PostgresqlTester $I): void { $I->wantToTest('Issue #111 - Unrecognized PostgreSQL data type [FAIL]'); - $tableName = 'pg_phalcon_double'; + $tableName = 'pg_phalcon_double'; $migrationsDir = codecept_output_dir(__FUNCTION__); $I->seeExceptionThrown( - Phalcon\Db\Exception::class, + \Phalcon\Db\Exception::class, function () use ($I, $tableName) { $I->getPhalconDb() - ->createTable($tableName, $I->getDefaultSchema(), [ - 'columns' => [ - new Column('point_double_column', [ - 'type' => Column::TYPE_DOUBLE, - 'default' => 0, - 'notNull' => false, - 'comment' => "Double typed column", - ]), - ], - ]) - ; + ->createTable($tableName, $I->getDefaultSchema(), [ + 'columns' => [ + new Column('point_double_column', [ + 'type' => Column::TYPE_DOUBLE, + 'default' => 0, + 'notNull' => false, + 'comment' => "Double typed column", + ]), + ], + ]); } ); @@ -101,27 +95,22 @@ function () use ($I, $tableName) { 'migrationsDir' => [ $migrationsDir, ], - 'config' => $I->getMigrationsConfig(), - 'tableName' => '@', + 'config' => $I->getMigrationsConfig(), + 'tableName' => '@', ]); $I->getPhalconDb() - ->dropTable($tableName) - ; + ->dropTable($tableName); Migrations::run([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); - $indexes = $I->getPhalconDb() - ->describeIndexes(Migrations::MIGRATION_LOG_TABLE) - ; + $indexes = $I->getPhalconDb()->describeIndexes(Migrations::MIGRATION_LOG_TABLE); - $I->assertFalse($I->getPhalconDb() - ->tableExists($tableName, $I->getDefaultSchema())); - $I->assertTrue($I->getPhalconDb() - ->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); + $I->assertFalse($I->getPhalconDb()->tableExists($tableName, $I->getDefaultSchema())); + $I->assertTrue($I->getPhalconDb()->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); $I->assertSame(1, count($indexes)); } @@ -132,47 +121,42 @@ public function testIssue111Fixed(PostgresqlTester $I): void { $I->wantToTest('Issue #111 - Unrecognized PostgreSQL data type [FIXED]'); - $tableName = 'pg_phalcon_double'; + $tableName = 'pg_phalcon_double'; $migrationsDir = codecept_output_dir(__FUNCTION__); $I->getPhalconDb() - ->createTable($tableName, $I->getDefaultSchema(), [ - 'columns' => [ - new Column('point_double_column', [ - 'type' => Column::TYPE_FLOAT, - 'default' => 0, - 'notNull' => false, - 'comment' => "Double typed column", - ]), - ], - ]) - ; + ->createTable($tableName, $I->getDefaultSchema(), [ + 'columns' => [ + new Column('point_double_column', [ + 'type' => Column::TYPE_FLOAT, + 'default' => 0, + 'notNull' => false, + 'comment' => "Double typed column", + ]), + ], + ]); ob_start(); Migrations::generate([ 'migrationsDir' => [ $migrationsDir, ], - 'config' => $I->getMigrationsConfig(), - 'tableName' => '@', + 'config' => $I->getMigrationsConfig(), + 'tableName' => '@', ]); $I->getPhalconDb() - ->dropTable($tableName) - ; + ->dropTable($tableName); Migrations::run([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); $indexes = $I->getPhalconDb() - ->describeIndexes(Migrations::MIGRATION_LOG_TABLE) - ; + ->describeIndexes(Migrations::MIGRATION_LOG_TABLE); - $I->assertTrue($I->getPhalconDb() - ->tableExists($tableName, $I->getDefaultSchema())); - $I->assertTrue($I->getPhalconDb() - ->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); + $I->assertTrue($I->getPhalconDb()->tableExists($tableName, $I->getDefaultSchema())); + $I->assertTrue($I->getPhalconDb()->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); $I->assertSame(1, count($indexes)); } @@ -185,24 +169,21 @@ public function testIssue112(PostgresqlTester $I): void $tableName = 'pg_phalcon_primary_index'; $I->getPhalconDb() - ->createTable($tableName, $I->getDefaultSchema(), [ - 'columns' => [ - new Column('id', [ - 'type' => Column::TYPE_INTEGER, - 'notNull' => true, - 'first' => true, - ]), - ], - 'indexes' => [ - new Index('pk_id_0', ['id'], 'PRIMARY KEY'), - ], - ]) - ; - - $indexes = $I->getPhalconDb() - ->describeIndexes($tableName, $I->getDefaultSchema()) - ; - $index = array_shift($indexes); + ->createTable($tableName, $I->getDefaultSchema(), [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'notNull' => true, + 'first' => true, + ]), + ], + 'indexes' => [ + new Index('pk_id_0', ['id'], 'PRIMARY KEY'), + ], + ]); + + $indexes = $I->getPhalconDb()->describeIndexes($tableName, $I->getDefaultSchema()); + $index = array_shift($indexes); $I->assertSame(PdoPostgresql::INDEX_TYPE_PRIMARY, $index->getType()); } diff --git a/tests/postgresql/MigrationsCest.php b/tests/postgresql/MigrationsCest.php index 548fe01..e18d2b4 100644 --- a/tests/postgresql/MigrationsCest.php +++ b/tests/postgresql/MigrationsCest.php @@ -25,49 +25,41 @@ final class MigrationsCest */ public function postgresPhalconMigrationsTable(PostgresqlTester $I): void { - $tableName = 'pg_phalcon_migrations'; + $tableName = 'pg_phalcon_migrations'; $migrationsDir = codecept_output_dir(__FUNCTION__); - $I->getPhalconDb() - ->createTable($tableName, $I->getDefaultSchema(), [ - 'columns' => [ - new Column('column_name', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 10, - 'unsigned' => true, - 'notNull' => true, - 'first' => true, - ]), - ], - ]) - ; + $I->getPhalconDb()->createTable($tableName, $I->getDefaultSchema(), [ + 'columns' => [ + new Column('column_name', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 10, + 'unsigned' => true, + 'notNull' => true, + 'first' => true, + ]), + ], + ]); ob_start(); Migrations::generate([ 'migrationsDir' => [ $migrationsDir, ], - 'config' => $I->getMigrationsConfig(), - 'tableName' => '@', + 'config' => $I->getMigrationsConfig(), + 'tableName' => '@', ]); - $I->getPhalconDb() - ->dropTable($tableName) - ; + $I->getPhalconDb()->dropTable($tableName); Migrations::run([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), 'migrationsInDb' => true, ]); ob_clean(); - $indexes = $I->getPhalconDb() - ->describeIndexes(Migrations::MIGRATION_LOG_TABLE) - ; + $indexes = $I->getPhalconDb()->describeIndexes(Migrations::MIGRATION_LOG_TABLE); - $I->assertTrue($I->getPhalconDb() - ->tableExists($tableName, $I->getDefaultSchema())); - $I->assertTrue($I->getPhalconDb() - ->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); + $I->assertTrue($I->getPhalconDb()->tableExists($tableName, $I->getDefaultSchema())); + $I->assertTrue($I->getPhalconDb()->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); $I->assertSame(1, count($indexes)); } @@ -78,43 +70,36 @@ public function postgresPhalconMigrationsTable(PostgresqlTester $I): void */ public function generateWithExportOnCreate(PostgresqlTester $I): void { - $dbName = $_ENV['POSTGRES_TEST_DB_SCHEMA']; - $tableName = 'on_create'; + $dbName = $_ENV['POSTGRES_TEST_DB_SCHEMA']; + $tableName = 'on_create'; $migrationsDir = codecept_output_dir(__FUNCTION__); $I->getPhalconDb() - ->createTable($tableName, $dbName, [ - 'columns' => [ - new Column('id', [ - 'type' => Column::TYPE_INTEGER, - 'size' => 10, - 'unsigned' => true, - 'notNull' => true, - 'first' => true, - 'primary' => true, - 'autoIncrement' => true, - ]), - ], - ]) - ; + ->createTable($tableName, $dbName, [ + 'columns' => [ + new Column('id', [ + 'type' => Column::TYPE_INTEGER, + 'size' => 10, + 'unsigned' => true, + 'notNull' => true, + 'first' => true, + 'primary' => true, + 'autoIncrement' => true, + ]), + ], + ]); - $I->getPhalconDb() - ->insert($tableName, [1], ['id']) - ; - $I->getPhalconDb() - ->insert($tableName, [2], ['id']) - ; - $I->getPhalconDb() - ->insert($tableName, [3], ['id']) - ; + $I->getPhalconDb()->insert($tableName, [1], ['id']); + $I->getPhalconDb()->insert($tableName, [2], ['id']); + $I->getPhalconDb()->insert($tableName, [3], ['id']); ob_start(); Migrations::generate([ - 'migrationsDir' => $migrationsDir, - 'config' => $I->getMigrationsConfig(), - 'tableName' => '@', + 'migrationsDir' => $migrationsDir, + 'config' => $I->getMigrationsConfig(), + 'tableName' => '@', 'noAutoIncrement' => true, - 'exportData' => 'oncreate', + 'exportData' => 'oncreate', ]); ob_clean();