Skip to content

Commit

Permalink
Alters test to expect the PHP notice as documentation of existing beh…
Browse files Browse the repository at this point in the history
…aviour

Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Jul 25, 2022
1 parent 14e8d6e commit 73d7a19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
</NonInvariantDocblockPropertyType>
</file>
<file src="src/BaseInputFilter.php">
<DocblockTypeContradiction occurrences="1">
<code>! is_string($name)</code>
</DocblockTypeContradiction>
<InvalidPropertyAssignmentValue occurrences="1">
<code>$this-&gt;inputs</code>
</InvalidPropertyAssignmentValue>
Expand Down
1 change: 0 additions & 1 deletion src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use function is_array;
use function is_int;
use function is_object;
use function is_string;
use function sprintf;

class BaseInputFilter implements
Expand Down
17 changes: 15 additions & 2 deletions test/ValidationGroup/InputFilterCollectionsValidationGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Laminas\InputFilter\InputFilter;
use PHPUnit\Framework\TestCase;

use const PHP_VERSION_ID;

final class InputFilterCollectionsValidationGroupTest extends TestCase
{
private InputFilter $inputFilter;
Expand Down Expand Up @@ -127,6 +129,7 @@ public function testValidationGroupViaCollection(?int $count): void
$this->setCollectionCount($count);
$collection = $this->inputFilter->get('stuff');
self::assertInstanceOf(CollectionInputFilter::class, $collection);
/** @psalm-suppress InvalidArgument */
$collection->setValidationGroup([
0 => 'first',
1 => 'second',
Expand All @@ -147,7 +150,7 @@ public function testValidationGroupViaCollection(?int $count): void
}

/**
* This test fails because of an undefined offset - the validation group must be set for elements 0 through 3
* This test documents existing behaviour - the validation group must be set for elements 0 through 3
*
* @dataProvider collectionCountProvider
*/
Expand All @@ -157,6 +160,7 @@ public function testValidationGroupViaCollectionMustSpecifyAllKeys(?int $count):
$collection = $this->inputFilter->get('stuff');
self::assertInstanceOf(CollectionInputFilter::class, $collection);

/** @psalm-suppress InvalidArgument */
$collection->setValidationGroup([
0 => 'first',
]);
Expand All @@ -170,13 +174,22 @@ public function testValidationGroupViaCollectionMustSpecifyAllKeys(?int $count):
],
]);

self::assertTrue($this->inputFilter->isValid());
if (PHP_VERSION_ID >= 80000) {
$this->expectWarning();
$this->expectWarningMessage('Undefined array key 1');
} else {
$this->expectNotice();
$this->expectNoticeMessage('Undefined offset: 1');
}

$this->inputFilter->isValid();
}

/** @dataProvider collectionCountProvider */
public function testValidationGroupViaTopLevelInputFilter(?int $count): void
{
$this->setCollectionCount($count);
/** @psalm-suppress InvalidArgument */
$this->inputFilter->setValidationGroup([
'stuff' => [
0 => 'first',
Expand Down

0 comments on commit 73d7a19

Please sign in to comment.