Skip to content

Commit

Permalink
Fix deprecations in PHPUnit 10.5.18
Browse files Browse the repository at this point in the history
PHPUnit 11 will require that test method arguments match the array keys provided in the data provider, and, that all arguments listed in the data provider are present in the test method.

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Apr 15, 2024
1 parent cc20c47 commit fefbd17
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 60 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"require-dev": {
"ext-json": "*",
"laminas/laminas-coding-standard": "~2.5.0",
"phpunit/phpunit": "^10.5.15",
"phpunit/phpunit": "^10.5.18",
"psalm/plugin-phpunit": "^0.19.0",
"psr/http-message": "^2.0",
"vimeo/psalm": "^5.23.1",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@
<code><![CDATA[setDataArgumentsProvider]]></code>
<code><![CDATA[unknownScenariosProvider]]></code>
</PossiblyUnusedMethod>
<PossiblyUnusedParam>
<code><![CDATA[$inputName]]></code>
</PossiblyUnusedParam>
</file>
<file src="test/CollectionInputFilterTest.php">
<InvalidArgument>
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<directory name="test/StaticAnalysis" />
</errorLevel>
</PossiblyUnusedMethod>
<PossiblyUnusedParam>
<errorLevel type="suppress">
<directory name="test" />
</errorLevel>
</PossiblyUnusedParam>
</issueHandlers>

<stubs>
Expand Down
4 changes: 2 additions & 2 deletions test/CollectionInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static function dataNestingCollection(): array
}

#[DataProvider('dataNestingCollection')]
public function testNestingCollectionCountCached(?int $count, bool $expectedIsValid): void
public function testNestingCollectionCountCached(?int $count, bool $isValid): void
{
$firstInputFilter = new InputFilter();

Expand Down Expand Up @@ -291,7 +291,7 @@ public function testNestingCollectionCountCached(?int $count, bool $expectedIsVa
];

$mainInputFilter->setData($data);
self::assertSame($expectedIsValid, $mainInputFilter->isValid());
self::assertSame($isValid, $mainInputFilter->isValid());
}

/**
Expand Down
9 changes: 5 additions & 4 deletions test/FileInput/HttpServerFileInputDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Laminas\Validator;
use LaminasTest\InputFilter\InputTest;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Webmozart\Assert\Assert;

use function json_encode;
Expand Down Expand Up @@ -214,14 +215,14 @@ public function testValidationsRunWithoutFileArrayIsSend(): void
self::assertFalse($this->input->isValid());
}

/** @param mixed $value */
public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null): void
#[DataProvider('emptyValueProvider')]
public function testNotEmptyValidatorAddedWhenIsValidIsCalled(mixed $raw, mixed $filtered): void
{
self::markTestSkipped('Test is not enabled in FileInputTest');
}

/** @param mixed $value */
public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null): void
#[DataProvider('emptyValueProvider')]
public function testRequiredNotEmptyValidatorNotAddedWhenOneExists(mixed $raw, mixed $filtered): void
{
self::markTestSkipped('Test is not enabled in FileInputTest');
}
Expand Down
9 changes: 5 additions & 4 deletions test/FileInput/PsrFileInputDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use LaminasTest\InputFilter\InputTest;
use LaminasTest\InputFilter\TestAsset\UploadedFileInterfaceStub;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Http\Message\UploadedFileInterface;

use function in_array;
Expand Down Expand Up @@ -215,14 +216,14 @@ public function testRequiredUploadValidatorValidatorNotAddedWhenOneExists(): voi
self::assertEquals($validator, $validators[0]['instance']);
}

/** @param mixed $value */
public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value = null): void
#[DataProvider('emptyValueProvider')]
public function testNotEmptyValidatorAddedWhenIsValidIsCalled(mixed $raw, mixed $filtered): void
{
self::markTestSkipped('Test is not enabled in PsrFileInputTest');
}

/** @param mixed $value */
public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value = null): void
#[DataProvider('emptyValueProvider')]
public function testRequiredNotEmptyValidatorNotAddedWhenOneExists(mixed $raw, mixed $filtered): void
{
self::markTestSkipped('Test is not enabled in PsrFileInputTest');
}
Expand Down
65 changes: 20 additions & 45 deletions test/InputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,23 @@ public function testContinueIfEmptyFlagIsMutable(): void
self::assertTrue($input->continueIfEmpty());
}

/**
* @param mixed $fallbackValue
*/
#[DataProvider('setValueProvider')]
public function testSetFallbackValue($fallbackValue): void
public function testSetFallbackValue(mixed $raw, mixed $filtered): void
{
$input = $this->input;

$return = $input->setFallbackValue($fallbackValue);
$return = $input->setFallbackValue($raw);
self::assertSame($input, $return, 'setFallbackValue() must return it self');

self::assertEquals($fallbackValue, $input->getFallbackValue(), 'getFallbackValue() value not match');
self::assertEquals($raw, $input->getFallbackValue(), 'getFallbackValue() value not match');
self::assertTrue($input->hasFallback(), 'hasFallback() value not match');
}

/**
* @param mixed $fallbackValue
*/
#[DataProvider('setValueProvider')]
public function testClearFallbackValue($fallbackValue): void
public function testClearFallbackValue(mixed $raw, mixed $filtered): void
{
$input = $this->input;
$input->setFallbackValue($fallbackValue);
$input->setFallbackValue($raw);
$input->clearFallbackValue();
self::assertNull($input->getFallbackValue(), 'getFallbackValue() value not match');
self::assertFalse($input->hasFallback(), 'hasFallback() value not match');
Expand Down Expand Up @@ -322,15 +316,12 @@ public function testNotRequiredWithoutFallbackAndValueNotSetThenIsValid(): void
self::assertEquals([], $input->getMessages(), 'getMessages() should be empty because the input is valid');
}

/**
* @param mixed $value
*/
#[DataProvider('emptyValueProvider')]
public function testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue($value): void
public function testNotEmptyValidatorNotInjectedIfContinueIfEmptyIsTrue(mixed $raw, mixed $filtered): void
{
$input = $this->input;
$input->setContinueIfEmpty(true);
$input->setValue($value);
$input->setValue($raw);
$input->isValid();
$validators = $input->getValidatorChain()
->getValidators();
Expand Down Expand Up @@ -406,14 +397,11 @@ public function testBreakOnFailureFlagIsMutable(): void
self::assertTrue($this->input->breakOnFailure());
}

/**
* @param mixed $value
*/
#[DataProvider('emptyValueProvider')]
public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value): void
public function testNotEmptyValidatorAddedWhenIsValidIsCalled(mixed $raw, mixed $filtered): void
{
self::assertTrue($this->input->isRequired());
$this->input->setValue($value);
$this->input->setValue($raw);
$validatorChain = $this->input->getValidatorChain();
self::assertEquals(0, count($validatorChain->getValidators()));

Expand All @@ -427,16 +415,13 @@ public function testNotEmptyValidatorAddedWhenIsValidIsCalled($value): void
self::assertEquals(1, count($validatorChain->getValidators()));
}

/**
* @param mixed $value
*/
#[DataProvider('emptyValueProvider')]
public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value): void
public function testRequiredNotEmptyValidatorNotAddedWhenOneExists(mixed $raw, mixed $filtered): void
{
$this->input->setRequired(true);
$this->input->setValue($value);
$this->input->setValue($raw);

$notEmptyMock = $this->createNonEmptyValidatorMock(false, $value);
$notEmptyMock = $this->createNonEmptyValidatorMock(false, $raw);

$validatorChain = $this->input->getValidatorChain();
$validatorChain->prependValidator($notEmptyMock);
Expand All @@ -447,21 +432,17 @@ public function testRequiredNotEmptyValidatorNotAddedWhenOneExists($value): void
self::assertEquals($notEmptyMock, $validators[0]['instance']);
}

/**
* @param mixed $valueRaw
* @param mixed $valueFiltered
*/
#[DataProvider('emptyValueProvider')]
public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain($valueRaw, $valueFiltered): void
public function testDoNotInjectNotEmptyValidatorIfAnywhereInChain(mixed $raw, mixed $filtered): void
{
$filterChain = $this->createFilterChainMock([[$valueRaw, $valueFiltered]]);
$filterChain = $this->createFilterChainMock([[$raw, $filtered]]);
$validatorChain = $this->input->getValidatorChain();

$this->input->setRequired(true);
$this->input->setFilterChain($filterChain);
$this->input->setValue($valueRaw);
$this->input->setValue($raw);

$notEmptyMock = $this->createNonEmptyValidatorMock(false, $valueFiltered);
$notEmptyMock = $this->createNonEmptyValidatorMock(false, $filtered);

$validatorChain->attach(self::createValidatorMock(true));
$validatorChain->attach($notEmptyMock);
Expand Down Expand Up @@ -501,30 +482,24 @@ public function testIsRequiredVsAllowEmptyVsContinueIfEmptyVsIsValid(
self::assertEquals($value, $this->input->getValue(), 'getValue() must return the filtered value always');
}

/**
* @param mixed $value
*/
#[DataProvider('setValueProvider')]
public function testSetValuePutInputInTheDesiredState($value): void
public function testSetValuePutInputInTheDesiredState(mixed $raw, mixed $filtered): void
{
$input = $this->input;
self::assertFalse($input->hasValue(), 'Input should not have value by default');

$input->setValue($value);
$input->setValue($raw);
self::assertTrue($input->hasValue(), "hasValue() didn't return true when value was set");
}

/**
* @param mixed $value
*/
#[DataProvider('setValueProvider')]
public function testResetValueReturnsInputValueToDefaultValue($value): void
public function testResetValueReturnsInputValueToDefaultValue(mixed $raw, mixed $filtered): void
{
$input = $this->input;
$originalInput = clone $input;
self::assertFalse($input->hasValue(), 'Input should not have value by default');

$input->setValue($value);
$input->setValue($raw);
self::assertTrue($input->hasValue(), "hasValue() didn't return true when value was set");

$return = $input->resetValue();
Expand Down

0 comments on commit fefbd17

Please sign in to comment.