Skip to content

Commit

Permalink
initial upgrade to CakePHP5, added editor config
Browse files Browse the repository at this point in the history
  • Loading branch information
arusinowski committed Aug 5, 2023
1 parent 186e1df commit 8af8ceb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 46 deletions.
21 changes: 11 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
35 changes: 32 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/*
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
49 changes: 18 additions & 31 deletions src/TestSuite/Fixture/ChecksumTestFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ class ChecksumTestFixture extends TestFixture
*
* @var array<string, string>
*/
protected static $_tableHashes = [];
protected static array $_tableHashes = [];

/**
* Inserts records in the database
*
* 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;
}
Expand All @@ -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);
}

/**
Expand All @@ -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;
}

Expand All @@ -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);
}
Expand Down

0 comments on commit 8af8ceb

Please sign in to comment.