From ed5742f1f8816161b3bea8d8a155c61e4824f70d Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Tue, 28 Nov 2023 14:17:57 +0100 Subject: [PATCH 1/9] updated composer, added phpstan, psalm and phpcs, fixed issues reported by phpcs, updated copyright --- .editorconfig | 16 +++++++-- .gitignore | 32 +++++++++++++++-- .phive/phars.xml | 5 +++ .semver | 2 +- Docs/Documentation/Installation.md | 12 ++++--- Docs/Documentation/Overview.md | 11 +++--- Docs/Home.md | 6 ++-- LICENSE.txt | 2 +- composer.json | 23 ++++++++----- phpcs.xml | 6 ++++ phpstan.neon | 10 +++--- psalm.xml | 25 ++++++++++++++ readme.md | 11 +++--- src/Engine/BaseEngine.php | 6 ++-- src/Engine/EngineFactory.php | 11 +++--- src/Engine/EngineInterface.php | 7 ++-- src/Engine/MysqlEngine.php | 15 ++++---- src/Engine/PostgresEngine.php | 11 +++--- src/Engine/Traits/ExecuteTrait.php | 6 ++-- src/Plugin.php | 8 ++--- src/Shell/DbTestShell.php | 11 +++--- src/Shell/FixtureImportShell.php | 13 +++---- src/TestSuite/Fixture/FixtureInjector.php | 42 +++++++++++------------ src/TestSuite/Fixture/FixtureManager.php | 12 +++---- 24 files changed, 198 insertions(+), 105 deletions(-) create mode 100644 .phive/phars.xml create mode 100644 phpcs.xml create mode 100644 psalm.xml diff --git a/.editorconfig b/.editorconfig index bd0ddd7..ae35877 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,16 +1,26 @@ ; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org -root = false +root = true [*] indent_style = space indent_size = 4 -charset = "utf-8" end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true +[*.bat] +end_of_line = crlf + [*.yml] -indent_style = space indent_size = 2 + +[*.xml] +indent_size = 2 + +[Makefile] +indent_style = tab + +[*.neon] +indent_style = tab \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7739fcc..601dfed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,31 @@ -.idea +*.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/ +/composer.lock +/tools /vendor -composer.lock +/phpunit.xml +/webroot/css/style.css.map +/webroot/mix.js.map +/webroot/mix-manifest.json diff --git a/.phive/phars.xml b/.phive/phars.xml new file mode 100644 index 0000000..a8aff29 --- /dev/null +++ b/.phive/phars.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.semver b/.semver index 1765201..f5ef8df 100644 --- a/.semver +++ b/.semver @@ -1,5 +1,5 @@ --- -:major: 2 +:major: 3 :minor: 0 :patch: 0 :special: '' diff --git a/Docs/Documentation/Installation.md b/Docs/Documentation/Installation.md index ffb95a7..fd518fe 100644 --- a/Docs/Documentation/Installation.md +++ b/Docs/Documentation/Installation.md @@ -14,12 +14,13 @@ Load the plugin ``` bin/cake plugin load CakeDC/DbTest ``` -Note you'll need this plugin loaded in the `cli` section of your `Application::bootstrap`, around the line loading Bake Plugin: `$this->addPlugin('Bake');` +Note you'll need this plugin loaded in the `cli` section of your `Application::bootstrap`, around the line loading +Bake Plugin: `$this->addPlugin('Bake');` Configuration ------------- -Plugin requires an additional database connection to create the database snapshot named **test_template**. +Plugin requires an additional database connection to create the database snapshot named **test_template**. This connection is used as an unchangeable source of test fixtures. Add the next configuration setting into app.php @@ -44,11 +45,14 @@ Add the next configuration setting into app.php PHPUnit ------- -Copy https://github.com/CakeDC/cakephp-db-test/blob/master/phpunit.xml.dbtest as phpunit.xml.dist in your project (modify if needed) +Copy https://github.com/CakeDC/cakephp-db-test/blob/master/phpunit.xml.dbtest as phpunit.xml.dist in your +project (modify if needed) Fixture database ---------------- -Note from now on, you will NOT use fixture files, but rely on a "fixture database" allowing you to run migrations to it, modify your fixture data with your sql editor, or import fixtures from the live database using a regular table or database import tool, for example `mysqldump`. +Note from now on, you will NOT use fixture files, but rely on a "fixture database" allowing you to run +migrations to it, modify your fixture data with your sql editor, or import fixtures from the live +database using a regular table or database import tool, for example `mysqldump`. diff --git a/Docs/Documentation/Overview.md b/Docs/Documentation/Overview.md index ffe2078..8912cf9 100644 --- a/Docs/Documentation/Overview.md +++ b/Docs/Documentation/Overview.md @@ -15,7 +15,8 @@ Generic cycle of test execution under DbTest * Before test method starts, DbTest initializes the transaction. * After test method finishes, DbTest rollbacks transaction. -This way database modifications are quickly restored, but requires that the table uses a transaction engine like InnoDb. +This way database modifications are quickly restored, but requires that the table uses a transaction engine +like InnoDb. Support ------- @@ -27,11 +28,13 @@ Commercial support is also available, [contact us](http://cakedc.com/contact) fo Contributing ------------ -If you'd like to contribute new features, enhancements or bug fixes to the plugin, just read our [Contribution Guidelines](http://cakedc.com/plugins) for detailed instructions. +If you'd like to contribute new features, enhancements or bug fixes to the plugin, just read our +[Contribution Guidelines](http://cakedc.com/plugins) for detailed instructions. License ------- -Copyright 2007-2014 Cake Development Corporation (CakeDC). All rights reserved. +Copyright 2013-2023 Cake Development Corporation (CakeDC). All rights reserved. -Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file. +Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository +must retain the copyright notice found in each file. diff --git a/Docs/Home.md b/Docs/Home.md index 100fa4f..2cbb45b 100644 --- a/Docs/Home.md +++ b/Docs/Home.md @@ -6,11 +6,11 @@ The **DbTest** plugin enables developers to speeding up tests running on MySQL o Requirements ------------ -* CakePHP 3.5+ -* PHP 5.6.0+ +* CakePHP 5.0+ +* PHP 8.1+ * MySQL database with InnoDb engine * PostgreSQL database -* Phpunit 6.* +* Phpunit 10.* Documentation ------------- diff --git a/LICENSE.txt b/LICENSE.txt index d1103cd..a74c38b 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License -Copyright 2009-2020 +Copyright 2009-2023 Cake Development Corporation 1785 E. Sahara Avenue, Suite 490-423 Las Vegas, Nevada 89104 diff --git a/composer.json b/composer.json index 7dcaccb..4820dc5 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,7 @@ "name": "cakedc/cakephp-db-test", "description": "DbTest plugin for CakePHP", "type": "cakephp-plugin", + "license": "MIT", "require": { "php": ">=8.1", "cakephp/cakephp": "^5.0" @@ -21,20 +22,24 @@ "Cake\\Test\\": "./vendor/cakephp/cakephp/tests" } }, - "minimum-stability": "dev", - "prefer-stable": true, "scripts": { "check": [ "@cs-check", "@test" ], - "cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/", - "cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/", - "test": "phpunit", - "stan": "phpstan analyse src/ && psalm --show-info=false", - "psalm": "psalm --show-info=false", - "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.11 vimeo/psalm:^3.0 && mv composer.backup composer.json", - "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:^0.4.11 && mv composer.backup composer.json", "test-coverage": "phpunit --coverage-clover=clover.xml" + "cs-check": "phpcs --colors --parallel=16 -p src/ tests/", + "cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/", + "phpstan": "tools/phpstan analyse", + "psalm": "tools/psalm --show-info=false", + "stan": [ + "@phpstan", + "@psalm" + ], + "phpstan-tests": "tools/phpstan analyze -c tests/phpstan.neon", + "phpstan-baseline": "tools/phpstan --generate-baseline", + "psalm-baseline": "tools/psalm --set-baseline=psalm-baseline.xml", + "stan-setup": "phive install", + "test": "phpunit" }, "config": { "allow-plugins": { diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..1852cfd --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/phpstan.neon b/phpstan.neon index 886fec2..712bed1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,6 @@ parameters: - level: 6 - autoload_files: - - tests/bootstrap.php - ignoreErrors: - - '#Parameter \#1 $fp of function fwrite expects resource, resource|false given#' + level: 8 + treatPhpDocTypesAsCertain: false + checkGenericClassInNonGenericObjectType: false + paths: + - src/ diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..69a2070 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + diff --git a/readme.md b/readme.md index 1d4c09f..ef6242f 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,6 @@ DbTest Plugin ======================== -[![Bake Status](https://secure.travis-ci.org/CakeDC/cakephp-db-test.png?branch=master)](http://travis-ci.org/CakeDC/cakephp-db-test) [![Test Coverage](https://coveralls.io/repos/CakeDC/cakephp-db-test/badge.png?branch=master)](https://coveralls.io/r/CakeDC/cakephp-db-test?branch=master) [![Downloads](https://poser.pugx.org/CakeDC/cakephp-db-test/d/total.png)](https://packagist.org/packages/CakeDC/cakephp-db-test) [![Latest Version](https://poser.pugx.org/CakeDC/cakephp-db-test/v/stable.png)](https://packagist.org/packages/CakeDC/cakephp-db-test) @@ -11,11 +10,11 @@ The **DbTest** plugin enables developers to speeding up tests running on MySQL o Requirements ------------ -* CakePHP 4.0+ -* PHP 7.2.0+ +* CakePHP 5.0+ +* PHP 8.1+ * MySQL database with InnoDb engine * PostgreSQL database -* Phpunit 8.* +* Phpunit 10.* Documentation ------------- @@ -25,7 +24,7 @@ For documentation, as well as tutorials, see the [Docs](Docs/Home.md) directory Support ------- -For bugs and feature requests, please use the [issues](https://git.cakedc.com/cakedc/db_test/issues) section of this repository. +For bugs and feature requests, please use the [issues](https://git.cakedc.com/cakedc/db_test/issues) section of this repository. Commercial support is also available, [contact us](http://cakedc.com/contact) for more information. @@ -37,6 +36,6 @@ If you'd like to contribute new features, enhancements or bug fixes to the plugi License ------- -Copyright 2007-2020 Cake Development Corporation (CakeDC). All rights reserved. +Copyright 2013-2023 Cake Development Corporation (CakeDC). All rights reserved. Licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) License. Redistributions of the source code included in this repository must retain the copyright notice found in each file. diff --git a/src/Engine/BaseEngine.php b/src/Engine/BaseEngine.php index 48a09a7..16a80dc 100644 --- a/src/Engine/BaseEngine.php +++ b/src/Engine/BaseEngine.php @@ -1,11 +1,13 @@ '\\CakeDC\\DbTest\\Engine\\MysqlEngine', - 'Postgres' => '\\CakeDC\\DbTest\\Engine\\PostgresEngine' + 'Postgres' => '\\CakeDC\\DbTest\\Engine\\PostgresEngine', ]; $type = str_replace('Cake\\Database\\Driver\\', '', $driver); diff --git a/src/Engine/EngineInterface.php b/src/Engine/EngineInterface.php index 162ee2b..30e384a 100644 --- a/src/Engine/EngineInterface.php +++ b/src/Engine/EngineInterface.php @@ -1,18 +1,19 @@ _database['database']; $baseArgs = $this->_getBaseArguments(); - $command = "mysqldump"; + $command = 'mysqldump'; if (Configure::read('DbTest.dumpExtendedInserts') !== true) { - $command .= " --extended-insert=FALSE"; + $command .= ' --extended-insert=FALSE'; } if (Configure::read('DbTest.dumpNoTablespaces') === true) { - $command .= " --no-tablespaces"; + $command .= ' --no-tablespaces'; } $command .= " $baseArgs $databaseName | grep -v -a '/*!50013 DEFINER'"; if (!empty($file)) { @@ -91,7 +92,7 @@ protected function _getBaseArguments() $host = $this->_database['host']; $port = ''; if (!empty($this->_database['port'])) { - $port = " --port=" . $this->_database['port']; + $port = ' --port=' . $this->_database['port']; } $quote = DS === '/' ? "'" : '"'; diff --git a/src/Engine/PostgresEngine.php b/src/Engine/PostgresEngine.php index cc3f823..a83e5c1 100644 --- a/src/Engine/PostgresEngine.php +++ b/src/Engine/PostgresEngine.php @@ -1,11 +1,13 @@ _database['database']; $format = ' -Fc '; if (isset($options['format']) && $options['format'] == 'plain') { - $format = " -Fp "; + $format = ' -Fp '; } $command = "pg_dump $baseArgs -Z=0 --file=$file $format $testDbName"; @@ -119,7 +120,7 @@ protected function _getBaseArguments() $host = $this->_database['host']; $port = ''; if (!empty($this->_database['port'])) { - $port = " --port=" . $this->_database['port']; + $port = ' --port=' . $this->_database['port']; } return "--host=$host $port --username=$user"; diff --git a/src/Engine/Traits/ExecuteTrait.php b/src/Engine/Traits/ExecuteTrait.php index 76e497b..d2c1e56 100644 --- a/src/Engine/Traits/ExecuteTrait.php +++ b/src/Engine/Traits/ExecuteTrait.php @@ -1,11 +1,13 @@ Date: Tue, 28 Nov 2023 16:01:35 +0100 Subject: [PATCH 2/9] upgraded code to CakePHP5.x --- Docs/Documentation/Examples.md | 4 +- Docs/Documentation/Installation.md | 6 +- Docs/Documentation/Workflow.md | 4 +- src/Command/DbTestCommand.php | 73 +++++++++++++++++ src/Command/FixtureImportCommand.php | 69 ++++++++++++++++ src/{Plugin.php => DbTestPlugin.php} | 2 +- src/Engine/BaseEngine.php | 40 ++-------- src/Engine/EngineFactory.php | 22 ++++-- src/Engine/EngineInterface.php | 6 +- src/Engine/MysqlEngine.php | 25 ++---- src/Engine/PostgresEngine.php | 31 +++----- src/Engine/Traits/ExecuteTrait.php | 18 +++-- src/Shell/DbTestShell.php | 82 ------------------- src/Shell/FixtureImportShell.php | 96 ----------------------- src/TestSuite/Fixture/FixtureInjector.php | 17 ++-- src/TestSuite/Fixture/FixtureManager.php | 41 ++++++---- 16 files changed, 238 insertions(+), 298 deletions(-) create mode 100644 src/Command/DbTestCommand.php create mode 100644 src/Command/FixtureImportCommand.php rename src/{Plugin.php => DbTestPlugin.php} (92%) delete mode 100644 src/Shell/DbTestShell.php delete mode 100644 src/Shell/FixtureImportShell.php diff --git a/Docs/Documentation/Examples.md b/Docs/Documentation/Examples.md index 2759b6b..43d56cd 100644 --- a/Docs/Documentation/Examples.md +++ b/Docs/Documentation/Examples.md @@ -10,10 +10,10 @@ Importing template database form sql file, by default it will load `config/sql/t bin/cake db_test -i ``` -Use `--import-database-file` to specify the sql file to be loaded +Use `-f` to specify the sql file to be loaded ``` -bin/cake db_test -i --import-database-file=files/dump.sql +bin/cake db_test -i -f=files/dump.sql ``` diff --git a/Docs/Documentation/Installation.md b/Docs/Documentation/Installation.md index fd518fe..85a79c1 100644 --- a/Docs/Documentation/Installation.md +++ b/Docs/Documentation/Installation.md @@ -15,7 +15,7 @@ Load the plugin bin/cake plugin load CakeDC/DbTest ``` Note you'll need this plugin loaded in the `cli` section of your `Application::bootstrap`, around the line loading -Bake Plugin: `$this->addPlugin('Bake');` +Bake Plugin: `$this->addPlugin('DbTestPlugin');` Configuration ------------- @@ -30,8 +30,8 @@ Add the next configuration setting into app.php 'Datasources' => [ // ... 'test_template' => [ - 'className' => 'Cake\Database\Connection', - 'driver' => 'Cake\Database\Driver\Mysql', + 'className' => \Cake\Database\Connection::class, + 'driver' => \Cake\Database\Driver\Mysql::class, 'persistent' => false, 'host' => 'localhost', 'username' => 'my_app', diff --git a/Docs/Documentation/Workflow.md b/Docs/Documentation/Workflow.md index 1580c86..7c8eb7c 100644 --- a/Docs/Documentation/Workflow.md +++ b/Docs/Documentation/Workflow.md @@ -5,7 +5,7 @@ Adding new fixture ------------------ 1. Using any database modification tool (phpmysql, navicat, mysql) modify templates database. -2. Execute `bin/cake fixture_import dump` this will create `config/sql/test_db.sql` +2. Execute `bin/cake fixture_import` this will create `config/sql/test_db.sql` 3. Execute `bin/cake db_test -i` to import sql file. 4. Add modified sql file into repository. @@ -15,7 +15,7 @@ Update database structure To update database structure the following steps need to beperformed: 1. Apply migrations for test_template database `bin/cake migrations migrate --connection test_template` -2. Execute `bin/cake fixture_import dump` +2. Execute `bin/cake fixture_import` 3. Execute `bin/cake db_test -i` to import sql file. 4. Add modified sql file into repository. diff --git a/src/Command/DbTestCommand.php b/src/Command/DbTestCommand.php new file mode 100644 index 0000000..faf3aa8 --- /dev/null +++ b/src/Command/DbTestCommand.php @@ -0,0 +1,73 @@ +setDescription([ + __d('cake_d_c/db_test', 'The Db Test Shell extends the CakePhp TestSuite and no longer needs fixtures defined. + Instead the test and test-template databases are synchronized before each test class is executed. + Transaction wrapping used to rollback test case changes.'), + ]) + ->addOption('import-database-template', [ + 'boolean' => true, + 'short' => 'i', + 'help' => __d('cake_d_c/db_test', 'Drops test template database and imports test_db.sql file from app/Config/sql'), + ]) + ->addOption('import-database-file', [ + 'short' => 'f', + 'help' => __d('cake_d_c/db_test', 'Provides path to test_db.sql file'), + ]); + } + + /** + * @inheritdoc + */ + public function execute(Arguments $args, ConsoleIo $io) + { + Configure::load('app', 'default', false); + + $io->out(__d('cake_d_c/db_test', 'Db Test Shell')); + $io->hr(); + + if ($args->getOption('import-database-template')) { + $path = null; + if ( + !empty($args->getOption('import-database-file')) && + file_exists($args->getOption('import-database-file')) + ) { + $path = $args->getOption('import-database-file'); + } + $skeletonDatabase = ConnectionManager::get('test_template')->config(); + $manager = new FixtureManager(); + $manager->setupDatabase($skeletonDatabase, true, true, $path); + } else { + $io->out($this->getOptionParser()->help()); + } + + return self::CODE_SUCCESS; + } +} diff --git a/src/Command/FixtureImportCommand.php b/src/Command/FixtureImportCommand.php new file mode 100644 index 0000000..3a45c2b --- /dev/null +++ b/src/Command/FixtureImportCommand.php @@ -0,0 +1,69 @@ +setDescription( + __d( + 'cake_d_c/db_test', + 'DbTest fixture importer, dumps the template database' + ) + ) + ->addOption('dump-folder', [ + 'short' => 'd', + 'help' => __d('cake_d_c/db_test', 'Provides path to dump test_db.sql file.'), + ]); + } + + /** + * @inheritdoc + */ + public function execute(Arguments $args, ConsoleIo $io) + { + $skeletonDatabase = ConnectionManager::get('test_template')->config(); + + if (empty($skeletonDatabase)) { + $io->error( + __d('cake_d_c/db_test', 'Missing `test_template` datasource configuration') + ); + + return self::CODE_ERROR; + } + $skeletonName = $skeletonDatabase['database']; + + $dumpFolder = $args->getOption('dump-folder') ?? CONFIG . DS . 'sql'; + if (!is_dir($dumpFolder)) { + mkdir( + directory: $dumpFolder, + permissions: 0755, + recursive: true + ); + } + $dumpFile = $dumpFolder . DS . 'test_db.sql'; + + $io->out(__d('cake_d_c/db_test', "Exporting data from skeleton database: $skeletonName \n")); + $engine = EngineFactory::engine($skeletonDatabase); + $engine->export($dumpFile, ['format' => 'plain']); + } +} diff --git a/src/Plugin.php b/src/DbTestPlugin.php similarity index 92% rename from src/Plugin.php rename to src/DbTestPlugin.php index a78375d..33beddf 100644 --- a/src/Plugin.php +++ b/src/DbTestPlugin.php @@ -17,6 +17,6 @@ /** * Plugin loader */ -class Plugin extends BasePlugin +class DbTestPlugin extends BasePlugin { } diff --git a/src/Engine/BaseEngine.php b/src/Engine/BaseEngine.php index 16a80dc..0b0eee1 100644 --- a/src/Engine/BaseEngine.php +++ b/src/Engine/BaseEngine.php @@ -14,7 +14,7 @@ use CakeDC\DbTest\Engine\Traits\ExecuteTrait; -abstract class BaseEngine +abstract class BaseEngine implements EngineInterface { use ExecuteTrait; @@ -23,60 +23,34 @@ abstract class BaseEngine * * @var bool */ - protected $_verbose = false; + protected bool $_verbose = false; /** * Database configuration * - * @var bool + * @var array */ protected array $_database = []; /** * Constructor method * - * @param $database + * @param array $database * @param bool $verbose Show commands and results on execution - * @return void */ - public function __construct($database, $verbose = false) + public function __construct(array $database, bool $verbose = false) { $this->_database = $database; $this->_verbose = $verbose; } - /** - * Recreates test database. - * - * @return bool - */ - abstract public function recreateTestDatabase(); - - /** - * Import test skeleton database. - * - * @param string $file Sql file path. - * @param array $options Additional options. - * @return bool - */ - abstract public function import($file, $options = []); - - /** - * Export database. - * - * @param string $file Sql file path. - * @param array $options Additional options. - * @return bool - */ - abstract public function export($file, $options = []); - /** * Check if success. * * @param int $check Check value * @return bool */ - public function isSuccess($check) + public function isSuccess(int $check): bool { $allowed = [ 0 => true, @@ -91,7 +65,7 @@ public function isSuccess($check) * * @return bool */ - public function createSchema() + public function createSchema(): bool { return true; } diff --git a/src/Engine/EngineFactory.php b/src/Engine/EngineFactory.php index 9220a4f..a6e64aa 100644 --- a/src/Engine/EngineFactory.php +++ b/src/Engine/EngineFactory.php @@ -13,6 +13,7 @@ namespace CakeDC\DbTest\Engine; use Cake\Http\Exception\NotFoundException; +use function Cake\I18n\__d; class EngineFactory { @@ -21,9 +22,9 @@ class EngineFactory * * @param array $database Database configuration. * @param bool $verbose Show commands and results on execution - * @return \CakeDC\DbTest\Engine\BaseEngine + * @return \CakeDC\DbTest\Engine\EngineInterface */ - public static function engine($database, $verbose = false) + public static function engine(array $database, bool $verbose = false): EngineInterface { if (empty($database['driver'])) { throw new NotFoundException(__d('cake_d_c/db_test', 'Driver is not defined')); @@ -36,23 +37,28 @@ public static function engine($database, $verbose = false) /** * Translate a cake engine into a DbTest engine * - * @param $driver + * @param string $driver + * @return string */ - protected static function getEngineClass($driver) + protected static function getEngineClass(string $driver): string { $engineMap = [ - 'Mysql' => '\\CakeDC\\DbTest\\Engine\\MysqlEngine', - 'Postgres' => '\\CakeDC\\DbTest\\Engine\\PostgresEngine', + 'Mysql' => MysqlEngine::class, + 'Postgres' => PostgresEngine::class, ]; $type = str_replace('Cake\\Database\\Driver\\', '', $driver); if (!in_array($type, array_keys($engineMap))) { - throw new NotFoundException(__d('cake_d_c/db_test', 'Database engine {0} is not supported', $type)); + throw new NotFoundException( + __d('cake_d_c/db_test', 'Database engine {0} is not supported', $type) + ); } $engineClass = $engineMap[$type]; if (!class_exists($engineClass)) { - throw new NotFoundException(__d('cake_d_c/db_test', 'Can\'t load engine ' . $engineClass)); + throw new NotFoundException( + __d('cake_d_c/db_test', 'Can\'t load engine ' . $engineClass) + ); } return $engineClass; diff --git a/src/Engine/EngineInterface.php b/src/Engine/EngineInterface.php index 30e384a..c6283e8 100644 --- a/src/Engine/EngineInterface.php +++ b/src/Engine/EngineInterface.php @@ -19,7 +19,7 @@ interface EngineInterface * * @return bool */ - public function recreateTestDatabase(); + public function recreateTestDatabase(): bool; /** * Import test skeleton database. @@ -28,7 +28,7 @@ public function recreateTestDatabase(); * @param array $options Additional options. * @return bool */ - public function import($file, $options = []); + public function import(string $file, array $options = []): bool; /** * Export database. @@ -37,5 +37,5 @@ public function import($file, $options = []); * @param array $options Additional options. * @return bool */ - public function export($file, $options = []); + public function export(string $file, array $options = []): bool; } diff --git a/src/Engine/MysqlEngine.php b/src/Engine/MysqlEngine.php index 39940f6..d95f0c1 100644 --- a/src/Engine/MysqlEngine.php +++ b/src/Engine/MysqlEngine.php @@ -14,15 +14,14 @@ use Cake\Core\Configure; use Cake\Log\Log; +use function Cake\I18n\__d; class MysqlEngine extends BaseEngine { /** - * Recreates test database. - * - * @return bool + * @inheritdoc */ - public function recreateTestDatabase() + public function recreateTestDatabase(): bool { $databaseName = $this->_database['database']; $baseArgs = $this->_getBaseArguments(); @@ -39,13 +38,9 @@ public function recreateTestDatabase() } /** - * Import test skeleton database. - * - * @param string $file Sql file path. - * @param array $options Additional options/ - * @return bool + * @inheritdoc */ - public function import($file, $options = []) + public function import(string $file, array $options = []): bool { $databaseName = $this->_database['database']; $baseArgs = $this->_getBaseArguments(); @@ -55,13 +50,9 @@ public function import($file, $options = []) } /** - * Export database. - * - * @param string $file Sql file path. - * @param array $options Additional options/ - * @return bool + * @inheritdoc */ - public function export($file, $options = []) + public function export(string $file, array $options = []): bool { $databaseName = $this->_database['database']; $baseArgs = $this->_getBaseArguments(); @@ -85,7 +76,7 @@ public function export($file, $options = []) * * @return string */ - protected function _getBaseArguments() + protected function _getBaseArguments(): string { $user = $this->_database['username']; $password = $this->_database['password']; diff --git a/src/Engine/PostgresEngine.php b/src/Engine/PostgresEngine.php index a83e5c1..181ff97 100644 --- a/src/Engine/PostgresEngine.php +++ b/src/Engine/PostgresEngine.php @@ -13,15 +13,14 @@ namespace CakeDC\DbTest\Engine; use Cake\Log\Log; +use function Cake\I18n\__d; class PostgresEngine extends BaseEngine { /** - * Recreates test database. - * - * @return bool + * @inheritdoc */ - public function recreateTestDatabase() + public function recreateTestDatabase(): bool { $baseArgs = $this->_getBaseArguments(); $this->_setPassword(); @@ -48,11 +47,11 @@ public function recreateTestDatabase() * * @return bool */ - public function createSchema() + public function createSchema(): bool { $baseArgs = $this->_getBaseArguments(); $this->_setPassword(); - $success = false; + $success = 0; $testDbName = $this->_database['database']; if (!empty($this->_database['schema'])) { $schema = $this->_database['schema']; @@ -66,13 +65,9 @@ public function createSchema() } /** - * Import test skeleton database. - * - * @param string $file Sql file path. - * @param array $options Additional options/ - * @return bool + * @inheritdoc */ - public function import($file, $options = []) + public function import(string $file, array $options = []): bool { $baseArgs = $this->_getBaseArguments(); $testDbName = $this->_database['database']; @@ -88,13 +83,9 @@ public function import($file, $options = []) } /** - * Export database. - * - * @param string $file Sql file path. - * @param array $options Additional options/ - * @return bool + * @inheritdoc */ - public function export($file, $options = []) + public function export(string $file, array $options = []): bool { $baseArgs = $this->_getBaseArguments(); $this->_setPassword(); @@ -114,7 +105,7 @@ public function export($file, $options = []) * * @return string */ - protected function _getBaseArguments() + protected function _getBaseArguments(): string { $user = $this->_database['username']; $host = $this->_database['host']; @@ -131,7 +122,7 @@ protected function _getBaseArguments() * * @return void */ - protected function _setPassword() + protected function _setPassword(): void { $password = $this->_database['password']; putenv("PGPASSWORD=$password"); diff --git a/src/Engine/Traits/ExecuteTrait.php b/src/Engine/Traits/ExecuteTrait.php index d2c1e56..a57181c 100644 --- a/src/Engine/Traits/ExecuteTrait.php +++ b/src/Engine/Traits/ExecuteTrait.php @@ -13,6 +13,7 @@ namespace CakeDC\DbTest\Engine\Traits; use Cake\Log\Log; +use function Cake\I18n\__d; /** * For executing commands @@ -22,13 +23,16 @@ trait ExecuteTrait /** * Execute an external program * - * @param string $command The command that will be executed. - * @param array $output Command output - * @param int $return_var Return status of the executed command - * @return string The last line from the result of the command + * @param string $command The command that will be executed. + * @param array|null $output Command output + * @param int|null $return_var Return status of the executed command + * @return bool The last line from the result of the command */ - protected function _execute($command, &$output = null, &$return_var = null) - { + protected function _execute( + string $command, + ?array &$output = null, + ?int &$return_var = null + ): bool { if ($this->_verbose) { Log::info(__d('cake_d_c/db_test', $command . "\n")); } @@ -37,6 +41,6 @@ protected function _execute($command, &$output = null, &$return_var = null) Log::info(__d('cake_d_c/db_test', implode("\n", $output) . "\n")); } - return $result; + return (bool)$result; } } diff --git a/src/Shell/DbTestShell.php b/src/Shell/DbTestShell.php deleted file mode 100644 index 3da2870..0000000 --- a/src/Shell/DbTestShell.php +++ /dev/null @@ -1,82 +0,0 @@ -setDescription([ - __d('cake_d_c/db_test', 'The Db Test Shell extends the CakePhp TestSuite and no longer needs fixtures defined. - Instead the test and test-template databases are synchronized before each test class is executed. - Transaction wrapping used to rollback test case changes.'), - ])->addOption('import-database-template', [ - 'boolean' => true, - 'short' => 'i', - 'help' => __d('cake_d_c/db_test', 'Drops test template database and imports test_db.sql file from app/Config/sql'), - ])->addOption('import-database-file', [ - 'help' => __d('cake_d_c/db_test', 'Provides path to test_db.sql file'), - ]); - - return $parser; - } - - /** - * Main entry point for the shell - * - * @return mixed - */ - public function main() - { - Configure::load('app', 'default', false); - - $this->out(__d('cake_d_c/db_test', 'Db Test Shell')); - $this->hr(); - - if ($this->params['import-database-template']) { - $this->__importTestSkeleton(); - unset($this->params['import-database-template']); - } else { - $this->out($this->getOptionParser()->help()); - } - } - - /** - * Import test skeleton with given database file or default - * - * @return void - */ - private function __importTestSkeleton() - { - $path = null; - if (!empty($this->params['import-database-file']) && file_exists($this->params['import-database-file'])) { - $path = $this->params['import-database-file']; - unset($this->params['import-database-file']); - } - $skeletonDatabase = ConnectionManager::get('test_template')->config(); - $manager = new FixtureManager(); - $manager->setupDatabase($skeletonDatabase, true, true, $path); - } -} diff --git a/src/Shell/FixtureImportShell.php b/src/Shell/FixtureImportShell.php deleted file mode 100644 index e36b592..0000000 --- a/src/Shell/FixtureImportShell.php +++ /dev/null @@ -1,96 +0,0 @@ -out($this->getOptionParser()->help()); - } - - /** - * Get & configure the option parser - * - * @return \Cake\Console\ConsoleOptionParser - */ - public function getOptionParser(): ConsoleOptionParser - { - $parser = parent::getOptionParser(); - - return $parser->setDescription(__d('cake_d_c/db_test', 'DbTest fixture importer:')) - ->addOption('dump-folder', [ - 'help' => __d('cake_d_c/db_test', 'Provides path to dump test_db.sql file.'), - ])->addSubcommand('dump', ['help' => __d('cake_d_c/db_test', 'Dumps the template database')]); - } - - /** - * Creates fresh dump of templates schema - * - * @return void - */ - public function dump() - { - $skeletonDatabase = ConnectionManager::get('test_template')->config(); - - if (!empty($skeletonDatabase)) { - $skeletonName = $skeletonDatabase['database']; - - $dumpFolder = Hash::get($this->params, 'dump-folder', CONFIG . DS . 'sql'); - $this->_ensureFolder($dumpFolder); - $dumpFile = $dumpFolder . DS . 'test_db.sql'; - - $this->out(__d('cake_d_c/db_test', "Exporting data from skeleton database: $skeletonName \n")); - $engine = EngineFactory::engine($skeletonDatabase); - $engine->export($dumpFile, ['format' => 'plain']); - } - } - - /** - * Initializes this class with a DataSource object to use as default for all fixtures - * - * @return void - */ - protected function _initDb() - { - if ($this->_initialized) { - return; - } - $db = ConnectionManager::get('test_template'); - $db->cacheSources = false; - $this->_db = $db; - } - - /** - * Find and import test_skel. sql file from app/Config/sql - * - * @param string $path path - * @return void - */ - protected function _ensureFolder($path) - { - $Folder = new Folder($path, true); - } -} diff --git a/src/TestSuite/Fixture/FixtureInjector.php b/src/TestSuite/Fixture/FixtureInjector.php index 8baafab..37a2263 100644 --- a/src/TestSuite/Fixture/FixtureInjector.php +++ b/src/TestSuite/Fixture/FixtureInjector.php @@ -12,6 +12,7 @@ */ namespace CakeDC\DbTest\TestSuite\Fixture; +use Cake\Datasource\ConnectionInterface; use Cake\Datasource\ConnectionManager; use Exception; use PHPUnit\Framework\AssertionFailedError; @@ -189,16 +190,16 @@ public function endTestSuite(TestSuite $suite): void * Disconnects from test database (if necessary), sets up, and reconnects. * Disable datasource caching and sets the datasource for the test run. * - * @param string $ds Directory Separator + * @param \Cake\Datasource\ConnectionInterface $ds Directory Separator * @param array $database Database configuration * @return void */ - private function __loadDatabase($ds, $database) + private function __loadDatabase(ConnectionInterface $ds, $database) { - if ($ds->isConnected()) { + + if ($ds->getDriver()->isConnected()) { // attempt to disconnect and close connection to db. - $ds->disconnect(); - $ds->close(); + $ds->getDriver()->disconnect(); } if ($this->_fixtureManager->setupDatabase($database, false)) { @@ -206,10 +207,10 @@ private function __loadDatabase($ds, $database) $this->databaseLoaded = true; } - if (!$ds->isConnected()) { + if (!$ds->getDriver()->isConnected()) { // reconnect - $ds->disconnect(); - $ds->connect(); + $ds->getDriver()->disconnect(); + $ds->getDriver()->connect(); } $ds->cacheSources = false; diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index 455a22e..95e3e42 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/src/TestSuite/Fixture/FixtureManager.php @@ -15,7 +15,6 @@ use Cake\Datasource\ConnectionManager; use Cake\Log\Log; use CakeDC\DbTest\Engine\EngineFactory; -use Shim\Filesystem\Folder; class FixtureManager { @@ -24,20 +23,24 @@ class FixtureManager * * @var bool */ - protected $_verbose = false; + protected bool $_verbose = false; /** * Drops existing connections to test database, recreates db, * and transfers data from test_skel to test * - * @param array $database Database configuration - * @param bool $createSchema true when schema will be created - * @param bool $importTestSkeleton true when skeleton will be imported - * @param string $sqlFilePath Path to the sql script to import + * @param array $database Database configuration + * @param bool $createSchema true when schema will be created + * @param bool $importTestSkeleton true when skeleton will be imported + * @param string|null $sqlFilePath Path to the sql script to import * @return bool */ - public function setupDatabase($database, $createSchema, $importTestSkeleton = false, $sqlFilePath = null) - { + public function setupDatabase( + array $database, + bool $createSchema, + bool $importTestSkeleton = false, + ?string $sqlFilePath = null + ): bool { $engine = EngineFactory::engine($database, $this->_verbose); $success = $engine->recreateTestDatabase(); @@ -58,10 +61,10 @@ public function setupDatabase($database, $createSchema, $importTestSkeleton = fa * * mysqlamdin must be in your path and be the proper version for your database * - * @param string $database Database configuration + * @param array $database Database configuration * @return void */ - public function transferData($database) + public function transferData(array $database): void { $testDbName = $database['database']; $skeletonDatabase = ConnectionManager::get('test_template')->config(); @@ -87,11 +90,11 @@ public function transferData($database) /** * Find and import test_db.sql file from app/Config/sql * - * @param string $database Database configuration. - * @param string $sqlFilePath Path to the sql script to import + * @param array $database Database configuration. + * @param string|null $sqlFilePath Path to the sql script to import * @return void */ - private function __importTestSkeleton($database, $sqlFilePath = null) + private function __importTestSkeleton(array $database, ?string $sqlFilePath = null): void { $testDbName = $database['database']; $cacheFolder = CACHE . 'fixtures'; @@ -121,7 +124,7 @@ private function __importTestSkeleton($database, $sqlFilePath = null) * @param bool $verbose * @return void */ - public function setVerbose($verbose) + public function setVerbose(bool $verbose): void { $this->_verbose = $verbose; } @@ -132,8 +135,14 @@ public function setVerbose($verbose) * @param string $path Path to folder * @return void */ - protected function _ensureFolder($path) + protected function _ensureFolder(string $path): void { - $Folder = new Folder($path, true); + if (!is_dir($path)) { + mkdir( + directory: $path, + permissions: 0755, + recursive: true + ); + } } } From 5351d5510e5f09a4c51246929ce898147f758e94 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 12:13:10 +0100 Subject: [PATCH 3/9] migrated phpunit listener to phpunit event system --- phpunit.xml.dbtest | 52 ++-- ...PUnitAfterTestMethodFinishedSubscriber.php | 28 ++ ...HPUnitBeforeTestMethodCalledSubscriber.php | 28 ++ .../Fixture/Extension/PHPUnitExtension.php | 38 +++ .../Extension/PHPUnitStartedSubscriber.php | 141 ++++++++++ src/TestSuite/Fixture/FixtureInjector.php | 265 ------------------ 6 files changed, 259 insertions(+), 293 deletions(-) create mode 100644 src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php create mode 100644 src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php create mode 100644 src/TestSuite/Fixture/Extension/PHPUnitExtension.php create mode 100644 src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php delete mode 100644 src/TestSuite/Fixture/FixtureInjector.php diff --git a/phpunit.xml.dbtest b/phpunit.xml.dbtest index ea78e9e..10b4abd 100644 --- a/phpunit.xml.dbtest +++ b/phpunit.xml.dbtest @@ -1,10 +1,11 @@ - + @@ -18,27 +19,22 @@ - - - - - - - - - + + + + + + + - - - - ./src/ - ./plugins/*/src/ - - ./src/Console/Installer.php - ./src/Shell/ConsoleShell.php - - - + + + + src/ + plugins/*/src/ + + + src/Console/Installer.php + + diff --git a/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php new file mode 100644 index 0000000..186d945 --- /dev/null +++ b/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php @@ -0,0 +1,28 @@ +rollback(); + } +} diff --git a/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php new file mode 100644 index 0000000..3eae6ca --- /dev/null +++ b/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php @@ -0,0 +1,28 @@ +begin(); + } +} diff --git a/src/TestSuite/Fixture/Extension/PHPUnitExtension.php b/src/TestSuite/Fixture/Extension/PHPUnitExtension.php new file mode 100644 index 0000000..d065b76 --- /dev/null +++ b/src/TestSuite/Fixture/Extension/PHPUnitExtension.php @@ -0,0 +1,38 @@ +get('verbose'); + $fixtureManager->setVerbose($verbose); + + $facade->registerSubscribers( + new PHPUnitStartedSubscriber($fixtureManager), + new PHPUnitBeforeTestMethodCalledSubscriber(), + new PHPUnitAfterTestMethodFinishedSubscriber() + ); + } +} diff --git a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php new file mode 100644 index 0000000..edb0585 --- /dev/null +++ b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php @@ -0,0 +1,141 @@ +config(); + + try { + $ds = ConnectionManager::get('test'); + } catch (Exception) { + // create test database and schema + $this->fixtureManager->setupDatabase($database, true, false); + $ds = ConnectionManager::get('test'); + } + + // rollback transaction. gives us a 'fresh' copy of the database for the next + // test suite to run + $ds->rollback(); + + if (!$this->databaseLoaded) { + $this->loadDatabase($ds, $database); + } + // begin transaction. will hold all changes while the test suite runs. + } + + /** + * Disconnects from test database (if necessary), sets up, and reconnects. + * Disable datasource caching and sets the datasource for the test run. + * + * @param \Cake\Datasource\ConnectionInterface $ds Directory Separator + * @param array $database Database configuration + * @return void + */ + protected function loadDatabase(ConnectionInterface $ds, array $database): void + { + if ($ds->getDriver()->isConnected()) { + // attempt to disconnect and close connection to db. + $ds->getDriver()->disconnect(); + } + + if ($this->fixtureManager->setupDatabase($database, false)) { + $this->fixtureManager->transferData($database); + $this->databaseLoaded = true; + } + + if (!$ds->getDriver()->isConnected()) { + // reconnect + $ds->getDriver()->disconnect(); + $ds->getDriver()->connect(); + } + + $this->initDb(); + } + + /** + * Add aliases for all non test prefixed connections. + * + * This allows models to use the test connections without + * a pile of configuration work. + * + * @return void + */ + protected function aliasConnections(): void + { + $connections = ConnectionManager::configured(); + ConnectionManager::alias('test', 'default'); + $map = []; + foreach ($connections as $connection) { + if ($connection === 'test' || $connection === 'default') { + continue; + } + if (isset($map[$connection])) { + continue; + } + if (str_starts_with($connection, 'test_')) { + $map[$connection] = substr($connection, 5); + } else { + $map['test_' . $connection] = $connection; + } + } + foreach ($map as $alias => $connection) { + ConnectionManager::alias($alias, $connection); + } + } + + /** + * Initializes this class with a DataSource object to use as default for all fixtures + * + * @return void + */ + protected function initDb(): void + { + if ($this->initialized) { + + return; + } + $this->aliasConnections(); + $this->initialized = true; + } +} diff --git a/src/TestSuite/Fixture/FixtureInjector.php b/src/TestSuite/Fixture/FixtureInjector.php deleted file mode 100644 index 37a2263..0000000 --- a/src/TestSuite/Fixture/FixtureInjector.php +++ /dev/null @@ -1,265 +0,0 @@ -_fixtureManager = $manager; - $this->_fixtureManager->setVerbose($verbose); - } - - private $databaseLoaded = false; - - /** - * Called when an error is encountered during a test - * - * @param \PHPUnit\Framework\Test $test Failed Test - * @param \Exception $t Exception encountered - * @param float $time Time of occurrence - * @return void - */ - public function addError(Test $test, Throwable $t, float $time): void - { - } - - /** - * A warning occurred. - * - * @param \PHPUnit\Framework\Test $test - * @param \PHPUnit\Framework\Warning $e - * @param float $time - */ - public function addWarning(Test $test, Warning $e, float $time): void - { - } - - /** - * Called when a failure is encountered during a test - * - * @param \PHPUnit\Framework\Test $test Failed Test - * @param \PHPUnit\Framework\AssertionFailedError $e Failed Assertion - * @param float $time Time of occurrence - * @return void - */ - public function addFailure(Test $test, AssertionFailedError $e, float $time): void - { - } - - /** - * Called if a test is incomplete - * - * @param \PHPUnit\Framework\Test $test Incomplete Test - * @param \Throwable $t Exception encountered - * @param float $time Time of occurrence - * @return void - */ - public function addIncompleteTest(Test $test, \Throwable $t, float $time): void - { - } - - /** - * Called when a test is risky. - * - * @param \PHPUnit\Framework\Test $test Risky Test - * @param \Throwable $t Exception encountered - * @param float $time Time of occurrence - * @return void - */ - public function addRiskyTest(Test $test, \Throwable $t, float $time): void - { - } - - /** - * Called when a test is skipped. - * Tests are skipped when a test it was dependent on fails (using @depends) - * - * @param \PHPUnit\Framework\Test $test Skipped Test - * @param \Throwable $e Exception encountered - * @param float $time Time of occurrence - * @return void - */ - public function addSkippedTest(Test $test, Throwable $e, float $time): void - { - } - - /** - * Called at the beginning of a test (per test method in a class) - * - * @param \PHPUnit\Framework\Test $test Test - * @return void - */ - public function startTest(Test $test): void - { - ConnectionManager::get('test')->begin(); - } - - /** - * Called when a test ends (per test method in a class) - * - * @param \PHPUnit\Framework\Test $test Ended Test - * @param float $time Time of occurrence - * @return void - */ - public function endTest(Test $test, float $time): void - { - ConnectionManager::get('test')->rollback(); - } - - /** - * Called at the beginning of a suite. A suite is a collection of tests - * - * @param \PHPUnit\Framework\TestSuite $suite Suite - * @return void - */ - public function startTestSuite(TestSuite $suite): void - { - $database = ConnectionManager::get('test')->config(); - if (!empty($database) && get_class($suite) == 'PHPUnit\Framework\TestSuite') { - try { - $ds = ConnectionManager::get('test'); - } catch (Exception $e) { - // create test database and schema - $this->_fixtureManager->setupDatabase($database, true, false); - $ds = ConnectionManager::get('test'); - } - - // rollback transaction. gives us a 'fresh' copy of the database for the next test suite to run - $ds->rollback(); - - if (!$this->databaseLoaded) { - $this->__loadDatabase($ds, $database); - } - // begin transaction. will hold all changes while the test suite runs. - } - } - - /** - * Called at the end of a suite. - * - * @param \PHPUnit\Framework\TestSuite $suite Suite - * @return void - */ - public function endTestSuite(TestSuite $suite): void - { - } - - /** - * Disconnects from test database (if necessary), sets up, and reconnects. - * Disable datasource caching and sets the datasource for the test run. - * - * @param \Cake\Datasource\ConnectionInterface $ds Directory Separator - * @param array $database Database configuration - * @return void - */ - private function __loadDatabase(ConnectionInterface $ds, $database) - { - - if ($ds->getDriver()->isConnected()) { - // attempt to disconnect and close connection to db. - $ds->getDriver()->disconnect(); - } - - if ($this->_fixtureManager->setupDatabase($database, false)) { - $this->_fixtureManager->transferData($database); - $this->databaseLoaded = true; - } - - if (!$ds->getDriver()->isConnected()) { - // reconnect - $ds->getDriver()->disconnect(); - $ds->getDriver()->connect(); - } - - $ds->cacheSources = false; - - $this->_initDb(); - } - - /** - * Add aliases for all non test prefixed connections. - * - * This allows models to use the test connections without - * a pile of configuration work. - * - * @return void - */ - protected function _aliasConnections() - { - $connections = ConnectionManager::configured(); - ConnectionManager::alias('test', 'default'); - $map = []; - foreach ($connections as $connection) { - if ($connection === 'test' || $connection === 'default') { - continue; - } - if (isset($map[$connection])) { - continue; - } - if (strpos($connection, 'test_') === 0) { - $map[$connection] = substr($connection, 5); - } else { - $map['test_' . $connection] = $connection; - } - } - foreach ($map as $alias => $connection) { - ConnectionManager::alias($alias, $connection); - } - } - - /** - * Initializes this class with a DataSource object to use as default for all fixtures - * - * @return void - */ - protected function _initDb() - { - if ($this->_initialized) { - return; - } - $this->_aliasConnections(); - $this->_initialized = true; - } -} From d61db2cbf2a86df2e800d17ab98fb0d70a57dadd Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 12:27:55 +0100 Subject: [PATCH 4/9] fixed issues reported by phpcs --- src/Command/DbTestCommand.php | 10 ++++++---- src/Command/FixtureImportCommand.php | 4 ++-- src/Engine/BaseEngine.php | 2 +- src/Engine/EngineFactory.php | 2 +- src/Engine/MysqlEngine.php | 6 +++--- src/Engine/PostgresEngine.php | 9 +++++---- .../PHPUnitAfterTestMethodFinishedSubscriber.php | 4 ++++ .../PHPUnitBeforeTestMethodCalledSubscriber.php | 4 ++++ src/TestSuite/Fixture/Extension/PHPUnitExtension.php | 6 ++++++ .../Fixture/Extension/PHPUnitStartedSubscriber.php | 6 ++++-- src/TestSuite/Fixture/FixtureManager.php | 2 +- 11 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/Command/DbTestCommand.php b/src/Command/DbTestCommand.php index faf3aa8..33deaff 100644 --- a/src/Command/DbTestCommand.php +++ b/src/Command/DbTestCommand.php @@ -22,20 +22,22 @@ class DbTestCommand extends Command { /** - * @inheritdoc + * @inheritDoc */ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { return parent::buildOptionParser($parser) ->setDescription([ - __d('cake_d_c/db_test', 'The Db Test Shell extends the CakePhp TestSuite and no longer needs fixtures defined. + __d('cake_d_c/db_test', 'The Db Test Shell extends the CakePhp TestSuite and no ' . + 'longer needs fixtures defined. Instead the test and test-template databases are synchronized before each test class is executed. Transaction wrapping used to rollback test case changes.'), ]) ->addOption('import-database-template', [ 'boolean' => true, 'short' => 'i', - 'help' => __d('cake_d_c/db_test', 'Drops test template database and imports test_db.sql file from app/Config/sql'), + 'help' => __d('cake_d_c/db_test', 'Drops test template database and imports ' . + 'test_db.sql file from app/Config/sql'), ]) ->addOption('import-database-file', [ 'short' => 'f', @@ -44,7 +46,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar } /** - * @inheritdoc + * @inheritDoc */ public function execute(Arguments $args, ConsoleIo $io) { diff --git a/src/Command/FixtureImportCommand.php b/src/Command/FixtureImportCommand.php index 3a45c2b..b2be3aa 100644 --- a/src/Command/FixtureImportCommand.php +++ b/src/Command/FixtureImportCommand.php @@ -19,7 +19,7 @@ class FixtureImportCommand extends Command { /** - * @inheritdoc + * @inheritDoc */ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { @@ -37,7 +37,7 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar } /** - * @inheritdoc + * @inheritDoc */ public function execute(Arguments $args, ConsoleIo $io) { diff --git a/src/Engine/BaseEngine.php b/src/Engine/BaseEngine.php index 0b0eee1..b0285a2 100644 --- a/src/Engine/BaseEngine.php +++ b/src/Engine/BaseEngine.php @@ -35,7 +35,7 @@ abstract class BaseEngine implements EngineInterface /** * Constructor method * - * @param array $database + * @param array $database database configuration * @param bool $verbose Show commands and results on execution */ public function __construct(array $database, bool $verbose = false) diff --git a/src/Engine/EngineFactory.php b/src/Engine/EngineFactory.php index a6e64aa..e78f5e6 100644 --- a/src/Engine/EngineFactory.php +++ b/src/Engine/EngineFactory.php @@ -37,7 +37,7 @@ public static function engine(array $database, bool $verbose = false): EngineInt /** * Translate a cake engine into a DbTest engine * - * @param string $driver + * @param string $driver Driver name * @return string */ protected static function getEngineClass(string $driver): string diff --git a/src/Engine/MysqlEngine.php b/src/Engine/MysqlEngine.php index d95f0c1..f0c9a9d 100644 --- a/src/Engine/MysqlEngine.php +++ b/src/Engine/MysqlEngine.php @@ -19,7 +19,7 @@ class MysqlEngine extends BaseEngine { /** - * @inheritdoc + * @inheritDoc */ public function recreateTestDatabase(): bool { @@ -38,7 +38,7 @@ public function recreateTestDatabase(): bool } /** - * @inheritdoc + * @inheritDoc */ public function import(string $file, array $options = []): bool { @@ -50,7 +50,7 @@ public function import(string $file, array $options = []): bool } /** - * @inheritdoc + * @inheritDoc */ public function export(string $file, array $options = []): bool { diff --git a/src/Engine/PostgresEngine.php b/src/Engine/PostgresEngine.php index 181ff97..bcf38d6 100644 --- a/src/Engine/PostgresEngine.php +++ b/src/Engine/PostgresEngine.php @@ -18,7 +18,7 @@ class PostgresEngine extends BaseEngine { /** - * @inheritdoc + * @inheritDoc */ public function recreateTestDatabase(): bool { @@ -26,7 +26,8 @@ public function recreateTestDatabase(): bool $this->_setPassword(); $databaseName = $this->_database['database']; $systemUser = 'postgres'; - $terminateQuery = "select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where pg_stat_activity.datname = '$databaseName'"; + $terminateQuery = 'select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity ' . + "where pg_stat_activity.datname = '$databaseName'"; $this->_execute("psql $baseArgs -c \"$terminateQuery\" $systemUser", $output, $success); $output = []; @@ -65,7 +66,7 @@ public function createSchema(): bool } /** - * @inheritdoc + * @inheritDoc */ public function import(string $file, array $options = []): bool { @@ -83,7 +84,7 @@ public function import(string $file, array $options = []): bool } /** - * @inheritdoc + * @inheritDoc */ public function export(string $file, array $options = []): bool { diff --git a/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php index 186d945..572c831 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php @@ -21,6 +21,10 @@ */ class PHPUnitAfterTestMethodFinishedSubscriber implements AfterTestMethodFinishedSubscriber { + /** + * @param \PHPUnit\Event\Test\AfterTestMethodFinished $event Event + * @return void + */ public function notify(AfterTestMethodFinished $event): void { ConnectionManager::get('test')->rollback(); diff --git a/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php index 3eae6ca..be7de0c 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php @@ -21,6 +21,10 @@ */ class PHPUnitBeforeTestMethodCalledSubscriber implements BeforeTestMethodCalledSubscriber { + /** + * @param \PHPUnit\Event\Test\BeforeTestMethodCalled $event Event + * @return void + */ public function notify(BeforeTestMethodCalled $event): void { ConnectionManager::get('test')->begin(); diff --git a/src/TestSuite/Fixture/Extension/PHPUnitExtension.php b/src/TestSuite/Fixture/Extension/PHPUnitExtension.php index d065b76..978bd0d 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitExtension.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitExtension.php @@ -23,6 +23,12 @@ */ class PHPUnitExtension implements Extension { + /** + * @param \PHPUnit\TextUI\Configuration\Configuration $configuration Configuration + * @param \PHPUnit\Runner\Extension\Facade $facade Facade + * @param \PHPUnit\Runner\Extension\ParameterCollection $parameters Parameters + * @return void + */ public function bootstrap(Configuration $configuration, Facade $facade, ParameterCollection $parameters): void { $fixtureManager = new FixtureManager(); diff --git a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php index edb0585..f8cd818 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php @@ -33,13 +33,16 @@ class PHPUnitStartedSubscriber implements StartedSubscriber */ protected bool $initialized; + /** + * @param \CakeDC\DbTest\TestSuite\Fixture\FixtureManager $fixtureManager Fixture Manager instance + */ public function __construct( private readonly FixtureManager $fixtureManager ) { } /** - * @param \PHPUnit\Event\TestSuite\Started $event + * @param \PHPUnit\Event\TestSuite\Started $event Event * @return void */ public function notify(Started $event): void @@ -132,7 +135,6 @@ protected function aliasConnections(): void protected function initDb(): void { if ($this->initialized) { - return; } $this->aliasConnections(); diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index 95e3e42..796cbde 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/src/TestSuite/Fixture/FixtureManager.php @@ -121,7 +121,7 @@ private function __importTestSkeleton(array $database, ?string $sqlFilePath = nu /** * Set verbose mode. * - * @param bool $verbose + * @param bool $verbose Verbose * @return void */ public function setVerbose(bool $verbose): void From 97a7bb3dc23bf09bf528e4adf1fb17e241452b1f Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 12:46:34 +0100 Subject: [PATCH 5/9] fixed issues reported by psalm --- composer.json | 3 +- phpstan.neon | 2 + psalm.xml | 1 + src/Engine/BaseEngine.php | 6 +- src/Engine/EngineInterface.php | 7 + src/Engine/PostgresEngine.php | 4 +- ...PUnitAfterTestMethodFinishedSubscriber.php | 5 +- ...HPUnitBeforeTestMethodCalledSubscriber.php | 5 +- .../Extension/PHPUnitStartedSubscriber.php | 7 +- src/TestSuite/Fixture/FixtureManager.php | 1 + tests/bootstrap.php | 123 ++++++++++++++++++ 11 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 tests/bootstrap.php diff --git a/composer.json b/composer.json index 4820dc5..d7bfd5c 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ }, "require-dev": { "phpunit/phpunit": "^10.0", - "cakephp/cakephp-codesniffer": "^4.0" + "cakephp/cakephp-codesniffer": "^4.0", + "ext-mbstring": "*" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 712bed1..bedc53a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,5 +2,7 @@ parameters: level: 8 treatPhpDocTypesAsCertain: false checkGenericClassInNonGenericObjectType: false + bootstrapFiles: + - tests/bootstrap.php paths: - src/ diff --git a/psalm.xml b/psalm.xml index 69a2070..99db5dd 100644 --- a/psalm.xml +++ b/psalm.xml @@ -9,6 +9,7 @@ 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" + autoloader="tests/bootstrap.php" > diff --git a/src/Engine/BaseEngine.php b/src/Engine/BaseEngine.php index b0285a2..404456a 100644 --- a/src/Engine/BaseEngine.php +++ b/src/Engine/BaseEngine.php @@ -57,13 +57,11 @@ public function isSuccess(int $check): bool 1 => true, ]; - return isset($allowed[$check]) && $allowed[$check]; + return isset($allowed[$check]); } /** - * Create schema - * - * @return bool + * @inheritDoc */ public function createSchema(): bool { diff --git a/src/Engine/EngineInterface.php b/src/Engine/EngineInterface.php index c6283e8..80d8584 100644 --- a/src/Engine/EngineInterface.php +++ b/src/Engine/EngineInterface.php @@ -38,4 +38,11 @@ public function import(string $file, array $options = []): bool; * @return bool */ public function export(string $file, array $options = []): bool; + + /** + * Create database schema + * + * @return bool + */ + public function createSchema(): bool; } diff --git a/src/Engine/PostgresEngine.php b/src/Engine/PostgresEngine.php index bcf38d6..08383d5 100644 --- a/src/Engine/PostgresEngine.php +++ b/src/Engine/PostgresEngine.php @@ -44,9 +44,7 @@ public function recreateTestDatabase(): bool } /** - * Create schema - * - * @return bool + * @inheritDoc */ public function createSchema(): bool { diff --git a/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php index 572c831..ac8e2d2 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitAfterTestMethodFinishedSubscriber.php @@ -12,6 +12,7 @@ */ namespace CakeDC\DbTest\TestSuite\Fixture\Extension; +use Cake\Database\Connection; use Cake\Datasource\ConnectionManager; use PHPUnit\Event\Test\AfterTestMethodFinished; use PHPUnit\Event\Test\AfterTestMethodFinishedSubscriber; @@ -27,6 +28,8 @@ class PHPUnitAfterTestMethodFinishedSubscriber implements AfterTestMethodFinishe */ public function notify(AfterTestMethodFinished $event): void { - ConnectionManager::get('test')->rollback(); + $connection = ConnectionManager::get('test'); + assert($connection instanceof Connection); + $connection->rollback(); } } diff --git a/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php index be7de0c..9761215 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitBeforeTestMethodCalledSubscriber.php @@ -12,6 +12,7 @@ */ namespace CakeDC\DbTest\TestSuite\Fixture\Extension; +use Cake\Database\Connection; use Cake\Datasource\ConnectionManager; use PHPUnit\Event\Test\BeforeTestMethodCalled; use PHPUnit\Event\Test\BeforeTestMethodCalledSubscriber; @@ -27,6 +28,8 @@ class PHPUnitBeforeTestMethodCalledSubscriber implements BeforeTestMethodCalledS */ public function notify(BeforeTestMethodCalled $event): void { - ConnectionManager::get('test')->begin(); + $connection = ConnectionManager::get('test'); + assert($connection instanceof Connection); + $connection->begin(); } } diff --git a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php index f8cd818..c658623 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php @@ -12,6 +12,7 @@ */ namespace CakeDC\DbTest\TestSuite\Fixture\Extension; +use Cake\Database\Connection; use Cake\Datasource\ConnectionInterface; use Cake\Datasource\ConnectionManager; use CakeDC\DbTest\TestSuite\Fixture\FixtureManager; @@ -47,7 +48,9 @@ public function __construct( */ public function notify(Started $event): void { - $database = ConnectionManager::get('test')->config(); + $connection = ConnectionManager::get('test'); + assert($connection instanceof Connection); + $database = $connection->config(); try { $ds = ConnectionManager::get('test'); @@ -56,7 +59,7 @@ public function notify(Started $event): void $this->fixtureManager->setupDatabase($database, true, false); $ds = ConnectionManager::get('test'); } - + assert($ds instanceof Connection); // rollback transaction. gives us a 'fresh' copy of the database for the next // test suite to run $ds->rollback(); diff --git a/src/TestSuite/Fixture/FixtureManager.php b/src/TestSuite/Fixture/FixtureManager.php index 796cbde..b0d2fb2 100644 --- a/src/TestSuite/Fixture/FixtureManager.php +++ b/src/TestSuite/Fixture/FixtureManager.php @@ -15,6 +15,7 @@ use Cake\Datasource\ConnectionManager; use Cake\Log\Log; use CakeDC\DbTest\Engine\EngineFactory; +use function Cake\I18n\__d; class FixtureManager { diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..acb189c --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,123 @@ + 'DebugKit\TestApp', + 'encoding' => 'UTF-8', + 'base' => false, + 'baseUrl' => false, + 'dir' => 'src', + 'webroot' => 'webroot', + 'www_root' => APP . 'webroot', + 'fullBaseUrl' => 'http://localhost', + 'imageBaseUrl' => 'img/', + 'jsBaseUrl' => 'js/', + 'cssBaseUrl' => 'css/', + 'paths' => [ + 'plugins' => [APP . 'Plugin' . DS], + 'templates' => [APP . 'templates' . DS], + ], +]); +Configure::write('Session', [ + 'defaults' => 'php', +]); + +Cache::setConfig([ + '_cake_core_' => [ + 'engine' => 'File', + 'prefix' => 'cake_core_', + 'serialize' => true, + ], + '_cake_model_' => [ + 'engine' => 'File', + 'prefix' => 'cake_model_', + 'serialize' => true, + ], + 'default' => [ + 'engine' => 'File', + 'prefix' => 'default_', + 'serialize' => true, + ], +]); + +// Ensure default test connection is defined +if (!getenv('DB_URL')) { + putenv('DB_URL=sqlite://127.0.0.1/' . TMP . 'debug_kit_test.sqlite'); +} + +$config = [ + 'url' => getenv('DB_URL'), + 'timezone' => 'UTC', +]; + +// Use the test connection for 'debug_kit' as well. +ConnectionManager::setConfig('test', $config); +ConnectionManager::setConfig('test_debug_kit', $config); + +Log::setConfig([ + 'debug' => [ + 'engine' => 'Cake\Log\Engine\FileLog', + 'path' => LOGS, + 'levels' => ['notice', 'info', 'debug'], + 'file' => 'debug', + ], + 'error' => [ + 'engine' => 'Cake\Log\Engine\FileLog', + 'path' => LOGS, + 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], + 'file' => 'error', + ], +]); + +Plugin::getCollection()->add(new DbTestPlugin()); + +// Create test database schema +if (env('FIXTURE_SCHEMA_METADATA')) { + $loader = new SchemaLoader(); + $loader->loadInternalFile(env('FIXTURE_SCHEMA_METADATA'), 'test'); +} From a39ce094a1873be0716c4c7dba8128a479b0b981 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 12:51:32 +0100 Subject: [PATCH 6/9] fixed issues reported by phpstan --- src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php index c658623..9121ccf 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php @@ -13,7 +13,6 @@ namespace CakeDC\DbTest\TestSuite\Fixture\Extension; use Cake\Database\Connection; -use Cake\Datasource\ConnectionInterface; use Cake\Datasource\ConnectionManager; use CakeDC\DbTest\TestSuite\Fixture\FixtureManager; use Exception; @@ -74,11 +73,11 @@ public function notify(Started $event): void * Disconnects from test database (if necessary), sets up, and reconnects. * Disable datasource caching and sets the datasource for the test run. * - * @param \Cake\Datasource\ConnectionInterface $ds Directory Separator + * @param \Cake\Database\Connection $ds Directory Separator * @param array $database Database configuration * @return void */ - protected function loadDatabase(ConnectionInterface $ds, array $database): void + protected function loadDatabase(Connection $ds, array $database): void { if ($ds->getDriver()->isConnected()) { // attempt to disconnect and close connection to db. From 89072477ff5fd5bf2921822cc049a135935e0e99 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 14:36:08 +0100 Subject: [PATCH 7/9] fixed unititialized properties --- src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php index 9121ccf..a4f2abb 100644 --- a/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php +++ b/src/TestSuite/Fixture/Extension/PHPUnitStartedSubscriber.php @@ -27,11 +27,11 @@ class PHPUnitStartedSubscriber implements StartedSubscriber /** * @var true */ - protected bool $databaseLoaded; + protected bool $databaseLoaded = false; /** * @var true */ - protected bool $initialized; + protected bool $initialized = false; /** * @param \CakeDC\DbTest\TestSuite\Fixture\FixtureManager $fixtureManager Fixture Manager instance From 88bcd92b1fd248318f8ad6c008477e70ec558eb8 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 15:51:41 +0100 Subject: [PATCH 8/9] removed semver --- .semver | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 .semver diff --git a/.semver b/.semver deleted file mode 100644 index f5ef8df..0000000 --- a/.semver +++ /dev/null @@ -1,5 +0,0 @@ ---- -:major: 3 -:minor: 0 -:patch: 0 -:special: '' From 6dde7f0bbeee6dfe34685d81b74b34599449e5d1 Mon Sep 17 00:00:00 2001 From: Adam Rusinowski Date: Wed, 29 Nov 2023 16:10:14 +0100 Subject: [PATCH 9/9] added license doc blocks --- src/Command/DbTestCommand.php | 9 +++++++++ src/Command/FixtureImportCommand.php | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Command/DbTestCommand.php b/src/Command/DbTestCommand.php index 33deaff..304cacd 100644 --- a/src/Command/DbTestCommand.php +++ b/src/Command/DbTestCommand.php @@ -1,6 +1,15 @@