Skip to content

Commit

Permalink
Migrate tests for PHPUnit 10 compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <george@net-glue.co.uk>
  • Loading branch information
gsteel committed May 24, 2023
1 parent b818cf0 commit 1bb377c
Show file tree
Hide file tree
Showing 21 changed files with 607 additions and 361 deletions.
116 changes: 84 additions & 32 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@
<code>setInputFilter</code>
</PossiblyUnusedMethod>
</file>
<file src="src/InputFilterAwareTrait.php">
<InvalidNullableReturnType>
<code>InputFilterInterface</code>
</InvalidNullableReturnType>
</file>
<file src="src/InputFilterInterface.php">
<PossiblyUnusedReturnValue>
<code>InputFilterInterface</code>
Expand Down Expand Up @@ -432,12 +437,16 @@
</RedundantCondition>
</file>
<file src="test/BaseInputFilterTest.php">
<DeprecatedMethod>
<code>enableProxyingToOriginalMethods</code>
<code>enableProxyingToOriginalMethods</code>
</DeprecatedMethod>
<InvalidArgument>
<code><![CDATA[['nested' => ['nested-input1', 'nested-input2']]]]></code>
</InvalidArgument>
<InvalidDocblock>
<code>public function addMethodArgumentsProvider(): array</code>
</InvalidDocblock>
<LessSpecificReturnStatement>
<code>$dataSets</code>
</LessSpecificReturnStatement>
<MissingClosureParamType>
<code>$inputTypeData</code>
<code>$inputTypeData</code>
Expand All @@ -453,6 +462,7 @@
<code>$set[6]</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$getMessages</code>
<code>$msg</code>
<code>$msg</code>
<code>$name</code>
Expand Down Expand Up @@ -480,14 +490,6 @@
<code>$tmpTemplate[2]</code>
<code>$tmpTemplate[3]</code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[<string, array{
* 0: InputInterface,
* 1: null|string,
* 2: null|string,
* 3: MockObject&InputInterface
* }>]]></code>
</MixedInferredReturnType>
<MixedReturnTypeCoercion>
<code>$dataSets</code>
<code><![CDATA[array<string, array{
Expand All @@ -501,6 +503,14 @@
* 7: string[]
* }>]]></code>
</MixedReturnTypeCoercion>
<MoreSpecificReturnType>
<code><![CDATA[array<string, array{
* 0: InputInterface,
* 1: null|string,
* 2: null|string,
* 3: InputInterface,
* }>]]></code>
</MoreSpecificReturnType>
<PossiblyInvalidArgument>
<code>$input</code>
<code>$input</code>
Expand All @@ -518,11 +528,56 @@
<code>getName</code>
<code>isRequired</code>
</PossiblyUndefinedMethod>
<PossiblyUnusedMethod>
<code>addMethodArgumentsProvider</code>
<code>contextProvider</code>
<code>setDataArgumentsProvider</code>
<code>unknownScenariosProvider</code>
</PossiblyUnusedMethod>
<PossiblyUnusedParam>
<code>$context</code>
<code>$inputName</code>
</PossiblyUnusedParam>
</file>
<file src="test/CollectionInputFilterTest.php">
<InvalidArgument>
<code>$errorMessage</code>
</InvalidArgument>
<InvalidReturnStatement>
<code><![CDATA[[
// Description => [$required, $count, $data, $inputFilter, $expectedRaw, $expectedValues, $expectedValid, $expectedMessages]
'Required: T, Count: N, Valid: T' => [ $isRequired, null, $colRaw, $validIF() , $colRaw, $colFiltered, true , []],
'Required: T, Count: N, Valid: F' => [ $isRequired, null, $colRaw, $invalidIF(), $colRaw, $colFiltered, false, $colMessages],
'Required: T, Count: +1, Valid: F' => [ $isRequired, 2, $colRaw, $invalidIF(), $colRaw, $colFiltered, false, $colMessages],
'Required: F, Count: N, Valid: T' => [! $isRequired, null, $colRaw, $validIF() , $colRaw, $colFiltered, true , []],
'Required: F, Count: N, Valid: F' => [! $isRequired, null, $colRaw, $invalidIF(), $colRaw, $colFiltered, false, $colMessages],
'Required: F, Count: +1, Valid: F' => [! $isRequired, 2, $colRaw, $invalidIF(), $colRaw, $colFiltered, false, $colMessages],
'Required: T, Data: [], Valid: X' => [ $isRequired, null, [] , $noValidIF(), [] , [] , false, [['isEmpty' => 'Value is required and can\'t be empty']]],
'Required: F, Data: [], Valid: X' => [! $isRequired, null, [] , $noValidIF(), [] , [] , true , []],
]]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code><![CDATA[array<string, array{
* 0: bool,
* 1: null|int,
* 2: array,
* 3: BaseInputFilter&MockObject,
* 4: array,
* 5: array,
* 6: bool,
* 7: array
* }>]]></code>
</InvalidReturnType>
<PossiblyUnusedMethod>
<code>contextProvider</code>
<code>countVsDataProvider</code>
<code>dataNestingCollection</code>
<code>dataVsValidProvider</code>
<code>inputFilterProvider</code>
<code>invalidCollections</code>
<code>invalidDataType</code>
<code>isRequiredProvider</code>
</PossiblyUnusedMethod>
</file>
<file src="test/FactoryTest.php">
<PossiblyNullReference>
<code>getPluginManager</code>
Expand All @@ -532,6 +587,9 @@
<code>breakOnFailure</code>
<code>breakOnFailure</code>
</PossiblyUndefinedMethod>
<PossiblyUnusedMethod>
<code>inputTypeSpecificationProvider</code>
</PossiblyUnusedMethod>
<UndefinedInterfaceMethod>
<code>continueIfEmpty</code>
</UndefinedInterfaceMethod>
Expand Down Expand Up @@ -595,23 +653,16 @@
<code>$generator instanceof Generator</code>
</TypeDoesNotContainType>
</file>
<file src="test/InputFilterAwareTraitTest.php">
<InvalidArgument>
<code>InputFilterAwareTrait::class</code>
<code>InputFilterAwareTrait::class</code>
</InvalidArgument>
<MixedMethodCall>
<code>getInputFilter</code>
<code>getInputFilter</code>
<code>setInputFilter</code>
<code>setInputFilter</code>
</MixedMethodCall>
</file>
<file src="test/InputFilterPluginManagerCompatibilityTest.php">
<InvalidReturnType>
<code>getInstanceOf</code>
</InvalidReturnType>
</file>
<file src="test/InputFilterPluginManagerFactoryTest.php">
<PossiblyUnusedMethod>
<code>pluginProvider</code>
</PossiblyUnusedMethod>
</file>
<file src="test/InputFilterPluginManagerTest.php">
<LessSpecificReturnStatement>
<code><![CDATA[[
Expand All @@ -627,6 +678,10 @@
* 2: class-string<InputInterface>
* }>]]></code>
</MoreSpecificReturnType>
<PossiblyUnusedMethod>
<code>defaultInvokableClassesProvider</code>
<code>serviceProvider</code>
</PossiblyUnusedMethod>
</file>
<file src="test/InputFilterTest.php">
<ImplementedReturnTypeMismatch>
Expand Down Expand Up @@ -716,14 +771,6 @@
<LessSpecificReturnStatement>
<code>array_merge($emptyValues, $mixedValues)</code>
</LessSpecificReturnStatement>
<MissingClosureParamType>
<code>$context</code>
<code>$context</code>
<code>$context</code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
</MissingClosureParamType>
<MixedArrayAccess>
<code><![CDATA[$value['filtered']]]></code>
<code><![CDATA[$value['raw']]]></code>
Expand Down Expand Up @@ -768,4 +815,9 @@
<code>addServiceManager</code>
</PossiblyUnusedMethod>
</file>
<file src="test/ValidationGroup/InputFilterCollectionsValidationGroupTest.php">
<PossiblyUnusedMethod>
<code>collectionCountProvider</code>
</PossiblyUnusedMethod>
</file>
</files>
2 changes: 1 addition & 1 deletion src/InputFilterAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

trait InputFilterAwareTrait
{
/** @var InputFilterInterface */
/** @var InputFilterInterface|null */
protected $inputFilter;

/**
Expand Down
26 changes: 11 additions & 15 deletions test/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use Laminas\Filter\FilterChain;
use Laminas\InputFilter\ArrayInput;
use Laminas\InputFilter\Exception\InvalidArgumentException;
use Laminas\Validator\NotEmpty;
use Laminas\Validator\NotEmpty as NotEmptyValidator;
use Laminas\Validator\ValidatorChain;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\MockObject\MockObject;
use Webmozart\Assert\Assert;

Expand All @@ -18,9 +19,7 @@
use function current;
use function is_array;

/**
* @covers \Laminas\InputFilter\ArrayInput
*/
#[CoversClass(ArrayInput::class)]
class ArrayInputTest extends InputTest
{
protected function setUp(): void
Expand Down Expand Up @@ -76,7 +75,7 @@ public function testSetValueWithInvalidInputTypeThrowsInvalidArgumentException()
* 4: string[]
* }>
*/
public function fallbackValueVsIsValidProvider(): array
public static function fallbackValueVsIsValidProvider(): array
{
$dataSets = parent::fallbackValueVsIsValidProvider();
Assert::isArray($dataSets);
Expand All @@ -95,7 +94,7 @@ public function fallbackValueVsIsValidProvider(): array
* filtered: null|string|array
* }>
*/
public function emptyValueProvider(): iterable
public static function emptyValueProvider(): iterable
{
$dataSets = parent::emptyValueProvider();
Assert::isArray($dataSets);
Expand All @@ -112,7 +111,7 @@ public function emptyValueProvider(): iterable
* filtered: bool|int|float|string|list<string>|object
* }>
*/
public function mixedValueProvider(): array
public static function mixedValueProvider(): array
{
$dataSets = parent::mixedValueProvider();
Assert::isArray($dataSets);
Expand Down Expand Up @@ -167,14 +166,11 @@ static function ($values) {
return parent::createValidatorChainMock($valueMap, $messages);
}

/**
* @param bool $isValid
* @param mixed $value
* @param mixed $context
* @return NotEmpty&MockObject
*/
protected function createNonEmptyValidatorMock($isValid, $value, $context = null)
{
protected function createNonEmptyValidatorMock(
bool $isValid,
mixed $value,
mixed $context = null,
): NotEmptyValidator&MockObject {
// ArrayInput validates per each array value
if (is_array($value)) {
$value = current($value);
Expand Down
Loading

0 comments on commit 1bb377c

Please sign in to comment.