From 2c999ac959d74babd1e226d0d2646240da0f2185 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Mon, 21 Sep 2026 15:32:13 +0200 Subject: [PATCH 01/14] Replace `test` prefix in test trait method names with `assert` --- src/Traits/DataValidationTestTrait.php | 156 +++++---- .../Traits/DataValidationTestTraitTest.php | 318 +++++++++--------- 2 files changed, 241 insertions(+), 233 deletions(-) diff --git a/src/Traits/DataValidationTestTrait.php b/src/Traits/DataValidationTestTrait.php index f8f9537..ad7e57f 100644 --- a/src/Traits/DataValidationTestTrait.php +++ b/src/Traits/DataValidationTestTrait.php @@ -31,7 +31,7 @@ trait DataValidationTestTrait * @see \Cake\Validation\Validator::notEmptyString() * @see \Cake\Validation\Validator::notEmptyTime() */ - protected function testDataValidationNotEmpty( + protected function assertDataValidationNotEmpty( Table $table, string $fieldName, array $additionalDataSet = [], @@ -40,7 +40,7 @@ protected function testDataValidationNotEmpty( $list = [null, '']; $expected = ['_empty' => 'This field cannot be left empty']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -59,7 +59,7 @@ protected function testDataValidationNotEmpty( * @see \Cake\Validation\Validator::allowEmptyString() * @see \Cake\Validation\Validator::allowEmptyTime() */ - protected function testDataValidationEmpty( + protected function assertDataValidationEmpty( Table $table, string $fieldName, array $additionalDataSet = [], @@ -68,7 +68,7 @@ protected function testDataValidationEmpty( $list = [null, '']; $notExpected = ['_empty']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -88,14 +88,14 @@ protected function testDataValidationEmpty( * @return void * @see \Cake\Validation\Validator::requirePresence() */ - protected function testDataValidationRequired( + protected function assertDataValidationRequired( Table $table, string $fieldName, array $dataSet = [], array $options = [], ): void { $expected = ['_required' => 'This field is required']; - $this->testDataValidationContains($table, $fieldName, $dataSet, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataSet, $expected, $options); } /** @@ -108,14 +108,14 @@ protected function testDataValidationRequired( * @return void * @see \Cake\Validation\Validator::requirePresence() */ - protected function testDataValidationNotRequired( + protected function assertDataValidationNotRequired( Table $table, string $fieldName, array $dataSet = [], array $options = [], ): void { $notExpected = ['_required']; - $this->testDataValidationNotContains($table, $fieldName, $dataSet, $notExpected, $options); + $this->assertDataValidationNotContains($table, $fieldName, $dataSet, $notExpected, $options); } /** @@ -128,7 +128,7 @@ protected function testDataValidationNotRequired( * @return void * @see \Cake\Validation\Validator::boolean() */ - protected function testDataValidationBoolean( + protected function assertDataValidationBoolean( Table $table, string $fieldName, array $additionalDataSet = [], @@ -137,7 +137,7 @@ protected function testDataValidationBoolean( // Valid values $list = [true, false, 1, 0]; $notExpected = ['boolean']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -149,7 +149,7 @@ protected function testDataValidationBoolean( // Invalid values $list = ['Not a boolean', 123, []]; $expected = ['boolean' => 'The provided value must be a boolean']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -162,7 +162,7 @@ protected function testDataValidationBoolean( * @return void * @see \Cake\Validation\Validator::urlWithProtocol() */ - protected function testDataValidationURLWithProtocol( + protected function assertDataValidationURLWithProtocol( Table $table, string $fieldName, array $additionalDataSet = [], @@ -171,7 +171,7 @@ protected function testDataValidationURLWithProtocol( // Valid values $list = ['https://valid.com', 'http://valid.com']; $notExpected = ['urlWithProtocol']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -183,7 +183,7 @@ protected function testDataValidationURLWithProtocol( // Invalid values $list = ['no-protocol.com', 'htp://foo.com']; $expected = ['urlWithProtocol' => 'The provided value must be a URL with protocol']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -196,7 +196,7 @@ protected function testDataValidationURLWithProtocol( * @return void * @see \Cake\Validation\Validator::dateTime() */ - protected function testDataValidationDateTime( + protected function assertDataValidationDateTime( Table $table, string $fieldName, array $additionalDataSet = [], @@ -211,7 +211,7 @@ protected function testDataValidationDateTime( new FrozenTime(), ]; $notExpected = ['dateTime']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -229,7 +229,7 @@ protected function testDataValidationDateTime( '123', // Numeric ]; $expected = ['dateTime' => 'The provided value must be a date and time of one of these formats: `ymd`']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -242,7 +242,7 @@ protected function testDataValidationDateTime( * @return void * @see \Cake\Validation\Validator::date() */ - protected function testDataValidationDate( + protected function assertDataValidationDate( Table $table, string $fieldName, array $additionalDataSet = [], @@ -259,7 +259,7 @@ protected function testDataValidationDate( new FrozenTime(), ]; $notExpected = ['date']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -277,7 +277,7 @@ protected function testDataValidationDate( $expected = [ 'date' => 'The provided value must be a date of one of these formats: `ymd`', ]; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -292,7 +292,7 @@ protected function testDataValidationDate( * @return void * @see \Cake\Validation\Validator::inList() */ - protected function testDataValidationInList( + protected function assertDataValidationInList( Table $table, array $list, string $fieldName, @@ -302,7 +302,7 @@ protected function testDataValidationInList( ): void { foreach ($list as $value) { $dataSet = array_merge($additionalDataSet, [$fieldName => $value]); - $this->testDataValidation($table, $fieldName, $dataSet, $expected, $options); + $this->assertDataValidation($table, $fieldName, $dataSet, $expected, $options); } } @@ -316,14 +316,14 @@ protected function testDataValidationInList( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function testDataValidationNoErrors( + protected function assertDataValidationNoErrors( Table $table, string $fieldName, array $dataSet, array $options = [], ): void { $expected = []; - $this->testDataValidation($table, $fieldName, $dataSet, $expected, $options); + $this->assertDataValidation($table, $fieldName, $dataSet, $expected, $options); } /** @@ -335,10 +335,10 @@ protected function testDataValidationNoErrors( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function testFullDataValidationNoErrors(Table $table, array $dataSet, array $options = []): void + protected function assertFullDataValidationNoErrors(Table $table, array $dataSet, array $options = []): void { $expected = []; - $this->testFullDataValidation($table, $dataSet, $expected, $options); + $this->assertFullDataValidation($table, $dataSet, $expected, $options); } /** @@ -352,7 +352,7 @@ protected function testFullDataValidationNoErrors(Table $table, array $dataSet, * @return void * @see \Cake\Validation\Validator::validate() */ - protected function testDataValidation( + protected function assertDataValidation( Table $table, string $fieldName, array $dataSet, @@ -377,7 +377,7 @@ protected function testDataValidation( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function testDataValidationContains( + protected function assertDataValidationContains( Table $table, string $fieldName, array $dataSet, @@ -403,7 +403,7 @@ protected function testDataValidationContains( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function testDataValidationNotContains( + protected function assertDataValidationNotContains( Table $table, string $fieldName, array $dataSet, @@ -473,7 +473,7 @@ protected function assertDataValidationErrorsContain(string $fieldName, array $e * @param array $options Additional options for newEntity. * @return void */ - protected function testDataValidationListContains( + protected function assertDataValidationListContains( Table $table, array $list, string $fieldName, @@ -483,7 +483,7 @@ protected function testDataValidationListContains( ): void { foreach ($list as $value) { $dataSet = array_merge($additionalDataSet, [$fieldName => $value]); - $this->testDataValidationContains($table, $fieldName, $dataSet, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataSet, $expected, $options); } } @@ -500,7 +500,7 @@ protected function testDataValidationListContains( * @param array $options Additional options for newEntity. * @return void */ - protected function testDataValidationListNotContains( + protected function assertDataValidationListNotContains( Table $table, array $list, string $fieldName, @@ -510,7 +510,7 @@ protected function testDataValidationListNotContains( ): void { foreach ($list as $value) { $dataSet = array_merge($additionalDataSet, [$fieldName => $value]); - $this->testDataValidationNotContains($table, $fieldName, $dataSet, $rules, $options); + $this->assertDataValidationNotContains($table, $fieldName, $dataSet, $rules, $options); } } @@ -525,7 +525,7 @@ protected function testDataValidationListNotContains( * @return void * @todo Move to a rules dedicated helper class. */ - protected function testDataRules( + protected function assertDataRules( Table $table, string $fieldName, array $dataSet, @@ -553,7 +553,7 @@ protected function testDataRules( * @param array $options Additional options for newEntity. * @return void */ - protected function testRules( + protected function assertRules( Table $table, string $fieldName, array $dataSet, @@ -579,8 +579,12 @@ protected function testRules( * @return void * @todo Move to a rules dedicated helper class. */ - protected function testDataRulesNoErrors(Table $table, string $fieldName, array $dataSet, array $options = []): void - { + protected function assertDataRulesNoErrors( + Table $table, + string $fieldName, + array $dataSet, + array $options = [], + ): void { $defaultOptions = ['validate' => false]; $options = $defaultOptions + $options; $entity = $table->newEntity($dataSet, $options); @@ -603,7 +607,7 @@ protected function testDataRulesNoErrors(Table $table, string $fieldName, array * @return void * @see \Cake\Validation\Validator::maxLength() */ - protected function testDataValidationMaxLength( + protected function assertDataValidationMaxLength( Table $table, string $fieldName, int $maxLength, @@ -614,7 +618,7 @@ protected function testDataValidationMaxLength( $dataset = [$fieldName => $tooLongFieldContent]; $expected ??= ['maxLength' => sprintf('The provided value must be at most `%d` characters long', $maxLength)]; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -628,7 +632,7 @@ protected function testDataValidationMaxLength( * @return void * @see \Cake\Validation\Validator::minLength() */ - protected function testDataValidationMinLength( + protected function assertDataValidationMinLength( Table $table, string $fieldName, int $minLength, @@ -638,7 +642,7 @@ protected function testDataValidationMinLength( $tooShortFieldContent = str_repeat('A', $minLength - 1); $dataset = [$fieldName => $tooShortFieldContent]; $expected ??= ['minLength' => sprintf('The provided value must be at least `%d` characters long', $minLength)]; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -651,7 +655,7 @@ protected function testDataValidationMinLength( * @return void * @see \Cake\Validation\Validator::scalar() */ - protected function testDataValidationScalar( + protected function assertDataValidationScalar( Table $table, string $fieldName, ?array $expected = null, @@ -660,7 +664,7 @@ protected function testDataValidationScalar( $dataset = [$fieldName => []]; // A non-scalar value $expected ??= ['scalar' => 'The provided value must be scalar']; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -673,7 +677,7 @@ protected function testDataValidationScalar( * @return void * @see \Cake\Validation\Validator::decimal() */ - protected function testDataValidationDecimal( + protected function assertDataValidationDecimal( Table $table, string $fieldName, ?array $expected = null, @@ -693,12 +697,12 @@ protected function testDataValidationDecimal( $expected ??= [ 'decimal' => 'The provided value must be decimal with any number of decimal places, including none', ]; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [-99.0, 0.099]; $notExpected = ['decimal']; - $this->testDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -711,7 +715,7 @@ protected function testDataValidationDecimal( * @return void * @see \Cake\Validation\Validator::integer() */ - protected function testDataValidationInteger( + protected function assertDataValidationInteger( Table $table, string $fieldName, ?array $expected = null, @@ -729,12 +733,12 @@ protected function testDataValidationInteger( 'ab0,099', ]; $expected ??= ['integer' => 'The provided value must be an integer']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [-99, 99]; $notExpected = ['integer']; - $this->testDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -747,7 +751,7 @@ protected function testDataValidationInteger( * @return void * @see \Cake\Validation\Validator::nonNegativeInteger() */ - protected function testDataValidationNonNegativeInteger( + protected function assertDataValidationNonNegativeInteger( Table $table, string $fieldName, ?array $expected = null, @@ -757,13 +761,13 @@ protected function testDataValidationNonNegativeInteger( $dataset = [$fieldName => '-1']; $expected ??= ['nonNegativeInteger' => 'The provided value must be a non-negative integer']; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); // Non-negative integer $dataset = [$fieldName => '0']; $notExpected = ['nonNegativeInteger']; - $this->testDataValidationNotContains($table, $fieldName, $dataset, $notExpected, $options); + $this->assertDataValidationNotContains($table, $fieldName, $dataset, $notExpected, $options); } /** @@ -778,7 +782,7 @@ protected function testDataValidationNonNegativeInteger( * @return void * @see \Cake\Validation\Validator::greaterThanOrEqual() */ - protected function testDataValidationGreaterThanOrEqual( + protected function assertDataValidationGreaterThanOrEqual( Table $table, string $fieldName, float|int $threshold, @@ -798,13 +802,13 @@ protected function testDataValidationGreaterThanOrEqual( $threshold, ), ]; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); // Valid values: exactly at and just above the threshold $aboveThreshold = is_int($threshold) ? $threshold + 1 : $threshold + 0.01; $list = [$threshold, $aboveThreshold]; $notExpected = ['greaterThanOrEqual']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -824,7 +828,7 @@ protected function testDataValidationGreaterThanOrEqual( * @return void * @see \Cake\Validation\Validator::email() */ - protected function testDataValidationEmail( + protected function assertDataValidationEmail( Table $table, string $fieldName, ?array $expected = null, @@ -838,7 +842,7 @@ protected function testDataValidationEmail( 'in@valid.1', ]; $expected ??= ['email' => 'The provided value must be an e-mail address']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [ @@ -848,7 +852,7 @@ protected function testDataValidationEmail( 'va_lid.123+spamfolder@email.test', ]; $notExpected = ['email']; - $this->testDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -861,7 +865,7 @@ protected function testDataValidationEmail( * @return void * @see \Cake\Validation\Validator::uuid() */ - protected function testDataValidationUuid( + protected function assertDataValidationUuid( Table $table, string $fieldName, ?array $expected = null, @@ -875,7 +879,7 @@ protected function testDataValidationUuid( 'notAUuid', // Not a UUID ]; $expected ??= ['uuid' => 'The provided value must be a UUID']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [ @@ -890,7 +894,7 @@ protected function testDataValidationUuid( 'fc93ab0e-c99e-4b58-975e-9c5e68c53624', // GUID ]; $notExpected = ['uuid']; - $this->testDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -905,7 +909,7 @@ protected function testDataValidationUuid( * @return void * @see \Cake\Validation\Validator::lengthBetween() */ - protected function testDataValidationLengthBetween( + protected function assertDataValidationLengthBetween( Table $table, string $fieldName, int $minLength, @@ -925,7 +929,7 @@ protected function testDataValidationLengthBetween( $maxlength, ), ]; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); } // Too long @@ -939,7 +943,7 @@ protected function testDataValidationLengthBetween( $maxlength, ), ]; - $this->testDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -954,7 +958,7 @@ protected function testDataValidationLengthBetween( * @return void * @see \Cake\Validation\Validator::range() */ - protected function testDataValidationRange( + protected function assertDataValidationRange( Table $table, string $fieldName, int|float $lowerBound, @@ -984,7 +988,7 @@ protected function testDataValidationRange( $upperBound, ), ]; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid $list = [ @@ -995,7 +999,7 @@ protected function testDataValidationRange( ]; $notExpected = ['range']; - $this->testDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -1008,7 +1012,7 @@ protected function testDataValidationRange( * @return void * @see \Cake\Validation\Validator::naturalNumber() */ - protected function testDataValidationNaturalNumber( + protected function assertDataValidationNaturalNumber( Table $table, string $fieldName, array $additionalDataSet = [], @@ -1017,12 +1021,12 @@ protected function testDataValidationNaturalNumber( // Invalid values $list = [0, -1]; $expected = ['naturalNumber' => 'The provided value must be a natural number']; - $this->testDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); // Valid value $list = [1]; $notExpected = ['naturalNumber']; - $this->testDataValidationListNotContains( + $this->assertDataValidationListNotContains( $table, $list, $fieldName, @@ -1042,8 +1046,12 @@ protected function testDataValidationNaturalNumber( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function testFullDataValidation(Table $table, array $dataSet, array $expected, array $options = []): void - { + protected function assertFullDataValidation( + Table $table, + array $dataSet, + array $expected, + array $options = [], + ): void { $entity = $table->newEntity($dataSet, $options); $errors = $entity->getErrors(); @@ -1059,7 +1067,7 @@ protected function testFullDataValidation(Table $table, array $dataSet, array $e * @param array|null $expected The expected rule errors ("rule name" => "message") that must be present. * @return void */ - protected function testDataValidationForeignKey( + protected function assertDataValidationForeignKey( Table $table, string $fieldName, ?int $notExistingForeignKey = 999999, @@ -1086,7 +1094,7 @@ protected function testDataValidationForeignKey( * @param array|null $expected The expected rule errors ("rule name" => "message") that must be present. * @return void */ - protected function testDataValidationIsUnique( + protected function assertDataValidationIsUnique( Table $table, string $fieldName, mixed $fieldValue, diff --git a/tests/TestCase/Traits/DataValidationTestTraitTest.php b/tests/TestCase/Traits/DataValidationTestTraitTest.php index dd8148c..3ebb11c 100644 --- a/tests/TestCase/Traits/DataValidationTestTraitTest.php +++ b/tests/TestCase/Traits/DataValidationTestTraitTest.php @@ -45,12 +45,12 @@ protected function tearDown(): void } /** - * Test the testDataValidation base method + * Test the assertDataValidation base method * * @return void - * @covers ::testDataValidation + * @covers ::assertDataValidation */ - public function testTestDataValidation(): void + public function testAssertDataValidation(): void { // Ensure data validation of some field works as expected first $fieldName = 'not_empty_field'; @@ -60,16 +60,16 @@ public function testTestDataValidation(): void $errors = $entity->getError($fieldName); static::assertSame($expectedErrors, $errors); - $this->testDataValidation($this->table, $fieldName, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $fieldName, $dataSet, $expectedErrors); } /** - * Test the testDataValidationNoErrors base method + * Test the assertDataValidationNoErrors base method * * @return void - * @covers ::testDataValidationNoErrors + * @covers ::assertDataValidationNoErrors */ - public function testTestDataValidationNoErrors(): void + public function testAssertDataValidationNoErrors(): void { // Ensure data validation of some field works as expected first $fieldName = 'empty_field'; @@ -79,272 +79,272 @@ public function testTestDataValidationNoErrors(): void $errors = $entity->getError($fieldName); static::assertSame($expectedErrors, $errors); - $this->testDataValidationNoErrors($this->table, $fieldName, $dataSet); + $this->assertDataValidationNoErrors($this->table, $fieldName, $dataSet); } /** - * Test that testDataValidationNotEmpty passes when the field is not empty. + * Test that assertDataValidationNotEmpty passes when the field is not empty. * * @return void - * @covers ::testDataValidationNotEmpty + * @covers ::assertDataValidationNotEmpty */ - public function testTestDataValidationNotEmpty(): void + public function testAssertDataValidationNotEmpty(): void { // Ensure data validation of the field works as expected first $field = 'not_empty_field'; $expectedErrors = ['_empty' => 'This field cannot be left empty']; $dataSet = [$field => '']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationNotEmpty($this->table, $field); + $this->assertDataValidationNotEmpty($this->table, $field); } /** - * Test that testDataValidationEmpty passes when the field is empty. + * Test that assertDataValidationEmpty passes when the field is empty. * * @return void - * @covers ::testDataValidationEmpty + * @covers ::assertDataValidationEmpty */ - public function testTestDataValidationEmpty(): void + public function testAssertDataValidationEmpty(): void { // Ensure data validation of the field works as expected first $field = 'empty_field'; $dataSet = [$field => '']; - $this->testDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertDataValidationNoErrors($this->table, $field, $dataSet); - $this->testDataValidationEmpty($this->table, $field); + $this->assertDataValidationEmpty($this->table, $field); } /** - * Test that testDataValidationRequired passes when the field is required. + * Test that assertDataValidationRequired passes when the field is required. * * @return void - * @covers ::testDataValidationRequired + * @covers ::assertDataValidationRequired */ - public function testTestDataValidationRequired(): void + public function testAssertDataValidationRequired(): void { // Ensure data validation of the field works as expected first $field = 'required_field'; $expectedErrors = ['_required' => 'This field is required']; $dataSet = []; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationRequired($this->table, $field); + $this->assertDataValidationRequired($this->table, $field); } /** - * Test that testDataValidationNotRequired passes when the field is empty. + * Test that assertDataValidationNotRequired passes when the field is empty. * * @return void - * @covers ::testDataValidationNotRequired + * @covers ::assertDataValidationNotRequired */ - public function testTestDataValidationNotRequired(): void + public function testAssertDataValidationNotRequired(): void { // Ensure data validation of the field works as expected first $field = 'empty_field'; $dataSet = []; - $this->testDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertDataValidationNoErrors($this->table, $field, $dataSet); - $this->testDataValidationNotRequired($this->table, $field); + $this->assertDataValidationNotRequired($this->table, $field); } /** - * Test that testDataValidationBoolean passes when the field is boolean. + * Test that assertDataValidationBoolean passes when the field is boolean. * * @return void - * @covers ::testDataValidationBoolean + * @covers ::assertDataValidationBoolean */ - public function testTestDataValidationBoolean(): void + public function testAssertDataValidationBoolean(): void { // Ensure data validation of the field works as expected first $field = 'boolean_field'; $expectedErrors = ['boolean' => 'The provided value must be a boolean']; $dataSet = [$field => 'Not a boolean']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationBoolean($this->table, $field); + $this->assertDataValidationBoolean($this->table, $field); } /** - * Test that testDataValidationURLWithProtocol passes when the field is url. + * Test that assertDataValidationURLWithProtocol passes when the field is url. * * @return void - * @covers ::testDataValidationURLWithProtocol + * @covers ::assertDataValidationURLWithProtocol */ - public function testTestDataValidationURLWithProtocol(): void + public function testAssertDataValidationURLWithProtocol(): void { // Ensure data validation of the field works as expected first $field = 'url_field'; $expectedErrors = ['urlWithProtocol' => 'The provided value must be a URL with protocol']; $dataSet = [$field => 'no-protocol.com']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationURLWithProtocol($this->table, $field); + $this->assertDataValidationURLWithProtocol($this->table, $field); } /** - * Test that testDataValidationDateTime passes when the field is datetime. + * Test that assertDataValidationDateTime passes when the field is datetime. * * @return void - * @covers ::testDataValidationDateTime + * @covers ::assertDataValidationDateTime */ - public function testTestDataValidationDateTime(): void + public function testAssertDataValidationDateTime(): void { // Ensure data validation of the field works as expected first $field = 'datetime_field'; $expectedErrors = ['dateTime' => 'The provided value must be a date and time of one of these formats: `ymd`']; $dataSet = [$field => 'Not a date/time']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationDateTime($this->table, $field); + $this->assertDataValidationDateTime($this->table, $field); } /** - * Test that testDataValidationDate passes when the field is date. + * Test that assertDataValidationDate passes when the field is date. * * @return void - * @covers ::testDataValidationDate + * @covers ::assertDataValidationDate */ - public function testTestDataValidationDate(): void + public function testAssertDataValidationDate(): void { // Ensure data validation of the field works as expected first $field = 'date_field'; $expectedErrors = ['date' => 'The provided value must be a date of one of these formats: `ymd`']; $dataSet = [$field => 'Not a date']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationDate($this->table, $field); + $this->assertDataValidationDate($this->table, $field); } /** - * Test that testDataValidationInList passes when the field is datetime. + * Test that assertDataValidationInList passes when the field is datetime. * * @return void - * @covers ::testDataValidationInList + * @covers ::assertDataValidationInList */ - public function testTestDataValidationInList(): void + public function testAssertDataValidationInList(): void { // Ensure data validation of the field works as expected first $field = 'datetime_field'; $expectedErrors = ['dateTime' => 'The provided value must be a date and time of one of these formats: `ymd`']; $invalidValues = ['Not a date/time', '123']; - $this->testDataValidationInList($this->table, $invalidValues, $field, $expectedErrors); + $this->assertDataValidationInList($this->table, $invalidValues, $field, $expectedErrors); $validValues = ['1900-01-01 00:00:00', '2022-10-12 11:50:32']; - $this->testDataValidationInList($this->table, $validValues, $field); + $this->assertDataValidationInList($this->table, $validValues, $field); } /** - * Test that testDataValidationMaxLength passes when the value is less than the max length. + * Test that assertDataValidationMaxLength passes when the value is less than the max length. * * @return void - * @covers ::testDataValidationMaxLength + * @covers ::assertDataValidationMaxLength */ - public function testTestDataValidationMaxLength(): void + public function testAssertDataValidationMaxLength(): void { // Ensure data validation of the field works as expected first $maxLength = 10; $field = 'max_length_field'; $expectedErrors = ['maxLength' => 'The provided value must be at most `10` characters long']; $dataSet = [$field => str_repeat('A', $maxLength + 1)]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationMaxLength($this->table, $field, $maxLength); + $this->assertDataValidationMaxLength($this->table, $field, $maxLength); } /** - * Test that testDataValidationMinLength passes when the value is greater than the min length. + * Test that assertDataValidationMinLength passes when the value is greater than the min length. * * @return void - * @covers ::testDataValidationMinLength + * @covers ::assertDataValidationMinLength */ - public function testTestDataValidationMinLength(): void + public function testAssertDataValidationMinLength(): void { // Ensure data validation of the field works as expected first $minLength = 5; $field = 'min_length_field'; $expectedErrors = ['minLength' => 'The provided value must be at least `5` characters long']; $dataSet = [$field => str_repeat('A', $minLength - 1)]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationMinLength($this->table, $field, $minLength); + $this->assertDataValidationMinLength($this->table, $field, $minLength); } /** - * Test that testDataValidationScalar passes when the field is scalar. + * Test that assertDataValidationScalar passes when the field is scalar. * * @return void - * @covers ::testDataValidationScalar + * @covers ::assertDataValidationScalar */ - public function testTestDataValidationScalar(): void + public function testAssertDataValidationScalar(): void { // Ensure data validation of the field works as expected first $field = 'scalar_field'; $entity = $this->table->newEntity([$field => []]); static::assertArrayHasKey('scalar', $entity->getError($field)); - $this->testDataValidationScalar($this->table, $field); + $this->assertDataValidationScalar($this->table, $field); } /** - * Test that testDataValidationDecimal passes when the field is decimal. + * Test that assertDataValidationDecimal passes when the field is decimal. * * @return void - * @covers ::testDataValidationDecimal + * @covers ::assertDataValidationDecimal */ - public function testTestDataValidationDecimal(): void + public function testAssertDataValidationDecimal(): void { // Ensure data validation of the field works as expected first $field = 'decimal_field'; $expectedErrors = ['decimal' => 'The provided value must be decimal with any number of decimal places, including none']; $dataSet = [$field => 'not a decimal']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationDecimal($this->table, $field); + $this->assertDataValidationDecimal($this->table, $field); } /** - * Test that testDataValidationInteger passes when the field is integer. + * Test that assertDataValidationInteger passes when the field is integer. * * @return void - * @covers ::testDataValidationInteger + * @covers ::assertDataValidationInteger */ - public function testTestDataValidationInteger(): void + public function testAssertDataValidationInteger(): void { // Ensure data validation of the field works as expected first $field = 'integer_field'; $expectedErrors = ['integer' => 'The provided value must be an integer']; $dataSet = [$field => 'not a integer']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationInteger($this->table, $field); + $this->assertDataValidationInteger($this->table, $field); } /** - * Test that testDataValidationNonNegativeInteger passes when the field is a non-negative integer. + * Test that assertDataValidationNonNegativeInteger passes when the field is a non-negative integer. * * @return void - * @covers ::testDataValidationNonNegativeInteger + * @covers ::assertDataValidationNonNegativeInteger */ - public function testTestDataValidationNonNegativeInteger(): void + public function testAssertDataValidationNonNegativeInteger(): void { // Ensure data validation of the field works as expected first $field = 'non_negative_integer_field'; $expectedErrors = ['nonNegativeInteger' => 'The provided value must be a non-negative integer']; $dataSet = [$field => 'not a integer']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationNonNegativeInteger($this->table, $field); + $this->assertDataValidationNonNegativeInteger($this->table, $field); } /** - * Test that testDataValidationGreaterThanOrEqual passes when the field value + * Test that assertDataValidationGreaterThanOrEqual passes when the field value * is greater than or equal to the configured threshold. * * @return void - * @covers ::testDataValidationGreaterThanOrEqual + * @covers ::assertDataValidationGreaterThanOrEqual */ - public function testTestDataValidationGreaterThanOrEqual(): void + public function testAssertDataValidationGreaterThanOrEqual(): void { // Ensure data validation of the field works as expected first $threshold = 10; @@ -358,26 +358,26 @@ public function testTestDataValidationGreaterThanOrEqual(): void // Just below the threshold should fail $dataSet = [$field => $threshold - 1]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); // At the threshold should pass $dataSet = [$field => $threshold]; - $this->testDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertDataValidationNoErrors($this->table, $field, $dataSet); // Above the threshold should pass $dataSet = [$field => $threshold + 1]; - $this->testDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertDataValidationNoErrors($this->table, $field, $dataSet); - $this->testDataValidationGreaterThanOrEqual($this->table, $field, $threshold); + $this->assertDataValidationGreaterThanOrEqual($this->table, $field, $threshold); } /** - * Test that testDataValidationEmail passes when the field is a valid email. + * Test that assertDataValidationEmail passes when the field is a valid email. * * @return void - * @covers ::testDataValidationEmail + * @covers ::assertDataValidationEmail */ - public function testTestDataValidationEmail(): void + public function testAssertDataValidationEmail(): void { // Ensure data validation of the field works as expected first $field = 'email_field'; @@ -385,18 +385,18 @@ public function testTestDataValidationEmail(): void 'email' => 'The provided value must be an e-mail address', ]; $dataSet = [$field => 'Not an email']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationEmail($this->table, $field); + $this->assertDataValidationEmail($this->table, $field); } /** - * Test that testDataValidationUuid passes when the field is a valid uuid. + * Test that assertDataValidationUuid passes when the field is a valid uuid. * * @return void - * @covers ::testDataValidationUuid + * @covers ::assertDataValidationUuid */ - public function testTestDataValidationUuid(): void + public function testAssertDataValidationUuid(): void { // Ensure data validation of the field works as expected first $field = 'uuid_field'; @@ -404,18 +404,18 @@ public function testTestDataValidationUuid(): void 'uuid' => 'The provided value must be a UUID', ]; $dataSet = [$field => 'Not a uuid']; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationUuid($this->table, $field); + $this->assertDataValidationUuid($this->table, $field); } /** - * Test that testDataValidationLengthBetween passes when the field is between the min and max length. + * Test that assertDataValidationLengthBetween passes when the field is between the min and max length. * * @return void - * @covers ::testDataValidationLengthBetween + * @covers ::assertDataValidationLengthBetween */ - public function testTestDataValidationLengthBetween(): void + public function testAssertDataValidationLengthBetween(): void { // Ensure data validation of the field works as expected first $minLength = 5; @@ -423,20 +423,20 @@ public function testTestDataValidationLengthBetween(): void $field = 'length_between_field'; $expectedErrors = ['lengthBetween' => 'The length of the provided value must be between `5` and `10`, inclusively']; $dataSet = [$field => str_repeat('A', $minLength - 1)]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); $dataSet = [$field => str_repeat('A', $maxLength + 1)]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationLengthBetween($this->table, $field, $minLength, $maxLength); + $this->assertDataValidationLengthBetween($this->table, $field, $minLength, $maxLength); } /** - * Test that testDataValidationRange passes when the field is between the lower and upper bound. + * Test that assertDataValidationRange passes when the field is between the lower and upper bound. * * @return void - * @covers ::testDataValidationRange + * @covers ::assertDataValidationRange */ - public function testTestDataValidationRange(): void + public function testAssertDataValidationRange(): void { // Ensure data validation of the field works as expected first $lowerBound = -30.0; @@ -445,29 +445,29 @@ public function testTestDataValidationRange(): void $expectedErrors = ['range' => 'The provided value must be between `-30` and `30`, inclusively']; $dataSet = [$field => $lowerBound - 1]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); $dataSet = [$field => $upperBound + 1]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationRange($this->table, $field, $lowerBound, $upperBound); + $this->assertDataValidationRange($this->table, $field, $lowerBound, $upperBound); } /** - * Test that testDataValidationNaturalNumber passes when the field is a natural number. + * Test that assertDataValidationNaturalNumber passes when the field is a natural number. * * @return void - * @covers ::testDataValidationNaturalNumber + * @covers ::assertDataValidationNaturalNumber */ - public function testTestDataValidationNaturalNumber(): void + public function testAssertDataValidationNaturalNumber(): void { // Ensure data validation of the field works as expected first $field = 'natural_number_field'; $expectedErrors = ['naturalNumber' => 'The provided value must be a natural number']; $dataSet = [$field => -1]; - $this->testDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); - $this->testDataValidationNaturalNumber($this->table, $field); + $this->assertDataValidationNaturalNumber($this->table, $field); } /** @@ -479,7 +479,7 @@ public function testTestDataValidationNaturalNumber(): void public function testTestFullDataValidationNoErrors(): void { $dataSet = ['required_field' => 'required', 'multi_rule_field' => 1]; - $this->testFullDataValidationNoErrors($this->table, $dataSet); + $this->assertFullDataValidationNoErrors($this->table, $dataSet); } /** @@ -495,7 +495,7 @@ public function testTestFullDataValidation(): void 'not_empty_field' => ['_empty' => 'This field cannot be left empty'], 'required_field' => ['_required' => 'This field is required'], ]; - $this->testFullDataValidation($this->table, $dataSet, $expectedErrors); + $this->assertFullDataValidation($this->table, $dataSet, $expectedErrors); } /** @@ -518,7 +518,7 @@ public function testTestDataRules(): void static::assertFalse($this->table->save($duplicate)); static::assertSame($expectedErrors, $duplicate->getError($field)); - $this->testDataRules($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataRules($this->table, $field, $dataSet, $expectedErrors); } /** @@ -537,16 +537,16 @@ public function testTestDataRulesNoErrors(): void static::assertNotFalse($this->table->save($entity)); static::assertEmpty($entity->getError($field)); - $this->testDataRulesNoErrors($this->table, $field, [$field => 'another-unique-' . uniqid('', true)]); + $this->assertDataRulesNoErrors($this->table, $field, [$field => 'another-unique-' . uniqid('', true)]); } /** - * Test that testDataValidationForeignKey passes when the foreign key does not exist. + * Test that assertDataValidationForeignKey passes when the foreign key does not exist. * * @return void - * @covers ::testDataValidationForeignKey + * @covers ::assertDataValidationForeignKey */ - public function testTestDataValidationForeignKey(): void + public function testAssertDataValidationForeignKey(): void { // Ensure the rule works as expected first $field = 'parent_id'; @@ -557,42 +557,42 @@ public function testTestDataValidationForeignKey(): void static::assertFalse($this->table->checkRules($entity)); static::assertSame($expectedErrors, $entity->getError($field)); - $this->testDataValidationForeignKey($this->table, $field, $notExistingForeignKey); + $this->assertDataValidationForeignKey($this->table, $field, $notExistingForeignKey); } /** - * Test that testDataValidationForeignKey passes with the default not existing foreign key. + * Test that assertDataValidationForeignKey passes with the default not existing foreign key. * * @return void - * @covers ::testDataValidationForeignKey + * @covers ::assertDataValidationForeignKey */ - public function testTestDataValidationForeignKeyDefault(): void + public function testAssertDataValidationForeignKeyDefault(): void { $field = 'parent_id'; - $this->testDataValidationForeignKey($this->table, $field); + $this->assertDataValidationForeignKey($this->table, $field); } /** - * Test that testDataValidationForeignKey accepts a custom expected error. + * Test that assertDataValidationForeignKey accepts a custom expected error. * * @return void - * @covers ::testDataValidationForeignKey + * @covers ::assertDataValidationForeignKey */ - public function testTestDataValidationForeignKeyCustomExpected(): void + public function testAssertDataValidationForeignKeyCustomExpected(): void { $field = 'parent_id'; $expectedErrors = ['_existsIn' => 'This value does not exist']; - $this->testDataValidationForeignKey($this->table, $field, 999999, $expectedErrors); + $this->assertDataValidationForeignKey($this->table, $field, 999999, $expectedErrors); } /** - * Test that testDataValidationIsUnique passes when the field value is not unique. + * Test that assertDataValidationIsUnique passes when the field value is not unique. * * @return void - * @covers ::testDataValidationIsUnique + * @covers ::assertDataValidationIsUnique */ - public function testTestDataValidationIsUnique(): void + public function testAssertDataValidationIsUnique(): void { // Ensure the rule works as expected first $field = 'unique_field'; @@ -612,16 +612,16 @@ public function testTestDataValidationIsUnique(): void // Use a different value since the trait method will also save a record $this->table->deleteAll([]); - $this->testDataValidationIsUnique($this->table, $field, 'another-duplicate-value', $dataset); + $this->assertDataValidationIsUnique($this->table, $field, 'another-duplicate-value', $dataset); } /** - * Test that testDataValidationIsUnique accepts a custom expected error. + * Test that assertDataValidationIsUnique accepts a custom expected error. * * @return void - * @covers ::testDataValidationIsUnique + * @covers ::assertDataValidationIsUnique */ - public function testTestDataValidationIsUniqueCustomExpected(): void + public function testAssertDataValidationIsUniqueCustomExpected(): void { $field = 'unique_field'; $dataset = [ @@ -630,7 +630,7 @@ public function testTestDataValidationIsUniqueCustomExpected(): void ]; $expectedErrors = ['_isUnique' => 'This value is already in use']; - $this->testDataValidationIsUnique($this->table, $field, 'custom-duplicate-value', $dataset, $expectedErrors); + $this->assertDataValidationIsUnique($this->table, $field, 'custom-duplicate-value', $dataset, $expectedErrors); } /** @@ -655,16 +655,16 @@ public function testTestRules(): void static::assertFalse($this->table->save($duplicate)); static::assertSame($expectedErrors, $duplicate->getError($field)); - $this->testRules($this->table, $field, $dataSet, $expectedErrors); + $this->assertRules($this->table, $field, $dataSet, $expectedErrors); } /** - * Test the testDataValidationContains base method. + * Test the assertDataValidationContains base method. * * @return void - * @covers ::testDataValidationContains + * @covers ::assertDataValidationContains */ - public function testTestDataValidationContains(): void + public function testAssertDataValidationContains(): void { // An invalid scalar value must produce a `scalar` error $field = 'scalar_field'; @@ -673,52 +673,52 @@ public function testTestDataValidationContains(): void $entity = $this->table->newEntity($dataSet); static::assertArrayHasKey('scalar', $entity->getError($field)); - $this->testDataValidationContains($this->table, $field, $dataSet, $expectedErrors); + $this->assertDataValidationContains($this->table, $field, $dataSet, $expectedErrors); } /** - * Test the testDataValidationNotContains base method. + * Test the assertDataValidationNotContains base method. * * @return void - * @covers ::testDataValidationNotContains + * @covers ::assertDataValidationNotContains */ - public function testTestDataValidationNotContains(): void + public function testAssertDataValidationNotContains(): void { // A valid boolean value must not produce a `boolean` error $field = 'boolean_field'; $entity = $this->table->newEntity([$field => true]); static::assertArrayNotHasKey('boolean', $entity->getError($field)); - $this->testDataValidationNotContains($this->table, $field, [$field => true], ['boolean']); + $this->assertDataValidationNotContains($this->table, $field, [$field => true], ['boolean']); } /** - * Test the testDataValidationListContains base method. + * Test the assertDataValidationListContains base method. * * @return void - * @covers ::testDataValidationListContains + * @covers ::assertDataValidationListContains */ - public function testTestDataValidationListContains(): void + public function testAssertDataValidationListContains(): void { $field = 'boolean_field'; $expectedErrors = ['boolean' => 'The provided value must be a boolean']; $invalidValues = ['Not a boolean', 123]; - $this->testDataValidationListContains($this->table, $invalidValues, $field, $expectedErrors); + $this->assertDataValidationListContains($this->table, $invalidValues, $field, $expectedErrors); } /** - * Test the testDataValidationListNotContains base method. + * Test the assertDataValidationListNotContains base method. * * @return void - * @covers ::testDataValidationListNotContains + * @covers ::assertDataValidationListNotContains */ - public function testTestDataValidationListNotContains(): void + public function testAssertDataValidationListNotContains(): void { $field = 'boolean_field'; $validValues = [true, false, 1, 0]; - $this->testDataValidationListNotContains($this->table, $validValues, $field, ['boolean']); + $this->assertDataValidationListNotContains($this->table, $validValues, $field, ['boolean']); } /** @@ -744,7 +744,7 @@ public function testAssertDataValidationErrorsContain(): void * Test that a type-specific method only asserts its own rule and ignores unrelated errors. * * @return void - * @covers ::testDataValidationInteger + * @covers ::assertDataValidationInteger */ public function testTypeSpecificMethodIgnoresUnrelatedErrors(): void { @@ -757,6 +757,6 @@ public function testTypeSpecificMethodIgnoresUnrelatedErrors(): void static::assertArrayHasKey('maxLength', $errors); // The type-specific method still passes because it checks for the `integer` rule, only - $this->testDataValidationInteger($this->table, $field); + $this->assertDataValidationInteger($this->table, $field); } } From 96a7315187da9e4e2f7fc61eb699a39b3a5b8784 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Mon, 21 Sep 2026 15:33:53 +0200 Subject: [PATCH 02/14] Update change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b23f1b..28e2806 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Optional custom `$expected` parameter for `testDataValidationForeignKey()` and `testDataValidationIsUnique()`. ### Changed +- **BREAKING CHANGE:** Replace `test` prefix in all test trait method names with `assert`. - **BREAKING CHANGE:** All type-specific/rule-dedicated methods now assert only their own validation rule for the field, ignoring others. ### Fixed From 4a96d4b0bb16602e4911cbb82f20724d8b76d1e3 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Tue, 22 Sep 2026 08:18:28 +0200 Subject: [PATCH 03/14] Remove `Data` prefix from all method names --- CHANGELOG.md | 2 +- src/Traits/DataValidationTestTrait.php | 142 +++---- .../Traits/DataValidationTestTraitTest.php | 348 +++++++++--------- 3 files changed, 246 insertions(+), 246 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28e2806..befa05c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Optional custom `$expected` parameter for `testDataValidationForeignKey()` and `testDataValidationIsUnique()`. ### Changed -- **BREAKING CHANGE:** Replace `test` prefix in all test trait method names with `assert`. +- **BREAKING CHANGE:** Replace `testData` prefix in all test trait method names with `assert`. - **BREAKING CHANGE:** All type-specific/rule-dedicated methods now assert only their own validation rule for the field, ignoring others. ### Fixed diff --git a/src/Traits/DataValidationTestTrait.php b/src/Traits/DataValidationTestTrait.php index ad7e57f..7de875b 100644 --- a/src/Traits/DataValidationTestTrait.php +++ b/src/Traits/DataValidationTestTrait.php @@ -31,7 +31,7 @@ trait DataValidationTestTrait * @see \Cake\Validation\Validator::notEmptyString() * @see \Cake\Validation\Validator::notEmptyTime() */ - protected function assertDataValidationNotEmpty( + protected function assertValidationNotEmpty( Table $table, string $fieldName, array $additionalDataSet = [], @@ -40,7 +40,7 @@ protected function assertDataValidationNotEmpty( $list = [null, '']; $expected = ['_empty' => 'This field cannot be left empty']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -59,7 +59,7 @@ protected function assertDataValidationNotEmpty( * @see \Cake\Validation\Validator::allowEmptyString() * @see \Cake\Validation\Validator::allowEmptyTime() */ - protected function assertDataValidationEmpty( + protected function assertValidationEmpty( Table $table, string $fieldName, array $additionalDataSet = [], @@ -68,7 +68,7 @@ protected function assertDataValidationEmpty( $list = [null, '']; $notExpected = ['_empty']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -88,14 +88,14 @@ protected function assertDataValidationEmpty( * @return void * @see \Cake\Validation\Validator::requirePresence() */ - protected function assertDataValidationRequired( + protected function assertValidationRequired( Table $table, string $fieldName, array $dataSet = [], array $options = [], ): void { $expected = ['_required' => 'This field is required']; - $this->assertDataValidationContains($table, $fieldName, $dataSet, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataSet, $expected, $options); } /** @@ -108,14 +108,14 @@ protected function assertDataValidationRequired( * @return void * @see \Cake\Validation\Validator::requirePresence() */ - protected function assertDataValidationNotRequired( + protected function assertValidationNotRequired( Table $table, string $fieldName, array $dataSet = [], array $options = [], ): void { $notExpected = ['_required']; - $this->assertDataValidationNotContains($table, $fieldName, $dataSet, $notExpected, $options); + $this->assertValidationNotContains($table, $fieldName, $dataSet, $notExpected, $options); } /** @@ -128,7 +128,7 @@ protected function assertDataValidationNotRequired( * @return void * @see \Cake\Validation\Validator::boolean() */ - protected function assertDataValidationBoolean( + protected function assertValidationBoolean( Table $table, string $fieldName, array $additionalDataSet = [], @@ -137,7 +137,7 @@ protected function assertDataValidationBoolean( // Valid values $list = [true, false, 1, 0]; $notExpected = ['boolean']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -149,7 +149,7 @@ protected function assertDataValidationBoolean( // Invalid values $list = ['Not a boolean', 123, []]; $expected = ['boolean' => 'The provided value must be a boolean']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -162,7 +162,7 @@ protected function assertDataValidationBoolean( * @return void * @see \Cake\Validation\Validator::urlWithProtocol() */ - protected function assertDataValidationURLWithProtocol( + protected function assertValidationURLWithProtocol( Table $table, string $fieldName, array $additionalDataSet = [], @@ -171,7 +171,7 @@ protected function assertDataValidationURLWithProtocol( // Valid values $list = ['https://valid.com', 'http://valid.com']; $notExpected = ['urlWithProtocol']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -183,7 +183,7 @@ protected function assertDataValidationURLWithProtocol( // Invalid values $list = ['no-protocol.com', 'htp://foo.com']; $expected = ['urlWithProtocol' => 'The provided value must be a URL with protocol']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -196,7 +196,7 @@ protected function assertDataValidationURLWithProtocol( * @return void * @see \Cake\Validation\Validator::dateTime() */ - protected function assertDataValidationDateTime( + protected function assertValidationDateTime( Table $table, string $fieldName, array $additionalDataSet = [], @@ -211,7 +211,7 @@ protected function assertDataValidationDateTime( new FrozenTime(), ]; $notExpected = ['dateTime']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -229,7 +229,7 @@ protected function assertDataValidationDateTime( '123', // Numeric ]; $expected = ['dateTime' => 'The provided value must be a date and time of one of these formats: `ymd`']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -242,7 +242,7 @@ protected function assertDataValidationDateTime( * @return void * @see \Cake\Validation\Validator::date() */ - protected function assertDataValidationDate( + protected function assertValidationDate( Table $table, string $fieldName, array $additionalDataSet = [], @@ -259,7 +259,7 @@ protected function assertDataValidationDate( new FrozenTime(), ]; $notExpected = ['date']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -277,7 +277,7 @@ protected function assertDataValidationDate( $expected = [ 'date' => 'The provided value must be a date of one of these formats: `ymd`', ]; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); } /** @@ -292,7 +292,7 @@ protected function assertDataValidationDate( * @return void * @see \Cake\Validation\Validator::inList() */ - protected function assertDataValidationInList( + protected function assertValidationInList( Table $table, array $list, string $fieldName, @@ -302,7 +302,7 @@ protected function assertDataValidationInList( ): void { foreach ($list as $value) { $dataSet = array_merge($additionalDataSet, [$fieldName => $value]); - $this->assertDataValidation($table, $fieldName, $dataSet, $expected, $options); + $this->assertValidation($table, $fieldName, $dataSet, $expected, $options); } } @@ -316,14 +316,14 @@ protected function assertDataValidationInList( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function assertDataValidationNoErrors( + protected function assertValidationNoErrors( Table $table, string $fieldName, array $dataSet, array $options = [], ): void { $expected = []; - $this->assertDataValidation($table, $fieldName, $dataSet, $expected, $options); + $this->assertValidation($table, $fieldName, $dataSet, $expected, $options); } /** @@ -352,7 +352,7 @@ protected function assertFullDataValidationNoErrors(Table $table, array $dataSet * @return void * @see \Cake\Validation\Validator::validate() */ - protected function assertDataValidation( + protected function assertValidation( Table $table, string $fieldName, array $dataSet, @@ -377,7 +377,7 @@ protected function assertDataValidation( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function assertDataValidationContains( + protected function assertValidationContains( Table $table, string $fieldName, array $dataSet, @@ -387,7 +387,7 @@ protected function assertDataValidationContains( $entity = $table->newEntity($dataSet, $options); $errors = $entity->getError($fieldName); - $this->assertDataValidationErrorsContain($fieldName, $errors, $expected); + $this->assertValidationErrorsContain($fieldName, $errors, $expected); } /** @@ -403,7 +403,7 @@ protected function assertDataValidationContains( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function assertDataValidationNotContains( + protected function assertValidationNotContains( Table $table, string $fieldName, array $dataSet, @@ -436,7 +436,7 @@ protected function assertDataValidationNotContains( * @param array $expected The expected errors ("rule name" => "message") that must be present. * @return void */ - protected function assertDataValidationErrorsContain(string $fieldName, array $errors, array $expected): void + protected function assertValidationErrorsContain(string $fieldName, array $errors, array $expected): void { foreach ($expected as $rule => $message) { static::assertArrayHasKey( @@ -473,7 +473,7 @@ protected function assertDataValidationErrorsContain(string $fieldName, array $e * @param array $options Additional options for newEntity. * @return void */ - protected function assertDataValidationListContains( + protected function assertValidationListContains( Table $table, array $list, string $fieldName, @@ -483,7 +483,7 @@ protected function assertDataValidationListContains( ): void { foreach ($list as $value) { $dataSet = array_merge($additionalDataSet, [$fieldName => $value]); - $this->assertDataValidationContains($table, $fieldName, $dataSet, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataSet, $expected, $options); } } @@ -500,7 +500,7 @@ protected function assertDataValidationListContains( * @param array $options Additional options for newEntity. * @return void */ - protected function assertDataValidationListNotContains( + protected function assertValidationListNotContains( Table $table, array $list, string $fieldName, @@ -510,7 +510,7 @@ protected function assertDataValidationListNotContains( ): void { foreach ($list as $value) { $dataSet = array_merge($additionalDataSet, [$fieldName => $value]); - $this->assertDataValidationNotContains($table, $fieldName, $dataSet, $rules, $options); + $this->assertValidationNotContains($table, $fieldName, $dataSet, $rules, $options); } } @@ -579,7 +579,7 @@ protected function assertRules( * @return void * @todo Move to a rules dedicated helper class. */ - protected function assertDataRulesNoErrors( + protected function assertRulesNoErrors( Table $table, string $fieldName, array $dataSet, @@ -607,7 +607,7 @@ protected function assertDataRulesNoErrors( * @return void * @see \Cake\Validation\Validator::maxLength() */ - protected function assertDataValidationMaxLength( + protected function assertValidationMaxLength( Table $table, string $fieldName, int $maxLength, @@ -618,7 +618,7 @@ protected function assertDataValidationMaxLength( $dataset = [$fieldName => $tooLongFieldContent]; $expected ??= ['maxLength' => sprintf('The provided value must be at most `%d` characters long', $maxLength)]; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -632,7 +632,7 @@ protected function assertDataValidationMaxLength( * @return void * @see \Cake\Validation\Validator::minLength() */ - protected function assertDataValidationMinLength( + protected function assertValidationMinLength( Table $table, string $fieldName, int $minLength, @@ -642,7 +642,7 @@ protected function assertDataValidationMinLength( $tooShortFieldContent = str_repeat('A', $minLength - 1); $dataset = [$fieldName => $tooShortFieldContent]; $expected ??= ['minLength' => sprintf('The provided value must be at least `%d` characters long', $minLength)]; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -655,7 +655,7 @@ protected function assertDataValidationMinLength( * @return void * @see \Cake\Validation\Validator::scalar() */ - protected function assertDataValidationScalar( + protected function assertValidationScalar( Table $table, string $fieldName, ?array $expected = null, @@ -664,7 +664,7 @@ protected function assertDataValidationScalar( $dataset = [$fieldName => []]; // A non-scalar value $expected ??= ['scalar' => 'The provided value must be scalar']; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -677,7 +677,7 @@ protected function assertDataValidationScalar( * @return void * @see \Cake\Validation\Validator::decimal() */ - protected function assertDataValidationDecimal( + protected function assertValidationDecimal( Table $table, string $fieldName, ?array $expected = null, @@ -697,12 +697,12 @@ protected function assertDataValidationDecimal( $expected ??= [ 'decimal' => 'The provided value must be decimal with any number of decimal places, including none', ]; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [-99.0, 0.099]; $notExpected = ['decimal']; - $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -715,7 +715,7 @@ protected function assertDataValidationDecimal( * @return void * @see \Cake\Validation\Validator::integer() */ - protected function assertDataValidationInteger( + protected function assertValidationInteger( Table $table, string $fieldName, ?array $expected = null, @@ -733,12 +733,12 @@ protected function assertDataValidationInteger( 'ab0,099', ]; $expected ??= ['integer' => 'The provided value must be an integer']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [-99, 99]; $notExpected = ['integer']; - $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -751,7 +751,7 @@ protected function assertDataValidationInteger( * @return void * @see \Cake\Validation\Validator::nonNegativeInteger() */ - protected function assertDataValidationNonNegativeInteger( + protected function assertValidationNonNegativeInteger( Table $table, string $fieldName, ?array $expected = null, @@ -761,13 +761,13 @@ protected function assertDataValidationNonNegativeInteger( $dataset = [$fieldName => '-1']; $expected ??= ['nonNegativeInteger' => 'The provided value must be a non-negative integer']; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); // Non-negative integer $dataset = [$fieldName => '0']; $notExpected = ['nonNegativeInteger']; - $this->assertDataValidationNotContains($table, $fieldName, $dataset, $notExpected, $options); + $this->assertValidationNotContains($table, $fieldName, $dataset, $notExpected, $options); } /** @@ -782,7 +782,7 @@ protected function assertDataValidationNonNegativeInteger( * @return void * @see \Cake\Validation\Validator::greaterThanOrEqual() */ - protected function assertDataValidationGreaterThanOrEqual( + protected function assertValidationGreaterThanOrEqual( Table $table, string $fieldName, float|int $threshold, @@ -802,13 +802,13 @@ protected function assertDataValidationGreaterThanOrEqual( $threshold, ), ]; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); // Valid values: exactly at and just above the threshold $aboveThreshold = is_int($threshold) ? $threshold + 1 : $threshold + 0.01; $list = [$threshold, $aboveThreshold]; $notExpected = ['greaterThanOrEqual']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -828,7 +828,7 @@ protected function assertDataValidationGreaterThanOrEqual( * @return void * @see \Cake\Validation\Validator::email() */ - protected function assertDataValidationEmail( + protected function assertValidationEmail( Table $table, string $fieldName, ?array $expected = null, @@ -842,7 +842,7 @@ protected function assertDataValidationEmail( 'in@valid.1', ]; $expected ??= ['email' => 'The provided value must be an e-mail address']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [ @@ -852,7 +852,7 @@ protected function assertDataValidationEmail( 'va_lid.123+spamfolder@email.test', ]; $notExpected = ['email']; - $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -865,7 +865,7 @@ protected function assertDataValidationEmail( * @return void * @see \Cake\Validation\Validator::uuid() */ - protected function assertDataValidationUuid( + protected function assertValidationUuid( Table $table, string $fieldName, ?array $expected = null, @@ -879,7 +879,7 @@ protected function assertDataValidationUuid( 'notAUuid', // Not a UUID ]; $expected ??= ['uuid' => 'The provided value must be a UUID']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid values $list = [ @@ -894,7 +894,7 @@ protected function assertDataValidationUuid( 'fc93ab0e-c99e-4b58-975e-9c5e68c53624', // GUID ]; $notExpected = ['uuid']; - $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -909,7 +909,7 @@ protected function assertDataValidationUuid( * @return void * @see \Cake\Validation\Validator::lengthBetween() */ - protected function assertDataValidationLengthBetween( + protected function assertValidationLengthBetween( Table $table, string $fieldName, int $minLength, @@ -929,7 +929,7 @@ protected function assertDataValidationLengthBetween( $maxlength, ), ]; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); } // Too long @@ -943,7 +943,7 @@ protected function assertDataValidationLengthBetween( $maxlength, ), ]; - $this->assertDataValidationContains($table, $fieldName, $dataset, $expected, $options); + $this->assertValidationContains($table, $fieldName, $dataset, $expected, $options); } /** @@ -958,7 +958,7 @@ protected function assertDataValidationLengthBetween( * @return void * @see \Cake\Validation\Validator::range() */ - protected function assertDataValidationRange( + protected function assertValidationRange( Table $table, string $fieldName, int|float $lowerBound, @@ -988,7 +988,7 @@ protected function assertDataValidationRange( $upperBound, ), ]; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, [], $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, [], $options); // Valid $list = [ @@ -999,7 +999,7 @@ protected function assertDataValidationRange( ]; $notExpected = ['range']; - $this->assertDataValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); + $this->assertValidationListNotContains($table, $list, $fieldName, $notExpected, [], $options); } /** @@ -1012,7 +1012,7 @@ protected function assertDataValidationRange( * @return void * @see \Cake\Validation\Validator::naturalNumber() */ - protected function assertDataValidationNaturalNumber( + protected function assertValidationNaturalNumber( Table $table, string $fieldName, array $additionalDataSet = [], @@ -1021,12 +1021,12 @@ protected function assertDataValidationNaturalNumber( // Invalid values $list = [0, -1]; $expected = ['naturalNumber' => 'The provided value must be a natural number']; - $this->assertDataValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); + $this->assertValidationListContains($table, $list, $fieldName, $expected, $additionalDataSet, $options); // Valid value $list = [1]; $notExpected = ['naturalNumber']; - $this->assertDataValidationListNotContains( + $this->assertValidationListNotContains( $table, $list, $fieldName, @@ -1067,7 +1067,7 @@ protected function assertFullDataValidation( * @param array|null $expected The expected rule errors ("rule name" => "message") that must be present. * @return void */ - protected function assertDataValidationForeignKey( + protected function assertValidationForeignKey( Table $table, string $fieldName, ?int $notExistingForeignKey = 999999, @@ -1081,7 +1081,7 @@ protected function assertDataValidationForeignKey( $expected ??= ['_existsIn' => 'This value does not exist']; - $this->assertDataValidationErrorsContain($fieldName, $entity->getError($fieldName), $expected); + $this->assertValidationErrorsContain($fieldName, $entity->getError($fieldName), $expected); } /** @@ -1094,7 +1094,7 @@ protected function assertDataValidationForeignKey( * @param array|null $expected The expected rule errors ("rule name" => "message") that must be present. * @return void */ - protected function assertDataValidationIsUnique( + protected function assertValidationIsUnique( Table $table, string $fieldName, mixed $fieldValue, @@ -1121,6 +1121,6 @@ protected function assertDataValidationIsUnique( $expected ??= ['_isUnique' => 'This value is already in use']; - $this->assertDataValidationErrorsContain($fieldName, $entity->getError($fieldName), $expected); + $this->assertValidationErrorsContain($fieldName, $entity->getError($fieldName), $expected); } } diff --git a/tests/TestCase/Traits/DataValidationTestTraitTest.php b/tests/TestCase/Traits/DataValidationTestTraitTest.php index 3ebb11c..b510415 100644 --- a/tests/TestCase/Traits/DataValidationTestTraitTest.php +++ b/tests/TestCase/Traits/DataValidationTestTraitTest.php @@ -45,12 +45,12 @@ protected function tearDown(): void } /** - * Test the assertDataValidation base method + * Test the assertValidation base method * * @return void - * @covers ::assertDataValidation + * @covers ::assertValidation */ - public function testAssertDataValidation(): void + public function testAssertValidation(): void { // Ensure data validation of some field works as expected first $fieldName = 'not_empty_field'; @@ -60,16 +60,16 @@ public function testAssertDataValidation(): void $errors = $entity->getError($fieldName); static::assertSame($expectedErrors, $errors); - $this->assertDataValidation($this->table, $fieldName, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $fieldName, $dataSet, $expectedErrors); } /** - * Test the assertDataValidationNoErrors base method + * Test the assertValidationNoErrors base method * * @return void - * @covers ::assertDataValidationNoErrors + * @covers ::assertValidationNoErrors */ - public function testAssertDataValidationNoErrors(): void + public function testAssertValidationNoErrors(): void { // Ensure data validation of some field works as expected first $fieldName = 'empty_field'; @@ -79,272 +79,272 @@ public function testAssertDataValidationNoErrors(): void $errors = $entity->getError($fieldName); static::assertSame($expectedErrors, $errors); - $this->assertDataValidationNoErrors($this->table, $fieldName, $dataSet); + $this->assertValidationNoErrors($this->table, $fieldName, $dataSet); } /** - * Test that assertDataValidationNotEmpty passes when the field is not empty. + * Test that assertValidationNotEmpty passes when the field is not empty. * * @return void - * @covers ::assertDataValidationNotEmpty + * @covers ::assertValidationNotEmpty */ - public function testAssertDataValidationNotEmpty(): void + public function testAssertValidationNotEmpty(): void { // Ensure data validation of the field works as expected first $field = 'not_empty_field'; $expectedErrors = ['_empty' => 'This field cannot be left empty']; $dataSet = [$field => '']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationNotEmpty($this->table, $field); + $this->assertValidationNotEmpty($this->table, $field); } /** - * Test that assertDataValidationEmpty passes when the field is empty. + * Test that assertValidationEmpty passes when the field is empty. * * @return void - * @covers ::assertDataValidationEmpty + * @covers ::assertValidationEmpty */ - public function testAssertDataValidationEmpty(): void + public function testAssertValidationEmpty(): void { // Ensure data validation of the field works as expected first $field = 'empty_field'; $dataSet = [$field => '']; - $this->assertDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertValidationNoErrors($this->table, $field, $dataSet); - $this->assertDataValidationEmpty($this->table, $field); + $this->assertValidationEmpty($this->table, $field); } /** - * Test that assertDataValidationRequired passes when the field is required. + * Test that assertValidationRequired passes when the field is required. * * @return void - * @covers ::assertDataValidationRequired + * @covers ::assertValidationRequired */ - public function testAssertDataValidationRequired(): void + public function testAssertValidationRequired(): void { // Ensure data validation of the field works as expected first $field = 'required_field'; $expectedErrors = ['_required' => 'This field is required']; $dataSet = []; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationRequired($this->table, $field); + $this->assertValidationRequired($this->table, $field); } /** - * Test that assertDataValidationNotRequired passes when the field is empty. + * Test that assertValidationNotRequired passes when the field is empty. * * @return void - * @covers ::assertDataValidationNotRequired + * @covers ::assertValidationNotRequired */ - public function testAssertDataValidationNotRequired(): void + public function testAssertValidationNotRequired(): void { // Ensure data validation of the field works as expected first $field = 'empty_field'; $dataSet = []; - $this->assertDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertValidationNoErrors($this->table, $field, $dataSet); - $this->assertDataValidationNotRequired($this->table, $field); + $this->assertValidationNotRequired($this->table, $field); } /** - * Test that assertDataValidationBoolean passes when the field is boolean. + * Test that assertValidationBoolean passes when the field is boolean. * * @return void - * @covers ::assertDataValidationBoolean + * @covers ::assertValidationBoolean */ - public function testAssertDataValidationBoolean(): void + public function testAssertValidationBoolean(): void { // Ensure data validation of the field works as expected first $field = 'boolean_field'; $expectedErrors = ['boolean' => 'The provided value must be a boolean']; $dataSet = [$field => 'Not a boolean']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationBoolean($this->table, $field); + $this->assertValidationBoolean($this->table, $field); } /** - * Test that assertDataValidationURLWithProtocol passes when the field is url. + * Test that assertValidationURLWithProtocol passes when the field is url. * * @return void - * @covers ::assertDataValidationURLWithProtocol + * @covers ::assertValidationURLWithProtocol */ - public function testAssertDataValidationURLWithProtocol(): void + public function testAssertValidationURLWithProtocol(): void { // Ensure data validation of the field works as expected first $field = 'url_field'; $expectedErrors = ['urlWithProtocol' => 'The provided value must be a URL with protocol']; $dataSet = [$field => 'no-protocol.com']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationURLWithProtocol($this->table, $field); + $this->assertValidationURLWithProtocol($this->table, $field); } /** - * Test that assertDataValidationDateTime passes when the field is datetime. + * Test that assertValidationDateTime passes when the field is datetime. * * @return void - * @covers ::assertDataValidationDateTime + * @covers ::assertValidationDateTime */ - public function testAssertDataValidationDateTime(): void + public function testAssertValidationDateTime(): void { // Ensure data validation of the field works as expected first $field = 'datetime_field'; $expectedErrors = ['dateTime' => 'The provided value must be a date and time of one of these formats: `ymd`']; $dataSet = [$field => 'Not a date/time']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationDateTime($this->table, $field); + $this->assertValidationDateTime($this->table, $field); } /** - * Test that assertDataValidationDate passes when the field is date. + * Test that assertValidationDate passes when the field is date. * * @return void - * @covers ::assertDataValidationDate + * @covers ::assertValidationDate */ - public function testAssertDataValidationDate(): void + public function testAssertValidationDate(): void { // Ensure data validation of the field works as expected first $field = 'date_field'; $expectedErrors = ['date' => 'The provided value must be a date of one of these formats: `ymd`']; $dataSet = [$field => 'Not a date']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationDate($this->table, $field); + $this->assertValidationDate($this->table, $field); } /** - * Test that assertDataValidationInList passes when the field is datetime. + * Test that assertValidationInList passes when the field is datetime. * * @return void - * @covers ::assertDataValidationInList + * @covers ::assertValidationInList */ - public function testAssertDataValidationInList(): void + public function testAssertValidationInList(): void { // Ensure data validation of the field works as expected first $field = 'datetime_field'; $expectedErrors = ['dateTime' => 'The provided value must be a date and time of one of these formats: `ymd`']; $invalidValues = ['Not a date/time', '123']; - $this->assertDataValidationInList($this->table, $invalidValues, $field, $expectedErrors); + $this->assertValidationInList($this->table, $invalidValues, $field, $expectedErrors); $validValues = ['1900-01-01 00:00:00', '2022-10-12 11:50:32']; - $this->assertDataValidationInList($this->table, $validValues, $field); + $this->assertValidationInList($this->table, $validValues, $field); } /** - * Test that assertDataValidationMaxLength passes when the value is less than the max length. + * Test that assertValidationMaxLength passes when the value is less than the max length. * * @return void - * @covers ::assertDataValidationMaxLength + * @covers ::assertValidationMaxLength */ - public function testAssertDataValidationMaxLength(): void + public function testAssertValidationMaxLength(): void { // Ensure data validation of the field works as expected first $maxLength = 10; $field = 'max_length_field'; $expectedErrors = ['maxLength' => 'The provided value must be at most `10` characters long']; $dataSet = [$field => str_repeat('A', $maxLength + 1)]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationMaxLength($this->table, $field, $maxLength); + $this->assertValidationMaxLength($this->table, $field, $maxLength); } /** - * Test that assertDataValidationMinLength passes when the value is greater than the min length. + * Test that assertValidationMinLength passes when the value is greater than the min length. * * @return void - * @covers ::assertDataValidationMinLength + * @covers ::assertValidationMinLength */ - public function testAssertDataValidationMinLength(): void + public function testAssertValidationMinLength(): void { // Ensure data validation of the field works as expected first $minLength = 5; $field = 'min_length_field'; $expectedErrors = ['minLength' => 'The provided value must be at least `5` characters long']; $dataSet = [$field => str_repeat('A', $minLength - 1)]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationMinLength($this->table, $field, $minLength); + $this->assertValidationMinLength($this->table, $field, $minLength); } /** - * Test that assertDataValidationScalar passes when the field is scalar. + * Test that assertValidationScalar passes when the field is scalar. * * @return void - * @covers ::assertDataValidationScalar + * @covers ::assertValidationScalar */ - public function testAssertDataValidationScalar(): void + public function testAssertValidationScalar(): void { // Ensure data validation of the field works as expected first $field = 'scalar_field'; $entity = $this->table->newEntity([$field => []]); static::assertArrayHasKey('scalar', $entity->getError($field)); - $this->assertDataValidationScalar($this->table, $field); + $this->assertValidationScalar($this->table, $field); } /** - * Test that assertDataValidationDecimal passes when the field is decimal. + * Test that assertValidationDecimal passes when the field is decimal. * * @return void - * @covers ::assertDataValidationDecimal + * @covers ::assertValidationDecimal */ - public function testAssertDataValidationDecimal(): void + public function testAssertValidationDecimal(): void { // Ensure data validation of the field works as expected first $field = 'decimal_field'; $expectedErrors = ['decimal' => 'The provided value must be decimal with any number of decimal places, including none']; $dataSet = [$field => 'not a decimal']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationDecimal($this->table, $field); + $this->assertValidationDecimal($this->table, $field); } /** - * Test that assertDataValidationInteger passes when the field is integer. + * Test that assertValidationInteger passes when the field is integer. * * @return void - * @covers ::assertDataValidationInteger + * @covers ::assertValidationInteger */ - public function testAssertDataValidationInteger(): void + public function testAssertValidationInteger(): void { // Ensure data validation of the field works as expected first $field = 'integer_field'; $expectedErrors = ['integer' => 'The provided value must be an integer']; $dataSet = [$field => 'not a integer']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationInteger($this->table, $field); + $this->assertValidationInteger($this->table, $field); } /** - * Test that assertDataValidationNonNegativeInteger passes when the field is a non-negative integer. + * Test that assertValidationNonNegativeInteger passes when the field is a non-negative integer. * * @return void - * @covers ::assertDataValidationNonNegativeInteger + * @covers ::assertValidationNonNegativeInteger */ - public function testAssertDataValidationNonNegativeInteger(): void + public function testAssertValidationNonNegativeInteger(): void { // Ensure data validation of the field works as expected first $field = 'non_negative_integer_field'; $expectedErrors = ['nonNegativeInteger' => 'The provided value must be a non-negative integer']; $dataSet = [$field => 'not a integer']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationNonNegativeInteger($this->table, $field); + $this->assertValidationNonNegativeInteger($this->table, $field); } /** - * Test that assertDataValidationGreaterThanOrEqual passes when the field value + * Test that assertValidationGreaterThanOrEqual passes when the field value * is greater than or equal to the configured threshold. * * @return void - * @covers ::assertDataValidationGreaterThanOrEqual + * @covers ::assertValidationGreaterThanOrEqual */ - public function testAssertDataValidationGreaterThanOrEqual(): void + public function testAssertValidationGreaterThanOrEqual(): void { // Ensure data validation of the field works as expected first $threshold = 10; @@ -358,26 +358,26 @@ public function testAssertDataValidationGreaterThanOrEqual(): void // Just below the threshold should fail $dataSet = [$field => $threshold - 1]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); // At the threshold should pass $dataSet = [$field => $threshold]; - $this->assertDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertValidationNoErrors($this->table, $field, $dataSet); // Above the threshold should pass $dataSet = [$field => $threshold + 1]; - $this->assertDataValidationNoErrors($this->table, $field, $dataSet); + $this->assertValidationNoErrors($this->table, $field, $dataSet); - $this->assertDataValidationGreaterThanOrEqual($this->table, $field, $threshold); + $this->assertValidationGreaterThanOrEqual($this->table, $field, $threshold); } /** - * Test that assertDataValidationEmail passes when the field is a valid email. + * Test that assertValidationEmail passes when the field is a valid email. * * @return void - * @covers ::assertDataValidationEmail + * @covers ::assertValidationEmail */ - public function testAssertDataValidationEmail(): void + public function testAssertValidationEmail(): void { // Ensure data validation of the field works as expected first $field = 'email_field'; @@ -385,18 +385,18 @@ public function testAssertDataValidationEmail(): void 'email' => 'The provided value must be an e-mail address', ]; $dataSet = [$field => 'Not an email']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationEmail($this->table, $field); + $this->assertValidationEmail($this->table, $field); } /** - * Test that assertDataValidationUuid passes when the field is a valid uuid. + * Test that assertValidationUuid passes when the field is a valid uuid. * * @return void - * @covers ::assertDataValidationUuid + * @covers ::assertValidationUuid */ - public function testAssertDataValidationUuid(): void + public function testAssertValidationUuid(): void { // Ensure data validation of the field works as expected first $field = 'uuid_field'; @@ -404,18 +404,18 @@ public function testAssertDataValidationUuid(): void 'uuid' => 'The provided value must be a UUID', ]; $dataSet = [$field => 'Not a uuid']; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationUuid($this->table, $field); + $this->assertValidationUuid($this->table, $field); } /** - * Test that assertDataValidationLengthBetween passes when the field is between the min and max length. + * Test that assertValidationLengthBetween passes when the field is between the min and max length. * * @return void - * @covers ::assertDataValidationLengthBetween + * @covers ::assertValidationLengthBetween */ - public function testAssertDataValidationLengthBetween(): void + public function testAssertValidationLengthBetween(): void { // Ensure data validation of the field works as expected first $minLength = 5; @@ -423,20 +423,20 @@ public function testAssertDataValidationLengthBetween(): void $field = 'length_between_field'; $expectedErrors = ['lengthBetween' => 'The length of the provided value must be between `5` and `10`, inclusively']; $dataSet = [$field => str_repeat('A', $minLength - 1)]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); $dataSet = [$field => str_repeat('A', $maxLength + 1)]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationLengthBetween($this->table, $field, $minLength, $maxLength); + $this->assertValidationLengthBetween($this->table, $field, $minLength, $maxLength); } /** - * Test that assertDataValidationRange passes when the field is between the lower and upper bound. + * Test that assertValidationRange passes when the field is between the lower and upper bound. * * @return void - * @covers ::assertDataValidationRange + * @covers ::assertValidationRange */ - public function testAssertDataValidationRange(): void + public function testAssertValidationRange(): void { // Ensure data validation of the field works as expected first $lowerBound = -30.0; @@ -445,50 +445,50 @@ public function testAssertDataValidationRange(): void $expectedErrors = ['range' => 'The provided value must be between `-30` and `30`, inclusively']; $dataSet = [$field => $lowerBound - 1]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); $dataSet = [$field => $upperBound + 1]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationRange($this->table, $field, $lowerBound, $upperBound); + $this->assertValidationRange($this->table, $field, $lowerBound, $upperBound); } /** - * Test that assertDataValidationNaturalNumber passes when the field is a natural number. + * Test that assertValidationNaturalNumber passes when the field is a natural number. * * @return void - * @covers ::assertDataValidationNaturalNumber + * @covers ::assertValidationNaturalNumber */ - public function testAssertDataValidationNaturalNumber(): void + public function testAssertValidationNaturalNumber(): void { // Ensure data validation of the field works as expected first $field = 'natural_number_field'; $expectedErrors = ['naturalNumber' => 'The provided value must be a natural number']; $dataSet = [$field => -1]; - $this->assertDataValidation($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidation($this->table, $field, $dataSet, $expectedErrors); - $this->assertDataValidationNaturalNumber($this->table, $field); + $this->assertValidationNaturalNumber($this->table, $field); } /** - * Test that testFullDataValidationNoErrors passes when the full data set has no errors. + * Test that assertFullDataValidationNoErrors passes when the full data set has no errors. * * @return void - * @covers ::testFullDataValidationNoErrors + * @covers ::assertFullDataValidationNoErrors */ - public function testTestFullDataValidationNoErrors(): void + public function testAssertFullDataValidationNoErrors(): void { $dataSet = ['required_field' => 'required', 'multi_rule_field' => 1]; $this->assertFullDataValidationNoErrors($this->table, $dataSet); } /** - * Test that testFullDataValidation reports all errors. + * Test that assertFullDataValidation reports all errors. * * @return void - * @covers ::testFullDataValidation + * @covers ::assertFullDataValidation */ - public function testTestFullDataValidation(): void + public function testAssertFullDataValidation(): void { $dataSet = ['not_empty_field' => '', 'multi_rule_field' => 1]; $expectedErrors = [ @@ -499,12 +499,12 @@ public function testTestFullDataValidation(): void } /** - * Test that testDataRules passes when saving leads to the expected rule errors. + * Test that assertDataRules passes when saving leads to the expected rule errors. * * @return void - * @covers ::testDataRules + * @covers ::assertDataRules */ - public function testTestDataRules(): void + public function testAssertDataRules(): void { $field = 'unique_field'; $dataSet = [$field => 'duplicate']; @@ -522,12 +522,12 @@ public function testTestDataRules(): void } /** - * Test that testDataRulesNoErrors passes when saving leads to no rule errors. + * Test that assertRulesNoErrors passes when saving leads to no rule errors. * * @return void - * @covers ::testDataRulesNoErrors + * @covers ::assertRulesNoErrors */ - public function testTestDataRulesNoErrors(): void + public function testAssertRulesNoErrors(): void { // Ensure the rule works as expected first $field = 'unique_field'; @@ -537,16 +537,16 @@ public function testTestDataRulesNoErrors(): void static::assertNotFalse($this->table->save($entity)); static::assertEmpty($entity->getError($field)); - $this->assertDataRulesNoErrors($this->table, $field, [$field => 'another-unique-' . uniqid('', true)]); + $this->assertRulesNoErrors($this->table, $field, [$field => 'another-unique-' . uniqid('', true)]); } /** - * Test that assertDataValidationForeignKey passes when the foreign key does not exist. + * Test that assertValidationForeignKey passes when the foreign key does not exist. * * @return void - * @covers ::assertDataValidationForeignKey + * @covers ::assertValidationForeignKey */ - public function testAssertDataValidationForeignKey(): void + public function testAssertValidationForeignKey(): void { // Ensure the rule works as expected first $field = 'parent_id'; @@ -557,42 +557,42 @@ public function testAssertDataValidationForeignKey(): void static::assertFalse($this->table->checkRules($entity)); static::assertSame($expectedErrors, $entity->getError($field)); - $this->assertDataValidationForeignKey($this->table, $field, $notExistingForeignKey); + $this->assertValidationForeignKey($this->table, $field, $notExistingForeignKey); } /** - * Test that assertDataValidationForeignKey passes with the default not existing foreign key. + * Test that assertValidationForeignKey passes with the default not existing foreign key. * * @return void - * @covers ::assertDataValidationForeignKey + * @covers ::assertValidationForeignKey */ - public function testAssertDataValidationForeignKeyDefault(): void + public function testAssertValidationForeignKeyDefault(): void { $field = 'parent_id'; - $this->assertDataValidationForeignKey($this->table, $field); + $this->assertValidationForeignKey($this->table, $field); } /** - * Test that assertDataValidationForeignKey accepts a custom expected error. + * Test that assertValidationForeignKey accepts a custom expected error. * * @return void - * @covers ::assertDataValidationForeignKey + * @covers ::assertValidationForeignKey */ - public function testAssertDataValidationForeignKeyCustomExpected(): void + public function testAssertValidationForeignKeyCustomExpected(): void { $field = 'parent_id'; $expectedErrors = ['_existsIn' => 'This value does not exist']; - $this->assertDataValidationForeignKey($this->table, $field, 999999, $expectedErrors); + $this->assertValidationForeignKey($this->table, $field, 999999, $expectedErrors); } /** - * Test that assertDataValidationIsUnique passes when the field value is not unique. + * Test that assertValidationIsUnique passes when the field value is not unique. * * @return void - * @covers ::assertDataValidationIsUnique + * @covers ::assertValidationIsUnique */ - public function testAssertDataValidationIsUnique(): void + public function testAssertValidationIsUnique(): void { // Ensure the rule works as expected first $field = 'unique_field'; @@ -612,16 +612,16 @@ public function testAssertDataValidationIsUnique(): void // Use a different value since the trait method will also save a record $this->table->deleteAll([]); - $this->assertDataValidationIsUnique($this->table, $field, 'another-duplicate-value', $dataset); + $this->assertValidationIsUnique($this->table, $field, 'another-duplicate-value', $dataset); } /** - * Test that assertDataValidationIsUnique accepts a custom expected error. + * Test that assertValidationIsUnique accepts a custom expected error. * * @return void - * @covers ::assertDataValidationIsUnique + * @covers ::assertValidationIsUnique */ - public function testAssertDataValidationIsUniqueCustomExpected(): void + public function testAssertValidationIsUniqueCustomExpected(): void { $field = 'unique_field'; $dataset = [ @@ -630,16 +630,16 @@ public function testAssertDataValidationIsUniqueCustomExpected(): void ]; $expectedErrors = ['_isUnique' => 'This value is already in use']; - $this->assertDataValidationIsUnique($this->table, $field, 'custom-duplicate-value', $dataset, $expectedErrors); + $this->assertValidationIsUnique($this->table, $field, 'custom-duplicate-value', $dataset, $expectedErrors); } /** - * Test that testRules passes when saving leads to the expected rule errors. + * Test that assertRules passes when saving leads to the expected rule errors. * * @return void - * @covers ::testRules + * @covers ::assertRules */ - public function testTestRules(): void + public function testAssertRules(): void { $field = 'unique_field'; $dataSet = ['required_field' => 'required', $field => 'duplicate', 'multi_rule_field' => 1]; @@ -659,12 +659,12 @@ public function testTestRules(): void } /** - * Test the assertDataValidationContains base method. + * Test the assertValidationContains base method. * * @return void - * @covers ::assertDataValidationContains + * @covers ::assertValidationContains */ - public function testAssertDataValidationContains(): void + public function testAssertValidationContains(): void { // An invalid scalar value must produce a `scalar` error $field = 'scalar_field'; @@ -673,61 +673,61 @@ public function testAssertDataValidationContains(): void $entity = $this->table->newEntity($dataSet); static::assertArrayHasKey('scalar', $entity->getError($field)); - $this->assertDataValidationContains($this->table, $field, $dataSet, $expectedErrors); + $this->assertValidationContains($this->table, $field, $dataSet, $expectedErrors); } /** - * Test the assertDataValidationNotContains base method. + * Test the assertValidationNotContains base method. * * @return void - * @covers ::assertDataValidationNotContains + * @covers ::assertValidationNotContains */ - public function testAssertDataValidationNotContains(): void + public function testAssertValidationNotContains(): void { // A valid boolean value must not produce a `boolean` error $field = 'boolean_field'; $entity = $this->table->newEntity([$field => true]); static::assertArrayNotHasKey('boolean', $entity->getError($field)); - $this->assertDataValidationNotContains($this->table, $field, [$field => true], ['boolean']); + $this->assertValidationNotContains($this->table, $field, [$field => true], ['boolean']); } /** - * Test the assertDataValidationListContains base method. + * Test the assertValidationListContains base method. * * @return void - * @covers ::assertDataValidationListContains + * @covers ::assertValidationListContains */ - public function testAssertDataValidationListContains(): void + public function testAssertValidationListContains(): void { $field = 'boolean_field'; $expectedErrors = ['boolean' => 'The provided value must be a boolean']; $invalidValues = ['Not a boolean', 123]; - $this->assertDataValidationListContains($this->table, $invalidValues, $field, $expectedErrors); + $this->assertValidationListContains($this->table, $invalidValues, $field, $expectedErrors); } /** - * Test the assertDataValidationListNotContains base method. + * Test the assertValidationListNotContains base method. * * @return void - * @covers ::assertDataValidationListNotContains + * @covers ::assertValidationListNotContains */ - public function testAssertDataValidationListNotContains(): void + public function testAssertValidationListNotContains(): void { $field = 'boolean_field'; $validValues = [true, false, 1, 0]; - $this->assertDataValidationListNotContains($this->table, $validValues, $field, ['boolean']); + $this->assertValidationListNotContains($this->table, $validValues, $field, ['boolean']); } /** - * Test the assertDataValidationErrorsContain base method. + * Test the assertValidationErrorsContain base method. * * @return void - * @covers ::assertDataValidationErrorsContain + * @covers ::assertValidationErrorsContain */ - public function testAssertDataValidationErrorsContain(): void + public function testAssertValidationErrorsContain(): void { $field = 'boolean_field'; // The errors contain the expected rule alongside an unrelated one, which must be ignored @@ -737,14 +737,14 @@ public function testAssertDataValidationErrorsContain(): void ]; $expected = ['boolean' => 'The provided value must be a boolean']; - $this->assertDataValidationErrorsContain($field, $errors, $expected); + $this->assertValidationErrorsContain($field, $errors, $expected); } /** * Test that a type-specific method only asserts its own rule and ignores unrelated errors. * * @return void - * @covers ::assertDataValidationInteger + * @covers ::assertValidationInteger */ public function testTypeSpecificMethodIgnoresUnrelatedErrors(): void { @@ -757,6 +757,6 @@ public function testTypeSpecificMethodIgnoresUnrelatedErrors(): void static::assertArrayHasKey('maxLength', $errors); // The type-specific method still passes because it checks for the `integer` rule, only - $this->assertDataValidationInteger($this->table, $field); + $this->assertValidationInteger($this->table, $field); } } From 95e5476508b1db0123833e8d05d4955db84cb33a Mon Sep 17 00:00:00 2001 From: Fabian Arndt Date: Tue, 22 Sep 2026 14:38:24 +0200 Subject: [PATCH 04/14] Update CHANGELOG.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marc Würth --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index befa05c..e9cb095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Optional custom `$expected` parameter for `testDataValidationForeignKey()` and `testDataValidationIsUnique()`. ### Changed -- **BREAKING CHANGE:** Replace `testData` prefix in all test trait method names with `assert`. +- **BREAKING CHANGE:** Replace `testData` prefix in all test trait method names with `assert`. E.g. `testDataValidationNotEmpty()` becomes `assertValidationNotEmpty()`. - **BREAKING CHANGE:** All type-specific/rule-dedicated methods now assert only their own validation rule for the field, ignoring others. ### Fixed From 414431bcc1d07de33a33deddd78aa1bcc3f94c84 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Tue, 22 Sep 2026 14:40:33 +0200 Subject: [PATCH 05/14] Update usage guideline --- docs/Usage.md | 80 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/docs/Usage.md b/docs/Usage.md index 35ed2d9..8a0ce9b 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -34,20 +34,20 @@ All helper methods are `protected` and callable from within your test class. ## Example ```php -public function testValidationTitle(): void +public function assertValidationTitle(): void { // Assert that the "title" field's presence is required - $this->testDataValidationRequired($this->Articles, 'title'); + $this->assertValidationRequired($this->Articles, 'title'); // Assert that the field "title" cannot be empty - $this->testDataValidationNotEmpty($this->Articles, 'title'); + $this->assertValidationNotEmpty($this->Articles, 'title'); // Assert that the "title" field's maximum length is 255 characters - $this->testDataValidationMaxLength($this->Articles, 'title', 255); + $this->assertValidationMaxLength($this->Articles, 'title', 255); } -public function testValidationIsPublished(): void +public function assertValidationIsPublished(): void { // Assert that the field "is_published" must have a boolean value - $this->testDataValidationBoolean($this->Articles, 'is_published'); + $this->assertValidationBoolean($this->Articles, 'is_published'); } ``` @@ -61,42 +61,42 @@ Each helper builds an entity, runs the validator, and asserts the expected error ### Presence and emptiness -- `testDataValidationRequired($table, $fieldName)` - asserts the field is configured to require presence (`_required`). -- `testDataValidationNotRequired($table, $fieldName)` - asserts the field is not configured to require presence. -- `testDataValidationNotEmpty($table, $fieldName)` - asserts the field is configured to disallow empty values, i.e. `null` or `''` (`_empty`). -- `testDataValidationEmpty($table, $fieldName)` - asserts the field is configured to allow empty values, i.e. `null` or `''`. +- `assertValidationRequired($table, $fieldName)` - asserts the field is configured to require presence (`_required`). +- `assertValidationNotRequired($table, $fieldName)` - asserts the field is not configured to require presence. +- `assertValidationNotEmpty($table, $fieldName)` - asserts the field is configured to disallow empty values, i.e. `null` or `''` (`_empty`). +- `assertValidationEmpty($table, $fieldName)` - asserts the field is configured to allow empty values, i.e. `null` or `''`. ### Type validators -- `testDataValidationBoolean($table, $fieldName)` - asserts the field is configured with the `boolean` validation rule. -- `testDataValidationURLWithProtocol($table, $fieldName)` - asserts the field is configured with the `urlWithProtocol` validation rule (requires `http://` or `https://`). -- `testDataValidationDateTime($table, $fieldName)` - asserts the field is configured with the `dateTime` validation rule. -- `testDataValidationDate($table, $fieldName)` - asserts the field is configured with the `date` validation rule. -- `testDataValidationNaturalNumber($table, $fieldName)` - asserts the field is configured with the `naturalNumber` validation rule (positive integers). -- `testDataValidationScalar($table, $fieldName)` - asserts the field is configured with the `scalar` validation rule. -- `testDataValidationDecimal($table, $fieldName)` - asserts the field is configured with the `decimal` validation rule. -- `testDataValidationInteger($table, $fieldName)` - asserts the field is configured with the `integer` validation rule. -- `testDataValidationNonNegativeInteger($table, $fieldName)` - asserts the field is configured with the `nonNegativeInteger` validation rule. -- `testDataValidationGreaterThanOrEqual($table, $fieldName, $threshold)` - asserts the field is configured with the `greaterThanOrEqual` validation rule. -- `testDataValidationEmail($table, $fieldName)` - asserts the field is configured with the `email` validation rule. -- `testDataValidationUuid($table, $fieldName)` - asserts the field is configured with the `uuid` validation rule. +- `assertValidationBoolean($table, $fieldName)` - asserts the field is configured with the `boolean` validation rule. +- `assertValidationURLWithProtocol($table, $fieldName)` - asserts the field is configured with the `urlWithProtocol` validation rule (requires `http://` or `https://`). +- `assertValidationDateTime($table, $fieldName)` - asserts the field is configured with the `dateTime` validation rule. +- `assertValidationDate($table, $fieldName)` - asserts the field is configured with the `date` validation rule. +- `assertValidationNaturalNumber($table, $fieldName)` - asserts the field is configured with the `naturalNumber` validation rule (positive integers). +- `assertValidationScalar($table, $fieldName)` - asserts the field is configured with the `scalar` validation rule. +- `assertValidationDecimal($table, $fieldName)` - asserts the field is configured with the `decimal` validation rule. +- `assertValidationInteger($table, $fieldName)` - asserts the field is configured with the `integer` validation rule. +- `assertValidationNonNegativeInteger($table, $fieldName)` - asserts the field is configured with the `nonNegativeInteger` validation rule. +- `assertValidationGreaterThanOrEqual($table, $fieldName, $threshold)` - asserts the field is configured with the `greaterThanOrEqual` validation rule. +- `assertValidationEmail($table, $fieldName)` - asserts the field is configured with the `email` validation rule. +- `assertValidationUuid($table, $fieldName)` - asserts the field is configured with the `uuid` validation rule. ### Length validators -- `testDataValidationMaxLength($table, $fieldName, $maxLength)` -- `testDataValidationMinLength($table, $fieldName, $minLength, $expected)` -- `testDataValidationLengthBetween($table, $fieldName, $minLength, $maxLength)` -- `testDataValidationRange($table, $fieldName, $lowerBound, $upperBound)` +- `assertValidationMaxLength($table, $fieldName, $maxLength)` +- `assertValidationMinLength($table, $fieldName, $minLength, $expected)` +- `assertValidationLengthBetween($table, $fieldName, $minLength, $maxLength)` +- `assertValidationRange($table, $fieldName, $lowerBound, $upperBound)` ### Generic helpers -- `testDataValidation($table, $fieldName, $dataSet, $expected)` - the underlying helper. Use when no specialized helper fits. Compares the field's **complete** error array against `$expected`. -- `testDataValidationContains($table, $fieldName, $dataSet, $expected)` - asserts the given `"rule name" => "message"` pairs are present on the field, ignoring any other errors. -- `testDataValidationNotContains($table, $fieldName, $dataSet, $rules)` - asserts the given rule names are **not** present on the field, ignoring any other errors. -- `testDataValidationNoErrors($table, $fieldName, $dataSet)` - asserts a data set produces no errors on the field. -- `testDataValidationInList($table, $list, $fieldName, $expected)` - runs the complete-error-array assertion for each value in a list. -- `testDataValidationInListContains($table, $list, $fieldName, $expected)` - runs the `contains` assertion for each value in a list. -- `testDataValidationInListNotContains($table, $list, $fieldName, $rules)` - runs the `not contains` assertion for each value in a list. +- `assertValidation($table, $fieldName, $dataSet, $expected)` - the underlying helper. Use when no specialized helper fits. Compares the field's **complete** error array against `$expected`. +- `assertValidationContains($table, $fieldName, $dataSet, $expected)` - asserts the given `"rule name" => "message"` pairs are present on the field, ignoring any other errors. +- `assertValidationNotContains($table, $fieldName, $dataSet, $rules)` - asserts the given rule names are **not** present on the field, ignoring any other errors. +- `assertValidationNoErrors($table, $fieldName, $dataSet)` - asserts a data set produces no errors on the field. +- `assertValidationInList($table, $list, $fieldName, $expected)` - runs the complete-error-array assertion for each value in a list. +- `assertValidationInListContains($table, $list, $fieldName, $expected)` - runs the `contains` assertion for each value in a list. +- `assertValidationInListNotContains($table, $list, $fieldName, $rules)` - runs the `not contains` assertion for each value in a list. - `testFullDataValidation($table, $dataSet, $expected)` - asserts errors across all fields. - `testFullDataValidationNoErrors($table, $dataSet)` - asserts a full data set produces no errors at all. @@ -104,18 +104,18 @@ Each helper builds an entity, runs the validator, and asserts the expected error For application rules that run at save time (not marshalling time). These require a real database connection and fixtures. -- `testDataRules($table, $fieldName, $dataSet, $expected)` -- `testDataRulesNoErrors($table, $fieldName, $dataSet)` -- `testRules($table, $fieldName, $dataSet, $expected)` -- `testDataValidationUnique($table, $fieldName, $fieldValue)` -- `testDataValidationForeignKey($table, $fieldName)` +- `assertDataRules($table, $fieldName, $dataSet, $expected)` +- `assertRulesNoErrors($table, $fieldName, $dataSet)` +- `assertRules($table, $fieldName, $dataSet, $expected)` +- `assertValidationUnique($table, $fieldName, $fieldValue)` +- `assertValidationForeignKey($table, $fieldName)` ## Dependent fields Use the `$additionalDataSet` parameter to supply required companion fields so your test only fails for the reason you care about: ```php -$this->testDataValidationNotEmpty( +$this->assertValidationNotEmpty( $this->Articles, 'title', ['author_id' => 1] @@ -127,7 +127,7 @@ $this->testDataValidationNotEmpty( The `$options` parameter is forwarded to `Table::newEntity()`: ```php -$this->testDataValidationRequired( +$this->assertValidationRequired( $this->Articles, 'title', [], From 36cbc1958296f134be3141f9e54e78589bd50d44 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Tue, 22 Sep 2026 14:42:12 +0200 Subject: [PATCH 06/14] Adjust method names in unreleased changelog section --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cb095..b62dcff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,16 +6,16 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased](https://github.com/orca-services/cakephp-data-validation-testing) ### Added -- `testDataValidationNotContains()` to assert that specific validation rules are absent, ignoring others on the same field. -- `testDataValidationListContains()` and `testDataValidationListNotContains()` list helpers. -- Optional custom `$expected` parameter for `testDataValidationForeignKey()` and `testDataValidationIsUnique()`. +- `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()`. ### Changed - **BREAKING CHANGE:** Replace `testData` prefix in all test trait method names with `assert`. E.g. `testDataValidationNotEmpty()` becomes `assertValidationNotEmpty()`. - **BREAKING CHANGE:** All type-specific/rule-dedicated methods now assert only their own validation rule for the field, ignoring others. ### Fixed -- Ignore data validation in `testDataValidationIsUnique()` to correctly assert build rules. +- Ignore data validation in `assertValidationIsUnique()` to correctly assert build rules. ### Dependencies From 86b1c933334a6f423678f42e466fd199f8d62513 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Wed, 23 Sep 2026 08:34:04 +0200 Subject: [PATCH 07/14] Add migration guide --- docs/Migration.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/Migration.md diff --git a/docs/Migration.md b/docs/Migration.md new file mode 100644 index 0000000..44c9256 --- /dev/null +++ b/docs/Migration.md @@ -0,0 +1,61 @@ +# Upgrading CakePHP Data Validation Testing to 3.x + +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)) + +--- + +## 1. Method renames + +All `test`/`testData`-prefixed methods on `DataValidationTestTrait` are now prefixed with `assert` instead. +This avoids PHPUnit mistaking them for actual test methods. **No logic changed** only the method names. + +### Rename table + +| Old | New | +|---|---| +| `testDataValidationNotEmpty()` | `assertValidationNotEmpty()` | +| `testDataValidationEmpty()` | `assertValidationEmpty()` | +| `testDataValidationRequired()` | `assertValidationRequired()` | +| `testDataValidationNotRequired()` | `assertValidationNotRequired()` | +| `testDataValidationBoolean()` | `assertValidationBoolean()` | +| `testDataValidationURLWithProtocol()` | `assertValidationURLWithProtocol()` | +| `testDataValidationDateTime()` | `assertValidationDateTime()` | +| `testDataValidationDate()` | `assertValidationDate()` | +| `testDataValidationInList()` | `assertValidationInList()` | +| `testDataValidationNoErrors()` | `assertValidationNoErrors()` | +| `testFullDataValidationNoErrors()` | `assertFullDataValidationNoErrors()` | +| `testDataValidation()` | `assertValidation()` | +| `testDataValidationContains()` | `assertValidationContains()` | +| `testDataValidationNotContains()` | `assertValidationNotContains()` | +| `assertDataValidationErrorsContain()` | `assertValidationErrorsContain()` | +| `testDataValidationListContains()` | `assertValidationListContains()` | +| `testDataValidationListNotContains()` | `assertValidationListNotContains()` | +| `testDataRules()` | `assertDataRules()` | +| `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()` | +| `testFullDataValidation()` | `assertFullDataValidation()` | +| `testDataValidationForeignKey()` | `assertValidationForeignKey()` | +| `testDataValidationIsUnique()` | `assertValidationIsUnique()` | + +--- + +## 2. Rule-dedicated methods now check only their own rule + +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. From 971a8adc3ce7306268a736cfad387b6cd6d7b01d Mon Sep 17 00:00:00 2001 From: Neluxx Date: Fri, 25 Sep 2026 07:24:34 +0200 Subject: [PATCH 08/14] Rename FullDataValidation methods --- docs/Migration.md | 4 ++-- docs/Usage.md | 4 ++-- src/Traits/DataValidationTestTrait.php | 6 +++--- .../Traits/DataValidationTestTraitTest.php | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/Migration.md b/docs/Migration.md index 44c9256..8ba91b2 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -26,7 +26,7 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationDate()` | `assertValidationDate()` | | `testDataValidationInList()` | `assertValidationInList()` | | `testDataValidationNoErrors()` | `assertValidationNoErrors()` | -| `testFullDataValidationNoErrors()` | `assertFullDataValidationNoErrors()` | +| `testFullDataValidationNoErrors()` | `assertValidationTableNoErrors()` | | `testDataValidation()` | `assertValidation()` | | `testDataValidationContains()` | `assertValidationContains()` | | `testDataValidationNotContains()` | `assertValidationNotContains()` | @@ -48,7 +48,7 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationLengthBetween()` | `assertValidationLengthBetween()` | | `testDataValidationRange()` | `assertValidationRange()` | | `testDataValidationNaturalNumber()` | `assertValidationNaturalNumber()` | -| `testFullDataValidation()` | `assertFullDataValidation()` | +| `testFullDataValidation()` | `assertValidationTableErrors()` | | `testDataValidationForeignKey()` | `assertValidationForeignKey()` | | `testDataValidationIsUnique()` | `assertValidationIsUnique()` | diff --git a/docs/Usage.md b/docs/Usage.md index 8a0ce9b..5eb1494 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -97,8 +97,8 @@ Each helper builds an entity, runs the validator, and asserts the expected error - `assertValidationInList($table, $list, $fieldName, $expected)` - runs the complete-error-array assertion for each value in a list. - `assertValidationInListContains($table, $list, $fieldName, $expected)` - runs the `contains` assertion for each value in a list. - `assertValidationInListNotContains($table, $list, $fieldName, $rules)` - runs the `not contains` assertion for each value in a list. -- `testFullDataValidation($table, $dataSet, $expected)` - asserts errors across all fields. -- `testFullDataValidationNoErrors($table, $dataSet)` - asserts a full data set produces no errors at all. +- `assertValidationTableErrors($table, $dataSet, $expected)` - asserts errors across all fields. +- `assertValidationTableNoErrors($table, $dataSet)` - asserts a full data set produces no errors at all. ### Rules helpers diff --git a/src/Traits/DataValidationTestTrait.php b/src/Traits/DataValidationTestTrait.php index 7de875b..3f02f6a 100644 --- a/src/Traits/DataValidationTestTrait.php +++ b/src/Traits/DataValidationTestTrait.php @@ -335,10 +335,10 @@ protected function assertValidationNoErrors( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function assertFullDataValidationNoErrors(Table $table, array $dataSet, array $options = []): void + protected function assertValidationTableNoErrors(Table $table, array $dataSet, array $options = []): void { $expected = []; - $this->assertFullDataValidation($table, $dataSet, $expected, $options); + $this->assertValidationTableErrors($table, $dataSet, $expected, $options); } /** @@ -1046,7 +1046,7 @@ protected function assertValidationNaturalNumber( * @return void * @see \Cake\Validation\Validator::validate() */ - protected function assertFullDataValidation( + protected function assertValidationTableErrors( Table $table, array $dataSet, array $expected, diff --git a/tests/TestCase/Traits/DataValidationTestTraitTest.php b/tests/TestCase/Traits/DataValidationTestTraitTest.php index b510415..a297ba2 100644 --- a/tests/TestCase/Traits/DataValidationTestTraitTest.php +++ b/tests/TestCase/Traits/DataValidationTestTraitTest.php @@ -471,31 +471,31 @@ public function testAssertValidationNaturalNumber(): void } /** - * Test that assertFullDataValidationNoErrors passes when the full data set has no errors. + * Test that assertValidationTableNoErrors passes when the full data set has no errors. * * @return void - * @covers ::assertFullDataValidationNoErrors + * @covers ::assertValidationTableNoErrors */ - public function testAssertFullDataValidationNoErrors(): void + public function testAssertValidationTableNoErrors(): void { $dataSet = ['required_field' => 'required', 'multi_rule_field' => 1]; - $this->assertFullDataValidationNoErrors($this->table, $dataSet); + $this->assertValidationTableNoErrors($this->table, $dataSet); } /** - * Test that assertFullDataValidation reports all errors. + * Test that assertValidationTableErrors reports all errors. * * @return void - * @covers ::assertFullDataValidation + * @covers ::assertValidationTableErrors */ - public function testAssertFullDataValidation(): void + public function testAssertValidationTableErrors(): void { $dataSet = ['not_empty_field' => '', 'multi_rule_field' => 1]; $expectedErrors = [ 'not_empty_field' => ['_empty' => 'This field cannot be left empty'], 'required_field' => ['_required' => 'This field is required'], ]; - $this->assertFullDataValidation($this->table, $dataSet, $expectedErrors); + $this->assertValidationTableErrors($this->table, $dataSet, $expectedErrors); } /** From bfae933f93782eb9d8b4fb9be80368302ebc6a82 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Fri, 25 Sep 2026 07:28:47 +0200 Subject: [PATCH 09/14] Remove old assertRules method and rename assertDataRules to assertRules --- docs/Migration.md | 4 +-- docs/Usage.md | 1 - src/Traits/DataValidationTestTrait.php | 28 +--------------- .../Traits/DataValidationTestTraitTest.php | 33 +++---------------- 4 files changed, 7 insertions(+), 59 deletions(-) diff --git a/docs/Migration.md b/docs/Migration.md index 8ba91b2..9640066 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -33,8 +33,8 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `assertDataValidationErrorsContain()` | `assertValidationErrorsContain()` | | `testDataValidationListContains()` | `assertValidationListContains()` | | `testDataValidationListNotContains()` | `assertValidationListNotContains()` | -| `testDataRules()` | `assertDataRules()` | -| `testRules()` | `assertRules()` | +| `testDataRules()` | `assertRules()` | +| `testRules()` | Removed | | `testDataRulesNoErrors()` | `assertRulesNoErrors()` | | `testDataValidationMaxLength()` | `assertValidationMaxLength()` | | `testDataValidationMinLength()` | `assertValidationMinLength()` | diff --git a/docs/Usage.md b/docs/Usage.md index 5eb1494..1f27fbb 100644 --- a/docs/Usage.md +++ b/docs/Usage.md @@ -104,7 +104,6 @@ Each helper builds an entity, runs the validator, and asserts the expected error For application rules that run at save time (not marshalling time). These require a real database connection and fixtures. -- `assertDataRules($table, $fieldName, $dataSet, $expected)` - `assertRulesNoErrors($table, $fieldName, $dataSet)` - `assertRules($table, $fieldName, $dataSet, $expected)` - `assertValidationUnique($table, $fieldName, $fieldValue)` diff --git a/src/Traits/DataValidationTestTrait.php b/src/Traits/DataValidationTestTrait.php index 3f02f6a..08ff66c 100644 --- a/src/Traits/DataValidationTestTrait.php +++ b/src/Traits/DataValidationTestTrait.php @@ -525,7 +525,7 @@ protected function assertValidationListNotContains( * @return void * @todo Move to a rules dedicated helper class. */ - protected function assertDataRules( + protected function assertRules( Table $table, string $fieldName, array $dataSet, @@ -543,32 +543,6 @@ protected function assertDataRules( static::assertEquals($expected, $errors); } - /** - * Validate that a given data set for a given table leads to the expected table rules errors - * - * @param Table $table The table to test. - * @param string $fieldName The field to check for table rules errors. - * @param array $dataSet The data set to test. - * @param array $expected The expected table rules errors. - * @param array $options Additional options for newEntity. - * @return void - */ - protected function assertRules( - Table $table, - string $fieldName, - array $dataSet, - array $expected, - array $options = [], - ): void { - $entity = $table->newEntity($dataSet, $options); - $errors = $entity->getError($fieldName); - static::assertEmpty($errors); - - $table->save($entity); - $errors = $entity->getError($fieldName); - static::assertEquals($expected, $errors); - } - /** * Validate that a given data set for a given table does not lead to data rules errors * diff --git a/tests/TestCase/Traits/DataValidationTestTraitTest.php b/tests/TestCase/Traits/DataValidationTestTraitTest.php index a297ba2..be959a7 100644 --- a/tests/TestCase/Traits/DataValidationTestTraitTest.php +++ b/tests/TestCase/Traits/DataValidationTestTraitTest.php @@ -499,12 +499,12 @@ public function testAssertValidationTableErrors(): void } /** - * Test that assertDataRules passes when saving leads to the expected rule errors. + * Test that assertRules passes when saving leads to the expected rule errors. * * @return void - * @covers ::assertDataRules + * @covers ::assertRules */ - public function testAssertDataRules(): void + public function testAssertRules(): void { $field = 'unique_field'; $dataSet = [$field => 'duplicate']; @@ -518,7 +518,7 @@ public function testAssertDataRules(): void static::assertFalse($this->table->save($duplicate)); static::assertSame($expectedErrors, $duplicate->getError($field)); - $this->assertDataRules($this->table, $field, $dataSet, $expectedErrors); + $this->assertRules($this->table, $field, $dataSet, $expectedErrors); } /** @@ -633,31 +633,6 @@ public function testAssertValidationIsUniqueCustomExpected(): void $this->assertValidationIsUnique($this->table, $field, 'custom-duplicate-value', $dataset, $expectedErrors); } - /** - * Test that assertRules passes when saving leads to the expected rule errors. - * - * @return void - * @covers ::assertRules - */ - public function testAssertRules(): void - { - $field = 'unique_field'; - $dataSet = ['required_field' => 'required', $field => 'duplicate', 'multi_rule_field' => 1]; - $expectedErrors = ['_isUnique' => 'This value is already in use']; - - // Ensure a first record exists so the unique rule will fail on the second - $existing = $this->table->newEntity($dataSet); - static::assertNotFalse($this->table->save($existing)); - - // Ensure the rule works as expected first - $duplicate = $this->table->newEntity($dataSet); - static::assertEmpty($duplicate->getError($field)); - static::assertFalse($this->table->save($duplicate)); - static::assertSame($expectedErrors, $duplicate->getError($field)); - - $this->assertRules($this->table, $field, $dataSet, $expectedErrors); - } - /** * Test the assertValidationContains base method. * From 8e5e35f3e1c0faca9a9678335fe42c8eb1a99945 Mon Sep 17 00:00:00 2001 From: "marc.wuerth" Date: Fri, 25 Sep 2026 15:58:37 +0200 Subject: [PATCH 10/14] Formatting --- docs/Migration.md | 70 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/docs/Migration.md b/docs/Migration.md index 9640066..4a12848 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -14,43 +14,43 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** ### Rename table -| Old | New | -|---|---| -| `testDataValidationNotEmpty()` | `assertValidationNotEmpty()` | -| `testDataValidationEmpty()` | `assertValidationEmpty()` | -| `testDataValidationRequired()` | `assertValidationRequired()` | -| `testDataValidationNotRequired()` | `assertValidationNotRequired()` | -| `testDataValidationBoolean()` | `assertValidationBoolean()` | -| `testDataValidationURLWithProtocol()` | `assertValidationURLWithProtocol()` | -| `testDataValidationDateTime()` | `assertValidationDateTime()` | -| `testDataValidationDate()` | `assertValidationDate()` | -| `testDataValidationInList()` | `assertValidationInList()` | -| `testDataValidationNoErrors()` | `assertValidationNoErrors()` | -| `testFullDataValidationNoErrors()` | `assertValidationTableNoErrors()` | -| `testDataValidation()` | `assertValidation()` | -| `testDataValidationContains()` | `assertValidationContains()` | -| `testDataValidationNotContains()` | `assertValidationNotContains()` | -| `assertDataValidationErrorsContain()` | `assertValidationErrorsContain()` | -| `testDataValidationListContains()` | `assertValidationListContains()` | -| `testDataValidationListNotContains()` | `assertValidationListNotContains()` | -| `testDataRules()` | `assertRules()` | -| `testRules()` | Removed | -| `testDataRulesNoErrors()` | `assertRulesNoErrors()` | -| `testDataValidationMaxLength()` | `assertValidationMaxLength()` | -| `testDataValidationMinLength()` | `assertValidationMinLength()` | -| `testDataValidationScalar()` | `assertValidationScalar()` | -| `testDataValidationDecimal()` | `assertValidationDecimal()` | -| `testDataValidationInteger()` | `assertValidationInteger()` | +| Old | New | +|------------------------------------------|----------------------------------------| +| `testDataValidationNotEmpty()` | `assertValidationNotEmpty()` | +| `testDataValidationEmpty()` | `assertValidationEmpty()` | +| `testDataValidationRequired()` | `assertValidationRequired()` | +| `testDataValidationNotRequired()` | `assertValidationNotRequired()` | +| `testDataValidationBoolean()` | `assertValidationBoolean()` | +| `testDataValidationURLWithProtocol()` | `assertValidationURLWithProtocol()` | +| `testDataValidationDateTime()` | `assertValidationDateTime()` | +| `testDataValidationDate()` | `assertValidationDate()` | +| `testDataValidationInList()` | `assertValidationInList()` | +| `testDataValidationNoErrors()` | `assertValidationNoErrors()` | +| `testFullDataValidationNoErrors()` | `assertValidationTableNoErrors()` | +| `testDataValidation()` | `assertValidation()` | +| `testDataValidationContains()` | `assertValidationContains()` | +| `testDataValidationNotContains()` | `assertValidationNotContains()` | +| `assertDataValidationErrorsContain()` | `assertValidationErrorsContain()` | +| `testDataValidationListContains()` | `assertValidationListContains()` | +| `testDataValidationListNotContains()` | `assertValidationListNotContains()` | +| `testDataRules()` | `assertRules()` | +| `testRules()` | Removed | +| `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()` | -| `testFullDataValidation()` | `assertValidationTableErrors()` | -| `testDataValidationForeignKey()` | `assertValidationForeignKey()` | -| `testDataValidationIsUnique()` | `assertValidationIsUnique()` | +| `testDataValidationEmail()` | `assertValidationEmail()` | +| `testDataValidationUuid()` | `assertValidationUuid()` | +| `testDataValidationLengthBetween()` | `assertValidationLengthBetween()` | +| `testDataValidationRange()` | `assertValidationRange()` | +| `testDataValidationNaturalNumber()` | `assertValidationNaturalNumber()` | +| `testFullDataValidation()` | `assertValidationTableErrors()` | +| `testDataValidationForeignKey()` | `assertValidationForeignKey()` | +| `testDataValidationIsUnique()` | `assertValidationIsUnique()` | --- From b4e51689acffb62d11ac293fe9b12b5ab669409d Mon Sep 17 00:00:00 2001 From: Neluxx Date: Mon, 28 Sep 2026 12:46:06 +0200 Subject: [PATCH 11/14] Group similar methods together --- docs/Migration.md | 4 +-- src/Traits/DataValidationTestTrait.php | 44 +++++++++++++------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/Migration.md b/docs/Migration.md index 4a12848..f37d86c 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -25,9 +25,10 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationDateTime()` | `assertValidationDateTime()` | | `testDataValidationDate()` | `assertValidationDate()` | | `testDataValidationInList()` | `assertValidationInList()` | +| `testDataValidation()` | `assertValidation()` | | `testDataValidationNoErrors()` | `assertValidationNoErrors()` | +| `testFullDataValidation()` | `assertValidationTableErrors()` | | `testFullDataValidationNoErrors()` | `assertValidationTableNoErrors()` | -| `testDataValidation()` | `assertValidation()` | | `testDataValidationContains()` | `assertValidationContains()` | | `testDataValidationNotContains()` | `assertValidationNotContains()` | | `assertDataValidationErrorsContain()` | `assertValidationErrorsContain()` | @@ -48,7 +49,6 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationLengthBetween()` | `assertValidationLengthBetween()` | | `testDataValidationRange()` | `assertValidationRange()` | | `testDataValidationNaturalNumber()` | `assertValidationNaturalNumber()` | -| `testFullDataValidation()` | `assertValidationTableErrors()` | | `testDataValidationForeignKey()` | `assertValidationForeignKey()` | | `testDataValidationIsUnique()` | `assertValidationIsUnique()` | diff --git a/src/Traits/DataValidationTestTrait.php b/src/Traits/DataValidationTestTrait.php index 08ff66c..f06ce04 100644 --- a/src/Traits/DataValidationTestTrait.php +++ b/src/Traits/DataValidationTestTrait.php @@ -326,6 +326,28 @@ protected function assertValidationNoErrors( $this->assertValidation($table, $fieldName, $dataSet, $expected, $options); } + /** + * Validate that a given data set for a given table leads to the expected errors + * + * @param Table $table The table to test. + * @param array $dataSet The data set to test. + * @param array $expected The expected errors. + * @param array $options Additional options for newEntity. + * @return void + * @see \Cake\Validation\Validator::validate() + */ + protected function assertValidationTableErrors( + Table $table, + array $dataSet, + array $expected, + array $options = [], + ): void { + $entity = $table->newEntity($dataSet, $options); + $errors = $entity->getErrors(); + + static::assertEquals($expected, $errors); + } + /** * Validate that a given data set for a given table does not lead to data validation errors on any field * @@ -1010,28 +1032,6 @@ protected function assertValidationNaturalNumber( ); } - /** - * Validate that a given data set for a given table leads to the expected errors - * - * @param Table $table The table to test. - * @param array $dataSet The data set to test. - * @param array $expected The expected errors. - * @param array $options Additional options for newEntity. - * @return void - * @see \Cake\Validation\Validator::validate() - */ - protected function assertValidationTableErrors( - Table $table, - array $dataSet, - array $expected, - array $options = [], - ): void { - $entity = $table->newEntity($dataSet, $options); - $errors = $entity->getErrors(); - - static::assertEquals($expected, $errors); - } - /** * Validate the present foreign key to another table * From 85ee6d6e5555d708730db349fda5625af9b41da6 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Mon, 28 Sep 2026 12:46:24 +0200 Subject: [PATCH 12/14] Add replacement for removed method --- docs/Migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Migration.md b/docs/Migration.md index f37d86c..66c2294 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -35,7 +35,7 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationListContains()` | `assertValidationListContains()` | | `testDataValidationListNotContains()` | `assertValidationListNotContains()` | | `testDataRules()` | `assertRules()` | -| `testRules()` | Removed | +| `testRules()` | Removed use `assertRules()` instead | | `testDataRulesNoErrors()` | `assertRulesNoErrors()` | | `testDataValidationMaxLength()` | `assertValidationMaxLength()` | | `testDataValidationMinLength()` | `assertValidationMinLength()` | From ff45dd4d6cc1f8b2140d1e8d70d0b2e7f6006827 Mon Sep 17 00:00:00 2001 From: Neluxx Date: Mon, 28 Sep 2026 12:46:47 +0200 Subject: [PATCH 13/14] Update change log --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b62dcff..3188f41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Optional custom `$expected` parameter for `assertValidationForeignKey()` and `assertValidationIsUnique()`. ### Changed -- **BREAKING CHANGE:** Replace `testData` prefix in all test trait method names with `assert`. E.g. `testDataValidationNotEmpty()` becomes `assertValidationNotEmpty()`. +- **BREAKING CHANGE:** Replace `testDataValidation` prefix in all test trait method names with `assertValidation`. E.g. `testDataValidationNotEmpty()` becomes `assertValidationNotEmpty()`. - **BREAKING CHANGE:** All type-specific/rule-dedicated methods now assert only their own validation rule for the field, ignoring others. ### Fixed From fae9029aa9b924c99735396456710d1abe10c800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Mon, 28 Sep 2026 12:51:53 +0200 Subject: [PATCH 14/14] Wording --- docs/Migration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Migration.md b/docs/Migration.md index 66c2294..548cf47 100644 --- a/docs/Migration.md +++ b/docs/Migration.md @@ -35,7 +35,7 @@ This avoids PHPUnit mistaking them for actual test methods. **No logic changed** | `testDataValidationListContains()` | `assertValidationListContains()` | | `testDataValidationListNotContains()` | `assertValidationListNotContains()` | | `testDataRules()` | `assertRules()` | -| `testRules()` | Removed use `assertRules()` instead | +| `testRules()` | Removed. Use `assertRules()` instead | | `testDataRulesNoErrors()` | `assertRulesNoErrors()` | | `testDataValidationMaxLength()` | `assertValidationMaxLength()` | | `testDataValidationMinLength()` | `assertValidationMinLength()` |