Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some 8.2 compatibility issues in Date validator #149

Merged
merged 6 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 5 additions & 34 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.24.0@06dd975cb55d36af80f242561738f16c5f58264f">
<files psalm-version="4.26.0@6998fabb2bf528b65777bf9941920888d23c03ac">
gsteel marked this conversation as resolved.
Show resolved Hide resolved
<file src="bin/update_hostname_validator.php">
<MissingClosureParamType occurrences="2">
<code>$domain</code>
Expand Down Expand Up @@ -579,6 +579,9 @@
<PossiblyUndefinedVariable occurrences="1">
<code>$temp</code>
</PossiblyUndefinedVariable>
<TypeDoesNotContainType occurrences="1">
<code>$errors === false</code>
</TypeDoesNotContainType>
</file>
<file src="src/DateStep.php">
<ArgumentTypeCoercion occurrences="1">
Expand Down Expand Up @@ -1431,7 +1434,7 @@
</PossiblyNullArgument>
<RedundantConditionGivenDocblockType occurrences="3">
<code>$file !== null</code>
<code>is_array($files)</code>
<code>is_countable($files)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/File/UploadFile.php">
Expand Down Expand Up @@ -2045,9 +2048,6 @@
<code>[$this, 'errorHandlerIgnore']</code>
<code>[$this, 'errorHandlerIgnore']</code>
</InvalidArgument>
<InvalidScalarArgument occurrences="1">
<code>1</code>
</InvalidScalarArgument>
<MixedArgument occurrences="2">
<code>$message</code>
<code>$options</code>
Expand All @@ -2059,9 +2059,6 @@
<code>null</code>
<code>null</code>
</NullArgument>
<PossiblyNullArgument occurrences="1">
<code>var_export($messages, 1)</code>
</PossiblyNullArgument>
</file>
<file src="test/BarcodeTest.php">
<ArgumentTypeCoercion occurrences="1">
Expand Down Expand Up @@ -2167,9 +2164,6 @@
<code>'users'</code>
<code>'users'</code>
</InvalidArgument>
<UndefinedPropertyAssignment occurrences="1">
<code>$mockHasResultRow-&gt;one</code>
</UndefinedPropertyAssignment>
</file>
<file src="test/Db/RecordExistsTest.php">
<DeprecatedMethod occurrences="2">
Expand All @@ -2188,9 +2182,6 @@
<PossiblyNullReference occurrences="1">
<code>$parameters</code>
</PossiblyNullReference>
<UndefinedPropertyAssignment occurrences="1">
<code>$mockHasResultRow-&gt;one</code>
</UndefinedPropertyAssignment>
</file>
<file src="test/Db/TestAsset/ConcreteDbValidator.php">
<PropertyNotSetInConstructor occurrences="2">
Expand Down Expand Up @@ -2684,31 +2675,11 @@
<ArgumentTypeCoercion occurrences="1">
<code>$classOrInstance</code>
</ArgumentTypeCoercion>
<InvalidPropertyAssignmentValue occurrences="1"/>
<MixedArgument occurrences="2"/>
<MixedInferredReturnType occurrences="2">
<code>array</code>
<code>array</code>
</MixedInferredReturnType>
<MixedMethodCall occurrences="6">
<code>will</code>
<code>will</code>
<code>willReturn</code>
<code>willReturn</code>
<code>willReturnCallback</code>
<code>willReturnCallback</code>
</MixedMethodCall>
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>null</code>
</PossiblyNullPropertyAssignmentValue>
<UndefinedInterfaceMethod occurrences="6">
<code>method</code>
<code>method</code>
<code>method</code>
<code>method</code>
<code>method</code>
<code>method</code>
</UndefinedInterfaceMethod>
</file>
<file src="test/UriTest.php">
<InvalidArgument occurrences="4">
Expand Down
4 changes: 4 additions & 0 deletions src/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ protected function convertString($value, $addErrors = true)
// Invalid dates can show up as warnings (ie. "2007-02-99")
// and still return a DateTime object.
$errors = DateTime::getLastErrors();
if ($errors === false) {
return $date;
}

if ($errors['warning_count'] > 0) {
if ($addErrors) {
$this->error(self::FALSEFORMAT);
Expand Down
14 changes: 9 additions & 5 deletions test/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSetFormatIgnoresNull(): void
/**
* @return array[]
* @psalm-return array<array{
* 0: string|numeric|DateTime|object|array,
* 0: string|numeric|DateTime|object|array|null,
* 1: null|string,
* 2: bool,
* 3: bool
Expand Down Expand Up @@ -97,31 +97,35 @@ public function datesDataProvider(): array
[new DateTime(), null, true, false],
// invalid obj
[new stdClass(), null, false, false],
// Empty Values
[[], null, false, false],
['', null, false, false],
[null, null, false, false],
];
}

/**
* Ensures that the validator follows expected behavior
*
* @dataProvider datesDataProvider
* @param string|numeric|DateTime|object|array $input
* @param string|numeric|DateTime|object|array|null $input
*/
public function testBasic($input, ?string $format, bool $result, bool $resultStrict): void
{
$this->validator->setFormat($format);
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, PossiblyNullArgument */
$this->assertEquals($result, $this->validator->isValid($input));
}

/**
* @dataProvider datesDataProvider
* @param string|numeric|DateTime|object|array $input
* @param string|numeric|DateTime|object|array|null $input
*/
public function testBasicStrictMode($input, ?string $format, bool $result, bool $resultStrict): void
{
$this->validator->setStrict(true);
$this->validator->setFormat($format);
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, PossiblyNullArgument */
$this->assertSame($resultStrict, $this->validator->isValid($input));
}

Expand Down
5 changes: 4 additions & 1 deletion test/Db/NoRecordExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ protected function getMockHasResult()
$mockConnection = $this->createMock(ConnectionInterface::class);

// Mock has result
$mockHasResultRow = new ArrayObject();
$mockHasResultRow = new class extends ArrayObject {
public ?string $one = null;
};

$mockHasResultRow->one = 'one';

$mockHasResult = $this->createMock(ResultInterface::class);
Expand Down
5 changes: 4 additions & 1 deletion test/Db/RecordExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ protected function getMockHasResult()
$mockConnection = $this->createMock(ConnectionInterface::class);

// Mock has result
$mockHasResultRow = new ArrayObject();
$mockHasResultRow = new class extends ArrayObject {
public ?string $one = null;
};

$mockHasResultRow->one = 'one';

$mockHasResult = $this->createMock(ResultInterface::class);
Expand Down
2 changes: 2 additions & 0 deletions test/File/Crc32Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function testLegacy($options, $isValidParam, bool $expected, string $mess
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/ExcludeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function testLegacy($options, $isValidParam, bool $expected, string $mess
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/ExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function testLegacy(string $options, $isValidParam, bool $expected): void
if (is_array($isValidParam)) {
$validator = new File\Exists($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function testLegacy($options, $isValidParam, bool $expected, string $mess
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ public function testLegacy($options, $isValidParam, bool $expected, string $mess
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/ImageSizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public function testLegacy(array $options, $isValidParam, bool $expected, $messa
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/Md5Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public function testLegacy($options, $isValidParam, bool $expected, string $mess
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/NotExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public function testLegacy(string $options, $isValidParam, bool $expected): void
if (is_array($isValidParam)) {
$validator = new File\NotExists($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/Sha1Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public function testLegacy($options, $isValidParam, bool $expected, string $mess
if (! $expected) {
$this->assertArrayHasKey($messageKey, $validator->getMessages());
}
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/SizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function testLegacy($options, $isValidParam, bool $expected): void
if (is_array($isValidParam)) {
$validator = new File\Size($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/File/WordCountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function testLegacy($options, $isValidParam, bool $expected): void
if (is_array($isValidParam)) {
$validator = new File\WordCount($options);
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
} else {
$this->expectNotToPerformAssertions();
gsteel marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down