diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc30100..69e2a18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,12 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - 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 diff --git a/composer.json b/composer.json index 0ed3d09..300fe43 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,25 @@ } }, "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", + "tools-setup": "phive install", + "test": "phpunit" }, "require": { - "cakephp/cakephp": "^4.0" + "php": ">=8.1", + "cakephp/cakephp": "^5.0.0" }, "require-dev": { - "cakephp/cakephp-codesniffer": "^4.0" + "cakephp/cakephp-codesniffer": "^5.0" }, "support": { "source": "https://github.com/FriendsOfCake/fixturize", diff --git a/src/TestSuite/Fixture/ChecksumTestFixture.php b/src/TestSuite/Fixture/ChecksumTestFixture.php index 47a05e7..499f7fc 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 $_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 $db 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, + * @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 $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 +53,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 +73,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 +93,16 @@ 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(); + assert($connection instanceof Connection); + $driver = $connection->getDriver(); if ($driver instanceof Mysql) { - $sth = $db->execute('CHECKSUM TABLE `' . $this->table . '`'); + $sth = $connection->execute('CHECKSUM TABLE `' . $this->table . '`'); return (string)$sth->fetchColumn(1); }