From bde5ee275be0d8ba1078d7065f91a23a2ac69947 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 08:20:53 +0200 Subject: [PATCH 01/11] Add migration script --- migrate.php | 369 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+) create mode 100644 migrate.php diff --git a/migrate.php b/migrate.php new file mode 100644 index 0000000..7a1ea24 --- /dev/null +++ b/migrate.php @@ -0,0 +1,369 @@ + [ + 'Directories to migrate', + 'comma separated, relative to ' . getcwd(), + 'tests', + ], + 'composer_json' => [ + 'Path to the composer.json to update', + 'leave "-" to skip', + 'composer.json', + ], + 'version_constraint' => [ + 'New version constraint for ' . PACKAGE_NAME, + '', + '^3.0', + ], +]; + +/** + * Old method name => new method name + * + * Section 1 of the migration guide. + */ +$renames = [ + 'testDataValidationNotEmpty' => 'assertValidationNotEmpty', + 'testDataValidationEmpty' => 'assertValidationEmpty', + 'testDataValidationRequired' => 'assertValidationRequired', + 'testDataValidationNotRequired' => 'assertValidationNotRequired', + 'testDataValidationBoolean' => 'assertValidationBoolean', + 'testDataValidationURLWithProtocol' => 'assertValidationURLWithProtocol', + 'testDataValidationDateTime' => 'assertValidationDateTime', + 'testDataValidationDate' => 'assertValidationDate', + 'testDataValidationInList' => 'assertValidationInList', + 'testDataValidation' => 'assertValidation', + 'testDataValidationNoErrors' => 'assertValidationNoErrors', + 'testFullDataValidation' => 'assertValidationTableErrors', + 'testFullDataValidationNoErrors' => 'assertValidationTableNoErrors', + 'testDataValidationContains' => 'assertValidationContains', + 'testDataValidationNotContains' => 'assertValidationNotContains', + 'assertDataValidationErrorsContain' => 'assertValidationErrorsContain', + 'testDataValidationListContains' => 'assertValidationListContains', + 'testDataValidationListNotContains' => 'assertValidationListNotContains', + 'testDataRules' => 'assertRules', + // Removed, assertRules() is the replacement. See $manualReviewRenames. + 'testRules' => 'assertRules', + 'testDataRulesNoErrors' => 'assertRulesNoErrors', + 'testDataValidationMaxLength' => 'assertValidationMaxLength', + 'testDataValidationMinLength' => 'assertValidationMinLength', + 'testDataValidationScalar' => 'assertValidationScalar', + 'testDataValidationDecimal' => 'assertValidationDecimal', + 'testDataValidationInteger' => 'assertValidationInteger', + 'testDataValidationNonNegativeInteger' => 'assertValidationNonNegativeInteger', + 'testDataValidationGreaterThanOrEqual' => 'assertValidationGreaterThanOrEqual', + 'testDataValidationEmail' => 'assertValidationEmail', + 'testDataValidationUuid' => 'assertValidationUuid', + 'testDataValidationLengthBetween' => 'assertValidationLengthBetween', + 'testDataValidationRange' => 'assertValidationRange', + 'testDataValidationNaturalNumber' => 'assertValidationNaturalNumber', + 'testDataValidationForeignKey' => 'assertValidationForeignKey', + 'testDataValidationIsUnique' => 'assertValidationIsUnique', +]; + +/** + * Old method names whose replacement does not behave exactly the same, with the reason + */ +$manualReviewRenames = [ + 'testRules' => 'testRules() was removed. assertRules() skips data validation (validate => false) ' + . 'and asserts that saving fails, while testRules() asserted that there are no validation errors first.', +]; + +/** + * Rule-dedicated methods, which now only check their own rule (section 2 of the migration guide) + */ +$ruleDedicatedMethods = [ + 'assertValidationNotEmpty', + 'assertValidationEmpty', + 'assertValidationRequired', + 'assertValidationNotRequired', + 'assertValidationBoolean', + 'assertValidationURLWithProtocol', + 'assertValidationDateTime', + 'assertValidationDate', + 'assertValidationMaxLength', + 'assertValidationMinLength', + 'assertValidationScalar', + 'assertValidationDecimal', + 'assertValidationInteger', + 'assertValidationNonNegativeInteger', + 'assertValidationGreaterThanOrEqual', + 'assertValidationEmail', + 'assertValidationUuid', + 'assertValidationLengthBetween', + 'assertValidationRange', + 'assertValidationNaturalNumber', +]; + +$values = []; + +function read_from_console($prompt) +{ + if (function_exists('readline')) { + $line = trim(readline($prompt)); + if (!empty($line)) { + readline_add_history($line); + } + } else { + echo $prompt; + $line = trim(fgets(STDIN)); + } + + return $line; +} + +/** + * Build the regular expression matching calls/references of the given method names + * + * Only matches names directly preceded by "->" or "::", so that e.g. own test methods named alike are not touched. + * The longest names come first and a word boundary is enforced, so `testDataValidation` never matches a longer name. + */ +function method_call_pattern(array $methodNames) +{ + usort($methodNames, static function ($a, $b) { + return strlen($b) - strlen($a); + }); + $alternatives = implode('|', array_map(static function ($name) { + return preg_quote($name, '/'); + }, $methodNames)); + + return '/(->|::)(\s*)(' . $alternatives . ')\b/'; +} + +/** + * Find all PHP files in the given directories + */ +function find_php_files(array $paths) +{ + $files = []; + foreach ($paths as $path) { + if (is_file($path) && substr($path, -4) === '.php') { + $files[] = $path; + continue; + } + if (!is_dir($path)) { + echo "Warning: '$path' does not exist, skipping.\n"; + continue; + } + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), + ); + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'php') { + $files[] = $file->getPathname(); + } + } + } + sort($files); + + return array_unique($files); +} + +/** + * Get the line number of a byte offset within a text + */ +function line_of($text, $offset) +{ + return substr_count($text, "\n", 0, $offset) + 1; +} + +$modify = 'n'; +do { + if ($modify == 'q') { + exit; + } + + $values = []; + + echo "----------------------------------------------------------------------\n"; + echo 'Migration of ' . PACKAGE_NAME . " to 3.x\n"; + echo "Please, provide the following information:\n"; + echo "----------------------------------------------------------------------\n"; + foreach ($fields as $fieldKey => $field) { + $default = $field[COL_DEFAULT] ?? ''; + $prompt = sprintf( + '%s%s%s: ', + $field[COL_DESCRIPTION], + $field[COL_HELP] ? ' (' . $field[COL_HELP] . ')' : '', + $default !== '' ? ' [' . $default . ']' : '', + ); + $values[$fieldKey] = read_from_console($prompt); + if (empty($values[$fieldKey])) { + $values[$fieldKey] = $default; + } + } + echo "\n"; + + echo "----------------------------------------------------------------------\n"; + echo "Please, check that everything is correct:\n"; + echo "----------------------------------------------------------------------\n"; + foreach ($fields as $fieldKey => $field) { + echo $field[COL_DESCRIPTION] . ": $values[$fieldKey]\n"; + } + echo "\n"; +} while (($modify = strtolower(read_from_console('Migrate files with these values? [y/N/q] '))) !== 'y'); +echo "\n"; + +$paths = array_filter(array_map('trim', explode(',', $values['paths']))); +$filesToMigrate = find_php_files($paths); + +$renamePattern = method_call_pattern(array_keys($renames)); +$ruleDedicatedPattern = method_call_pattern($ruleDedicatedMethods); +$leftoverPattern = '/\b(' . implode('|', array_map(static function ($name) { + return preg_quote($name, '/'); +}, array_keys($renames))) . ')\b/'; + +$totalReplacements = 0; +$changedFiles = 0; +$manualReview = []; +$ruleDedicatedCalls = []; +$leftovers = []; + +echo "----------------------------------------------------------------------\n"; +echo "Renaming methods:\n"; +echo "----------------------------------------------------------------------\n"; +foreach ($filesToMigrate as $filename) { + $contentToReplaceIn = file_get_contents($filename); + + // Collect the calls that need a manual review, before replacing them + if (preg_match_all($renamePattern, $contentToReplaceIn, $matches, PREG_OFFSET_CAPTURE)) { + foreach ($matches[3] as $match) { + if (isset($manualReviewRenames[$match[0]])) { + $manualReview[] = sprintf( + '%s:%d: %s', + $filename, + line_of($contentToReplaceIn, $match[1]), + $manualReviewRenames[$match[0]], + ); + } + } + } + + $count = 0; + $migratedContent = preg_replace_callback( + $renamePattern, + static function ($match) use ($renames) { + return $match[1] . $match[2] . $renames[$match[3]]; + }, + $contentToReplaceIn, + -1, + $count, + ); + + if ($count > 0) { + file_put_contents($filename, $migratedContent); + echo "$filename: $count replacement(s)\n"; + $totalReplacements += $count; + $changedFiles++; + } + + // Rule-dedicated methods now only check their own rule + if (preg_match_all($ruleDedicatedPattern, $migratedContent, $matches, PREG_OFFSET_CAPTURE)) { + foreach ($matches[3] as $match) { + $ruleDedicatedCalls[] = sprintf( + '%s:%d: %s()', + $filename, + line_of($migratedContent, $match[1]), + $match[0], + ); + } + } + + // Old names still present, e.g. in strings, callables or own method definitions + if (preg_match_all($leftoverPattern, $migratedContent, $matches, PREG_OFFSET_CAPTURE)) { + foreach ($matches[1] as $match) { + $leftovers[] = sprintf( + '%s:%d: %s', + $filename, + line_of($migratedContent, $match[1]), + $match[0], + ); + } + } +} +echo "\n$totalReplacements replacement(s) in $changedFiles of " . count($filesToMigrate) . " file(s).\n\n"; + +$composerUpdated = false; +if ($values['composer_json'] !== '-') { + echo "----------------------------------------------------------------------\n"; + echo "Updating composer.json:\n"; + echo "----------------------------------------------------------------------\n"; + $composerJson = $values['composer_json']; + if (!is_file($composerJson)) { + echo "Warning: '$composerJson' does not exist, skipping.\n"; + } else { + $content = file_get_contents($composerJson); + $pattern = '/("' . preg_quote(PACKAGE_NAME, '/') . '"\s*:\s*")([^"]*)(")/'; + if (!preg_match($pattern, $content, $match)) { + echo 'Warning: ' . PACKAGE_NAME . " is not required in '$composerJson', skipping.\n"; + } else { + // Only replace the version constraint, so the formatting of the file is preserved + $content = preg_replace($pattern, '${1}' . $values['version_constraint'] . '${3}', $content, 1); + file_put_contents($composerJson, $content); + echo "Changed the constraint from '$match[2]' to '" . $values['version_constraint'] . "'.\n"; + $composerUpdated = true; + } + } + echo "\n"; +} + +echo "Done.\n\n"; + +if (!empty($manualReview)) { + echo "----------------------------------------------------------------------\n"; + echo "Please, review these replacements manually:\n"; + echo "----------------------------------------------------------------------\n"; + echo implode("\n", $manualReview) . "\n\n"; +} + +if (!empty($leftovers)) { + echo "----------------------------------------------------------------------\n"; + echo "Old method names that were not replaced automatically:\n"; + echo "(e.g. in strings, callables or own methods with the same name)\n"; + echo "----------------------------------------------------------------------\n"; + echo implode("\n", $leftovers) . "\n\n"; +} + +if (!empty($ruleDedicatedCalls)) { + echo "----------------------------------------------------------------------\n"; + echo "Rule-dedicated methods now check only their own rule.\n"; + echo "Previously the entire error array of the field was compared, which could hide\n"; + echo "unrelated errors. Please, check that these tests still cover what you intend,\n"; + echo "especially where a custom \$expected with several rules is passed:\n"; + echo "----------------------------------------------------------------------\n"; + echo implode("\n", $ruleDedicatedCalls) . "\n\n"; +} + +echo "\nNext steps:\n"; +if ($composerUpdated) { + echo '- Run: composer update ' . PACKAGE_NAME . " --with-dependencies\n"; +} +echo "- Run your test suite and fix failing tests.\n"; +echo "- Review the diff (e.g. git diff) before committing.\n\n"; + +echo "See https://github.com/orca-services/cakephp-data-validation-testing/blob/cakephp-5.x/docs/Migration.md\n"; From cafc26ebdcdd24f8ec638a2eacf84354361d605e Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 08:29:12 +0200 Subject: [PATCH 02/11] Update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3188f41..425c370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - `assertValidationNotContains()` to assert that specific validation rules are absent, ignoring others on the same field. - `assertValidationListContains()` and `assertValidationListNotContains()` list helpers. - Optional custom `$expected` parameter for `assertValidationForeignKey()` and `assertValidationIsUnique()`. +- Migration script `migrate.php` to automate upgrading from 2.x to 3.x. See the [migration guide](docs/Migration.md). [#47](https://github.com/orca-services/cakephp-data-validation-testing/issues/47) ### Changed - **BREAKING CHANGE:** Replace `testDataValidation` prefix in all test trait method names with `assertValidation`. E.g. `testDataValidationNotEmpty()` becomes `assertValidationNotEmpty()`. From dcf9fb55883cd8dd54820b0ed6526fe4296f1fa6 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 08:29:21 +0200 Subject: [PATCH 03/11] Update readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 515efc0..17e1864 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ A CakePHP plugin to help testing data validation. | Plugin Version | CakePHP Compatibility | Branch | Status | |----------------|-----------------------|-------------| --------- | +| 3.x | 5.x | cakephp-5.x | Supported | | 2.x | 5.x | cakephp-5.x | Supported | | 1.x | 4.x | cakephp-4.x | Supported | | 0.x | 2.x | cakephp-2.x | EOL | @@ -22,6 +23,11 @@ See the [installation documentation](docs/Installation.md). You can use the plugin as shown in [usage documentation](docs/Usage.md). +## Upgrading + +See the [migration guide](docs/Migration.md) for upgrading from 2.x to 3.x. +It includes a migration script that automates most of the necessary changes. + ## Versioning The releases of this plugin are versioned using [SemVer](http://semver.org/). From 6ad3f62c3299d850d4e95dee14ab665e48a11275 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 08:29:30 +0200 Subject: [PATCH 04/11] Update migration guide --- docs/Migration.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/Migration.md b/docs/Migration.md index 548cf47..f05617a 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -7,6 +7,42 @@ This major version bundles two breaking changes: --- +## Automated migration + +A migration script automates most of the steps below. Run it from the root of your application, +after installing 3.x (or before, if you let the script update your `composer.json`): + +```bash +php vendor/orca-services/cakephp-data-validation-testing/migrate.php +``` + +The script interactively asks for: + +- The directories to migrate (comma separated, default: `tests`) +- The path to your `composer.json` (default: `composer.json`, enter `-` to skip updating it) +- The new version constraint for the package (default: `^3.0`) + +What it does: + +1. Renames all calls of the old method names to the new ones (see [Method renames](#1-method-renames)). + Only method calls and references preceded by `->` or `::` are replaced, + so your own test methods with similar names are left untouched. +2. Replaces calls of the removed `testRules()` with `assertRules()` and lists them for manual review + (see [`testRules()` removal](#testrules-removal)). +3. Lists all calls of rule-dedicated methods for manual review + (see [Rule-dedicated methods now check only their own rule](#2-rule-dedicated-methods-now-check-only-their-own-rule)). +4. Lists old method names it did not replace, e.g. in strings, callables or own methods with the same name. +5. Optionally updates the version constraint of the package in your `composer.json`. + +The script modifies your files in place, so make sure your working tree is clean (e.g. committed in Git) before running it. +Afterward: + +- Run `composer update orca-services/cakephp-data-validation-testing --with-dependencies`, if the script updated your `composer.json`. +- Review the diff (e.g. `git diff`) and the listed findings. +- Run your test suite and fix any failing tests. + +--- + ## 1. Method renames All `test`/`testData`-prefixed methods on `DataValidationTestTrait` are now prefixed with `assert` instead. @@ -52,6 +88,13 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationForeignKey()` | `assertValidationForeignKey()` | | `testDataValidationIsUnique()` | `assertValidationIsUnique()` | +### `testRules()` removal + +`testRules()` was removed without a direct equivalent. Use `assertRules()` instead, but note the difference in behavior: +`assertRules()` skips data validation (`validate => false`) and asserts that saving fails, +while `testRules()` first asserted that there are no validation errors. +Review each replaced call to make sure the test still covers what you intend. + --- ## 2. Rule-dedicated methods now check only their own rule @@ -59,3 +102,6 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** Previously, methods like `assertValidationBoolean()`, `assertValidationEmail()`, `assertValidationInteger()`, etc. compared the **entire** error array for a field against an expected array (or `[]` for valid values). If a field had multiple validation errors, this could hide unrelated errors or cause false failures. Now these methods assert **only their own rule key** (present or absent), ignoring any other errors on the same field. + +Review your calls of these methods, especially where a custom `$expected` array containing several rules is passed, +and make sure the tests still cover what you intend. The migration script lists all these calls for you. From 9482cba8691d2b52d5b9f2aa4d5ba82069903399 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 11:13:08 +0200 Subject: [PATCH 05/11] Update compatibility matrix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 17e1864..eab78b7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A CakePHP plugin to help testing data validation. | Plugin Version | CakePHP Compatibility | Branch | Status | |----------------|-----------------------|-------------| --------- | | 3.x | 5.x | cakephp-5.x | Supported | -| 2.x | 5.x | cakephp-5.x | Supported | +| 2.x | 5.x | - | EOL | | 1.x | 4.x | cakephp-4.x | Supported | | 0.x | 2.x | cakephp-2.x | EOL | From 99608e38e3bbf96aaa3fb78f7b3dc9811397118a Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 11:35:32 +0200 Subject: [PATCH 06/11] Remove composer part from migrate script --- migrate.php | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/migrate.php b/migrate.php index 7a1ea24..dae38e5 100644 --- a/migrate.php +++ b/migrate.php @@ -13,7 +13,6 @@ * 1. Renames all calls of the old `testDataValidation`-prefixed trait methods to the new `assertValidation`-prefixed ones. * 2. Replaces calls of the removed `testRules()` with `assertRules()` and lists them for manual review. * 3. Lists all calls of rule-dedicated methods, which now only check their own rule, for manual review. - * 4. Optionally updates the version constraint of the package in composer.json. * * Usage: php vendor/orca-services/cakephp-data-validation-testing/migrate.php (from your application root) */ @@ -30,16 +29,6 @@ 'comma separated, relative to ' . getcwd(), 'tests', ], - 'composer_json' => [ - 'Path to the composer.json to update', - 'leave "-" to skip', - 'composer.json', - ], - 'version_constraint' => [ - 'New version constraint for ' . PACKAGE_NAME, - '', - '^3.0', - ], ]; /** @@ -236,7 +225,7 @@ function line_of($text, $offset) $ruleDedicatedPattern = method_call_pattern($ruleDedicatedMethods); $leftoverPattern = '/\b(' . implode('|', array_map(static function ($name) { return preg_quote($name, '/'); -}, array_keys($renames))) . ')\b/'; + }, array_keys($renames))) . ')\b/'; $totalReplacements = 0; $changedFiles = 0; @@ -308,30 +297,6 @@ static function ($match) use ($renames) { } echo "\n$totalReplacements replacement(s) in $changedFiles of " . count($filesToMigrate) . " file(s).\n\n"; -$composerUpdated = false; -if ($values['composer_json'] !== '-') { - echo "----------------------------------------------------------------------\n"; - echo "Updating composer.json:\n"; - echo "----------------------------------------------------------------------\n"; - $composerJson = $values['composer_json']; - if (!is_file($composerJson)) { - echo "Warning: '$composerJson' does not exist, skipping.\n"; - } else { - $content = file_get_contents($composerJson); - $pattern = '/("' . preg_quote(PACKAGE_NAME, '/') . '"\s*:\s*")([^"]*)(")/'; - if (!preg_match($pattern, $content, $match)) { - echo 'Warning: ' . PACKAGE_NAME . " is not required in '$composerJson', skipping.\n"; - } else { - // Only replace the version constraint, so the formatting of the file is preserved - $content = preg_replace($pattern, '${1}' . $values['version_constraint'] . '${3}', $content, 1); - file_put_contents($composerJson, $content); - echo "Changed the constraint from '$match[2]' to '" . $values['version_constraint'] . "'.\n"; - $composerUpdated = true; - } - } - echo "\n"; -} - echo "Done.\n\n"; if (!empty($manualReview)) { @@ -360,9 +325,6 @@ static function ($match) use ($renames) { } echo "\nNext steps:\n"; -if ($composerUpdated) { - echo '- Run: composer update ' . PACKAGE_NAME . " --with-dependencies\n"; -} echo "- Run your test suite and fix failing tests.\n"; echo "- Review the diff (e.g. git diff) before committing.\n\n"; From 19c75e0886a12cbe2cd72cb078b1a512b4f2c20b Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 30 Sep 2026 11:36:14 +0200 Subject: [PATCH 07/11] Adjust migration guide --- docs/Migration.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/Migration.md b/docs/Migration.md index f05617a..73a6f13 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -9,18 +9,20 @@ This major version bundles two breaking changes: ## Automated migration -A migration script automates most of the steps below. Run it from the root of your application, -after installing 3.x (or before, if you let the script update your `composer.json`): +A migration script automates most of the steps below. It is shipped with the package, +so first update the package to 3.x: ```bash -php vendor/orca-services/cakephp-data-validation-testing/migrate.php +composer require --dev orca-services/cakephp-data-validation-testing:^3.0 -W ``` -The script interactively asks for: +Then run the script from the root of your application: + +```bash +php vendor/orca-services/cakephp-data-validation-testing/migrate.php +``` -- The directories to migrate (comma separated, default: `tests`) -- The path to your `composer.json` (default: `composer.json`, enter `-` to skip updating it) -- The new version constraint for the package (default: `^3.0`) +The script interactively asks for the directories to migrate (comma separated, default: `tests`). What it does: @@ -32,12 +34,10 @@ What it does: 3. Lists all calls of rule-dedicated methods for manual review (see [Rule-dedicated methods now check only their own rule](#2-rule-dedicated-methods-now-check-only-their-own-rule)). 4. Lists old method names it did not replace, e.g. in strings, callables or own methods with the same name. -5. Optionally updates the version constraint of the package in your `composer.json`. The script modifies your files in place, so make sure your working tree is clean (e.g. committed in Git) before running it. Afterward: -- Run `composer update orca-services/cakephp-data-validation-testing --with-dependencies`, if the script updated your `composer.json`. - Review the diff (e.g. `git diff`) and the listed findings. - Run your test suite and fix any failing tests. From c9e970f2103f12c4e6b010a76980d43d41a05b63 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Thu, 1 Oct 2026 08:58:34 +0200 Subject: [PATCH 08/11] Improve change log entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 425c370..7557307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - `assertValidationNotContains()` to assert that specific validation rules are absent, ignoring others on the same field. - `assertValidationListContains()` and `assertValidationListNotContains()` list helpers. - Optional custom `$expected` parameter for `assertValidationForeignKey()` and `assertValidationIsUnique()`. -- Migration script `migrate.php` to automate upgrading from 2.x to 3.x. See the [migration guide](docs/Migration.md). [#47](https://github.com/orca-services/cakephp-data-validation-testing/issues/47) +- Migration script `migrate.php` to assist upgrading from 2.x to 3.x. See the [migration guide](docs/Migration.md). [#47](https://github.com/orca-services/cakephp-data-validation-testing/issues/47) ### Changed - **BREAKING CHANGE:** Replace `testDataValidation` prefix in all test trait method names with `assertValidation`. E.g. `testDataValidationNotEmpty()` becomes `assertValidationNotEmpty()`. From 0800fb57e69f75611fefb147378f44dc6f9bc1f9 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Thu, 1 Oct 2026 08:59:09 +0200 Subject: [PATCH 09/11] Improve migration guide --- docs/Migration.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/Migration.md b/docs/Migration.md index 73a6f13..2a7d9e5 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -5,11 +5,15 @@ This major version bundles two breaking changes: 1. **Method renames** — [PR #45](https://github.com/orca-services/cakephp-data-validation-testing/pull/45) (closes [#44](https://github.com/orca-services/cakephp-data-validation-testing/issues/44)) 2. **Rule-dedicated methods now check only their own rule** — [PR #40](https://github.com/orca-services/cakephp-data-validation-testing/pull/40) (closes [#38](https://github.com/orca-services/cakephp-data-validation-testing/issues/38)) +You can use the [Migration Script](#migration-script) to rename the old method calls automatically +and to find the places that need a manual review. + --- -## Automated migration +## Migration Script -A migration script automates most of the steps below. It is shipped with the package, +The Migration Script does not fully automate the upgrade, but it takes care of the method renames +and lists everything else you need to review manually. It is shipped with the package, so first update the package to 3.x: ```bash @@ -22,7 +26,7 @@ Then run the script from the root of your application: php vendor/orca-services/cakephp-data-validation-testing/migrate.php ``` -The script interactively asks for the directories to migrate (comma separated, default: `tests`). +The script interactively asks for the directories to migrate (comma separated, default: `tests,plugins`). What it does: @@ -104,4 +108,4 @@ Previously, methods like `assertValidationBoolean()`, `assertValidationEmail()`, Now these methods assert **only their own rule key** (present or absent), ignoring any other errors on the same field. Review your calls of these methods, especially where a custom `$expected` array containing several rules is passed, -and make sure the tests still cover what you intend. The migration script lists all these calls for you. +and make sure the tests still cover what you intend. The [Migration Script](#migration-script) lists all these calls for you. From c6f3207d5d962bdff182f9e018e3774a7f14f988 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Thu, 1 Oct 2026 08:59:23 +0200 Subject: [PATCH 10/11] Improve readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eab78b7..5b37656 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ You can use the plugin as shown in [usage documentation](docs/Usage.md). ## Upgrading See the [migration guide](docs/Migration.md) for upgrading from 2.x to 3.x. -It includes a migration script that automates most of the necessary changes. +It includes a migration script that renames the old method calls and lists the places that need a manual review. ## Versioning From e1e98c2b5ef72f48fad4122efef6bde010b4c83f Mon Sep 17 00:00:00 2001 From: Neluxx Date: Thu, 1 Oct 2026 09:00:18 +0200 Subject: [PATCH 11/11] Add plugins to the default directories in the migration script --- migrate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrate.php b/migrate.php index dae38e5..b2ea2f2 100644 --- a/migrate.php +++ b/migrate.php @@ -27,7 +27,7 @@ 'paths' => [ 'Directories to migrate', 'comma separated, relative to ' . getcwd(), - 'tests', + 'tests,plugins', ], ];