From 8af8ceb9b57f1588da68d6aff1ce0923a7c1792f Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Sat, 5 Aug 2023 14:28:59 +0200 Subject: [PATCH 1/8] initial upgrade to CakePHP5, added editor config --- .editorconfig | 21 ++++---- .gitignore | 35 +++++++++++-- composer.json | 7 ++- src/TestSuite/Fixture/ChecksumTestFixture.php | 49 +++++++------------ 4 files changed, 66 insertions(+), 46 deletions(-) diff --git a/.editorconfig b/.editorconfig index 13d94df..f7e2a69 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,20 +1,21 @@ -; This file is for unifying the coding style for different editors and IDEs. -; More information at http://editorconfig.org +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org -root = false +root = true [*] +end_of_line = lf +charset = utf-8 indent_style = space indent_size = 4 -charset = "utf-8" -end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.yml] -indent_style = space -indent_size = 2 - [*.neon] indent_style = tab -indent_size = 4 + +[phars.xml] +indent_size = 2 + +[*.js] +indent_size = 2 diff --git a/.gitignore b/.gitignore index 2e8ba9c..6ed876f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,35 @@ *.pyc docs/_build -phpunit.xml -vendor/ -composer.lock tmp +/composer.lock +*.diff +*.err +*.log +*.orig +*.rej +*.swo +*.swp +*.vi +*~ +.idea/* +nbproject/* +.vscode +.DS_Store +.cache +.phpunit.cache +.project +.settings +.svn +errors.err +tags +node_modules +package-lock.json +/.phpunit.result.cache +/nbproject/ +/tools +/vendor +/phpunit.xml +/webroot/css/style.css.map +/webroot/mix.js.map +/webroot/mix-manifest.json +.ddev/* diff --git a/composer.json b/composer.json index 19322b4..a63ff31 100644 --- a/composer.json +++ b/composer.json @@ -34,11 +34,14 @@ "cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/" }, "require": { - "cakephp/cakephp": "^4.0" + "php": ">=8.1", + "cakephp/cakephp": "5.x-dev" }, "require-dev": { - "cakephp/cakephp-codesniffer": "^4.0" + "cakephp/cakephp-codesniffer": "^5.0" }, + "minimum-stability": "dev", + "prefer-stable": true, "support": { "source": "https://github.com/FriendsOfCake/fixturize", "issues": "https://github.com/FriendsOfCake/fixturize/issues", diff --git a/src/TestSuite/Fixture/ChecksumTestFixture.php b/src/TestSuite/Fixture/ChecksumTestFixture.php index d26f0d8..a5bcb1b 100644 --- a/src/TestSuite/Fixture/ChecksumTestFixture.php +++ b/src/TestSuite/Fixture/ChecksumTestFixture.php @@ -21,7 +21,7 @@ class ChecksumTestFixture extends TestFixture * * @var array */ - protected static $_tableHashes = []; + protected static array $_tableHashes = []; /** * Inserts records in the database @@ -29,19 +29,19 @@ class ChecksumTestFixture extends TestFixture * This will only happen if the underlying table is modified in any way or * does not exist with a hash yet. * - * @param \Cake\Datasource\ConnectionInterface $db An instance of the connection + * @param \Cake\Datasource\ConnectionInterface $connection An instance of the connection * into which the records will be inserted. - * @return \Cake\Database\StatementInterface|bool on success or if there are no records to insert, + * @return bool on success or if there are no records to insert, * or false on failure. */ - public function insert(ConnectionInterface $db) + public function insert(ConnectionInterface $connection): bool { - if ($this->_tableUnmodified($db)) { + if ($this->_tableUnmodified($connection)) { return true; } - $result = parent::insert($db); - static::$_tableHashes[$this->_getTableKey()] = $this->_hash($db); + $result = parent::insert($connection); + static::$_tableHashes[$this->_getTableKey()] = $this->_hash($connection); return $result; } @@ -51,29 +51,16 @@ public function insert(ConnectionInterface $db) * * This will only happen if the underlying table is modified in any way * - * @param \Cake\Datasource\ConnectionInterface $db A reference to a db instance + * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return bool */ - public function truncate(ConnectionInterface $db): bool + public function truncate(ConnectionInterface $connection): bool { - if ($this->_tableUnmodified($db)) { + if ($this->_tableUnmodified($connection)) { return true; } - return parent::truncate($db); - } - - /** - * Drops the table from the test datasource - * - * @param \Cake\Datasource\ConnectionInterface $db An instance of the connection the fixture should be removed from. - * @return bool True on success, false on failure. - */ - public function drop(ConnectionInterface $db): bool - { - unset(static::$_tableHashes[$this->_getTableKey()]); - - return parent::drop($db); + return parent::truncate($connection); } /** @@ -84,17 +71,17 @@ public function drop(ConnectionInterface $db): bool * In all other cases where the initial and current hash differs, assume * the table has changed * - * @param \Cake\Datasource\ConnectionInterface $db A reference to a db instance + * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return bool */ - protected function _tableUnmodified(ConnectionInterface $db): bool + protected function _tableUnmodified(ConnectionInterface $connection): bool { $tableKey = $this->_getTableKey(); if (!array_key_exists($tableKey, static::$_tableHashes)) { return false; } - if (static::$_tableHashes[$tableKey] === $this->_hash($db)) { + if (static::$_tableHashes[$tableKey] === $this->_hash($connection)) { return true; } @@ -104,15 +91,15 @@ protected function _tableUnmodified(ConnectionInterface $db): bool /** * Get the table hash from MySQL for a specific table * - * @param \Cake\Datasource\ConnectionInterface $db A reference to a db instance + * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return string */ - protected function _hash(ConnectionInterface $db): string + protected function _hash(ConnectionInterface $connection): string { - $driver = $db->getDriver(); + $driver = $connection->getDriver(); if ($driver instanceof Mysql) { - $sth = $db->execute('CHECKSUM TABLE `' . $this->table . '`'); + $sth = $connection->execute('CHECKSUM TABLE `' . $this->table . '`'); return $sth->fetchColumn(1); } From 8833a31809c1cf610cd159de4f7fa5d772676c9b Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Fri, 11 Aug 2023 13:55:21 +0200 Subject: [PATCH 2/8] updated github ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc30100..7d086b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.1' extensions: mbstring, intl coverage: none tools: phpstan:1.10, cs2pr From e8dd8b5055d3967c7ea27993237d736995345ffe Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Sat, 12 Aug 2023 15:54:12 +0200 Subject: [PATCH 3/8] reverted .editorconfig and .gitignore changes --- .editorconfig | 21 ++++++++++----------- .gitignore | 35 +++-------------------------------- 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/.editorconfig b/.editorconfig index f7e2a69..13d94df 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,21 +1,20 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org -root = true +root = false [*] -end_of_line = lf -charset = utf-8 indent_style = space indent_size = 4 +charset = "utf-8" +end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[*.neon] -indent_style = tab - -[phars.xml] +[*.yml] +indent_style = space indent_size = 2 -[*.js] -indent_size = 2 +[*.neon] +indent_style = tab +indent_size = 4 diff --git a/.gitignore b/.gitignore index 6ed876f..2e8ba9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,35 +1,6 @@ *.pyc docs/_build +phpunit.xml +vendor/ +composer.lock tmp -/composer.lock -*.diff -*.err -*.log -*.orig -*.rej -*.swo -*.swp -*.vi -*~ -.idea/* -nbproject/* -.vscode -.DS_Store -.cache -.phpunit.cache -.project -.settings -.svn -errors.err -tags -node_modules -package-lock.json -/.phpunit.result.cache -/nbproject/ -/tools -/vendor -/phpunit.xml -/webroot/css/style.css.map -/webroot/mix.js.map -/webroot/mix-manifest.json -.ddev/* From cb406899653faf680c3ce151ca09967bfe11679d Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Tue, 29 Aug 2023 09:54:17 +0200 Subject: [PATCH 4/8] cc, removed php version from composer --- composer.json | 15 ++++++-- src/TestSuite/Fixture/ChecksumTestFixture.php | 35 ++++++++++--------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index a63ff31..9011290 100644 --- a/composer.json +++ b/composer.json @@ -30,11 +30,20 @@ } }, "scripts": { - "cs-check": "phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/", - "cs-fix": "phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/" + "cs-check": "phpcs --colors --parallel=16 -p src/", + "cs-fix": "phpcbf --colors --parallel=16 -p src/", + "phpstan": "tools/phpstan analyse", + "psalm": "tools/psalm --show-info=false", + "stan": [ + "@phpstan", + "@psalm" + ], + "stan-baseline": "tools/phpstan --generate-baseline", + "psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml", + "stan-setup": "phive install", + "test": "phpunit" }, "require": { - "php": ">=8.1", "cakephp/cakephp": "5.x-dev" }, "require-dev": { diff --git a/src/TestSuite/Fixture/ChecksumTestFixture.php b/src/TestSuite/Fixture/ChecksumTestFixture.php index a5bcb1b..14cfaa1 100644 --- a/src/TestSuite/Fixture/ChecksumTestFixture.php +++ b/src/TestSuite/Fixture/ChecksumTestFixture.php @@ -3,16 +3,18 @@ namespace FriendsOfCake\Fixturize\TestSuite\Fixture; +use Cake\Database\Connection; use Cake\Database\Driver\Mysql; use Cake\Datasource\ConnectionInterface; use Cake\TestSuite\Fixture\TestFixture; /** - * This class will inspect the database table hash and detect any change to the underlying - * data set and automatically re-create the table and data + * This class will inspect the database table hash and detect any change to + * the underlying data set and automatically re-create the table and data * - * If no data has changed, the usual truncate/insert flow is bypassed, increasing the speed - * of the test suite with heavy fixture usage up significantly. + * If no data has changed, the usual truncate/insert flow is bypassed, + * increasing the speed of the test suite with heavy fixture usage up + * significantly. */ class ChecksumTestFixture extends TestFixture { @@ -21,7 +23,7 @@ class ChecksumTestFixture extends TestFixture * * @var array */ - protected static array $_tableHashes = []; + protected static array $tableHashes = []; /** * Inserts records in the database @@ -29,19 +31,19 @@ class ChecksumTestFixture extends TestFixture * This will only happen if the underlying table is modified in any way or * does not exist with a hash yet. * - * @param \Cake\Datasource\ConnectionInterface $connection An instance of the connection - * into which the records will be inserted. + * @param \Cake\Datasource\ConnectionInterface $connection An instance + * of the connection into which the records will be inserted. * @return bool on success or if there are no records to insert, * or false on failure. */ public function insert(ConnectionInterface $connection): bool { - if ($this->_tableUnmodified($connection)) { + if ($this->tableUnmodified($connection)) { return true; } $result = parent::insert($connection); - static::$_tableHashes[$this->_getTableKey()] = $this->_hash($connection); + static::$tableHashes[$this->getTableKey()] = $this->hash($connection); return $result; } @@ -56,7 +58,7 @@ public function insert(ConnectionInterface $connection): bool */ public function truncate(ConnectionInterface $connection): bool { - if ($this->_tableUnmodified($connection)) { + if ($this->tableUnmodified($connection)) { return true; } @@ -74,14 +76,14 @@ public function truncate(ConnectionInterface $connection): bool * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return bool */ - protected function _tableUnmodified(ConnectionInterface $connection): bool + protected function tableUnmodified(ConnectionInterface $connection): bool { - $tableKey = $this->_getTableKey(); - if (!array_key_exists($tableKey, static::$_tableHashes)) { + $tableKey = $this->getTableKey(); + if (!array_key_exists($tableKey, static::$tableHashes)) { return false; } - if (static::$_tableHashes[$tableKey] === $this->_hash($connection)) { + if (static::$tableHashes[$tableKey] === $this->hash($connection)) { return true; } @@ -94,8 +96,9 @@ protected function _tableUnmodified(ConnectionInterface $connection): bool * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return string */ - protected function _hash(ConnectionInterface $connection): string + protected function hash(ConnectionInterface $connection): string { + assert($connection instanceof Connection); $driver = $connection->getDriver(); if ($driver instanceof Mysql) { @@ -113,7 +116,7 @@ protected function _hash(ConnectionInterface $connection): string * * @return string key for specify connection and table */ - protected function _getTableKey(): string + protected function getTableKey(): string { return $this->connection() . '-' . $this->table; } From 80dfc44c3e6477158438e0867dc76845e9d415da Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Sat, 23 Sep 2023 11:13:16 +0200 Subject: [PATCH 5/8] updated composer.json to use stable CakePHP5 --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9011290..2147637 100644 --- a/composer.json +++ b/composer.json @@ -44,13 +44,11 @@ "test": "phpunit" }, "require": { - "cakephp/cakephp": "5.x-dev" + "cakephp/cakephp": "^5.0.0" }, "require-dev": { "cakephp/cakephp-codesniffer": "^5.0" }, - "minimum-stability": "dev", - "prefer-stable": true, "support": { "source": "https://github.com/FriendsOfCake/fixturize", "issues": "https://github.com/FriendsOfCake/fixturize/issues", From 0e89ed3f7ea9523332d0f96d254f32910d70a5da Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Sun, 24 Sep 2023 11:04:06 +0200 Subject: [PATCH 6/8] added minimum php version to composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 2147637..7fe5aca 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "test": "phpunit" }, "require": { + "php": ">=8.1", "cakephp/cakephp": "^5.0.0" }, "require-dev": { From a779fc676d5b1d6bd611018c6308cba3b0509c1d Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Mon, 25 Sep 2023 09:33:27 +0200 Subject: [PATCH 7/8] restored underscore --- src/TestSuite/Fixture/ChecksumTestFixture.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/TestSuite/Fixture/ChecksumTestFixture.php b/src/TestSuite/Fixture/ChecksumTestFixture.php index 14cfaa1..12e7a16 100644 --- a/src/TestSuite/Fixture/ChecksumTestFixture.php +++ b/src/TestSuite/Fixture/ChecksumTestFixture.php @@ -23,7 +23,7 @@ class ChecksumTestFixture extends TestFixture * * @var array */ - protected static array $tableHashes = []; + protected static array $_tableHashes = []; /** * Inserts records in the database @@ -43,7 +43,7 @@ public function insert(ConnectionInterface $connection): bool } $result = parent::insert($connection); - static::$tableHashes[$this->getTableKey()] = $this->hash($connection); + static::$_tableHashes[$this->getTableKey()] = $this->hash($connection); return $result; } @@ -79,11 +79,11 @@ public function truncate(ConnectionInterface $connection): bool protected function tableUnmodified(ConnectionInterface $connection): bool { $tableKey = $this->getTableKey(); - if (!array_key_exists($tableKey, static::$tableHashes)) { + if (!array_key_exists($tableKey, static::$_tableHashes)) { return false; } - if (static::$tableHashes[$tableKey] === $this->hash($connection)) { + if (static::$_tableHashes[$tableKey] === $this->hash($connection)) { return true; } From fa433c99c4ada475a5caff6bae610a94a6909fa7 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Mon, 25 Sep 2023 15:15:00 +0200 Subject: [PATCH 8/8] restored underscores in protected methods, updated composer.json --- composer.json | 2 +- src/TestSuite/Fixture/ChecksumTestFixture.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 7fe5aca..b6cf8d4 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ ], "stan-baseline": "tools/phpstan --generate-baseline", "psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml", - "stan-setup": "phive install", + "tools-setup": "phive install", "test": "phpunit" }, "require": { diff --git a/src/TestSuite/Fixture/ChecksumTestFixture.php b/src/TestSuite/Fixture/ChecksumTestFixture.php index 12e7a16..a4a31ce 100644 --- a/src/TestSuite/Fixture/ChecksumTestFixture.php +++ b/src/TestSuite/Fixture/ChecksumTestFixture.php @@ -38,12 +38,12 @@ class ChecksumTestFixture extends TestFixture */ public function insert(ConnectionInterface $connection): bool { - if ($this->tableUnmodified($connection)) { + if ($this->_tableUnmodified($connection)) { return true; } $result = parent::insert($connection); - static::$_tableHashes[$this->getTableKey()] = $this->hash($connection); + static::$_tableHashes[$this->_getTableKey()] = $this->_hash($connection); return $result; } @@ -58,7 +58,7 @@ public function insert(ConnectionInterface $connection): bool */ public function truncate(ConnectionInterface $connection): bool { - if ($this->tableUnmodified($connection)) { + if ($this->_tableUnmodified($connection)) { return true; } @@ -76,14 +76,14 @@ public function truncate(ConnectionInterface $connection): bool * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return bool */ - protected function tableUnmodified(ConnectionInterface $connection): bool + protected function _tableUnmodified(ConnectionInterface $connection): bool { - $tableKey = $this->getTableKey(); + $tableKey = $this->_getTableKey(); if (!array_key_exists($tableKey, static::$_tableHashes)) { return false; } - if (static::$_tableHashes[$tableKey] === $this->hash($connection)) { + if (static::$_tableHashes[$tableKey] === $this->_hash($connection)) { return true; } @@ -96,7 +96,7 @@ protected function tableUnmodified(ConnectionInterface $connection): bool * @param \Cake\Datasource\ConnectionInterface $connection A reference to a db instance * @return string */ - protected function hash(ConnectionInterface $connection): string + protected function _hash(ConnectionInterface $connection): string { assert($connection instanceof Connection); $driver = $connection->getDriver(); @@ -116,7 +116,7 @@ protected function hash(ConnectionInterface $connection): string * * @return string key for specify connection and table */ - protected function getTableKey(): string + protected function _getTableKey(): string { return $this->connection() . '-' . $this->table; }