Skip to content

Commit

Permalink
Merge pull request #12 from CakeDC/3.next-cake5-upgrade
Browse files Browse the repository at this point in the history
3.next cake5 upgrade
  • Loading branch information
skie committed Feb 1, 2024
2 parents 1cf01a2 + 6dde7f0 commit 104fca2
Show file tree
Hide file tree
Showing 34 changed files with 834 additions and 664 deletions.
16 changes: 13 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
32 changes: 30 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="1.10.14" installed="1.10.14" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="5.10.0" installed="5.10.0" location="./tools/psalm" copy="false"/>
</phive>
5 changes: 0 additions & 5 deletions .semver

This file was deleted.

4 changes: 2 additions & 2 deletions Docs/Documentation/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand Down
16 changes: 10 additions & 6 deletions Docs/Documentation/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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('DbTestPlugin');`

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
Expand All @@ -29,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',
Expand All @@ -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`.


11 changes: 7 additions & 4 deletions Docs/Documentation/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand All @@ -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.
4 changes: 2 additions & 2 deletions Docs/Documentation/Workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions Docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 16 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"name": "cakedc/cakephp-db-test",
"description": "DbTest plugin for CakePHP",
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"cakephp/cakephp-codesniffer": "^4.0"
"cakephp/cakephp-codesniffer": "^4.0",
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -21,20 +23,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": {
Expand Down
6 changes: 6 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<ruleset name="DbTest plugin for CakePHP">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer"/>

<rule ref="CakePHP"/>
</ruleset>
12 changes: 7 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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
bootstrapFiles:
- tests/bootstrap.php
paths:
- src/
52 changes: 24 additions & 28 deletions phpunit.xml.dbtest
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
cacheDirectory=".phpunit.cache"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
Expand All @@ -18,27 +19,22 @@
<!-- Add plugin test suites here. -->
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener
class="\CakeDC\DbTest\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakedc/cakephp-db-test/src/TestSuite/Fixture/FixtureInjector.php">
<arguments>
<object class="\CakeDC\DbTest\TestSuite\Fixture\FixtureManager" />
<boolean></boolean>
</arguments>
</listener>
</listeners>
<!-- Load extension for fixtures -->
<extensions>
<bootstrap class="CakeDC\DbTest\TestSuite\Fixture\Extension\PHPUnitExtension">
<!-- Optionaly enable verbosity -->
<parameter name="verbose" value="false" />
</bootstrap>
</extensions>

<!-- Adds the folders to process in code coverage reports -->
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
<directory suffix=".php">./plugins/*/src/</directory>
<exclude>
<file>./src/Console/Installer.php</file>
<file>./src/Shell/ConsoleShell.php</file>
</exclude>
</whitelist>
</filter>
<!-- Ignore vendor tests in code coverage reports -->
<source>
<include>
<directory suffix=".php">src/</directory>
<directory suffix=".php">plugins/*/src/</directory>
</include>
<exclude>
<file>src/Console/Installer.php</file>
</exclude>
</source>
</phpunit>
26 changes: 26 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
usePhpDocMethodsWithoutMagicCall="true"
findUnusedPsalmSuppress="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
resolveFromConfigFile="true"
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"
>
<projectFiles>
<directory name="src/"/>
<ignoreFiles>
<directory name="vendor/"/>
</ignoreFiles>
</projectFiles>

<issueHandlers>
<RedundantPropertyInitializationCheck errorLevel="suppress"/>
<RedundantCast errorLevel="suppress"/>
<UndefinedAttributeClass errorLevel="suppress"/>
</issueHandlers>
</psalm>
Loading

0 comments on commit 104fca2

Please sign in to comment.