Skip to content

Commit

Permalink
Simplified InArrayTest a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Aug 12, 2021
1 parent 568a9e0 commit a4b6fbc
Showing 1 changed file with 22 additions and 41 deletions.
63 changes: 22 additions & 41 deletions tests/TypeReconciliation/InArrayTest.php
Expand Up @@ -33,20 +33,16 @@ function assertInArray($x) {
/**
* @param int|null $x
* @param non-empty-list<int> $y
* @return int|null
* @return int
*/
function assertInArray($x, $y) {
if (in_array($x, $y, true)) {
acceptInt($x);
return $x;
}
return $x;
throw new \Exception();
}
/**
* @param int $x
*/
function acceptInt($x): void {
}',
',
],
'typeNotChangedAfterAssertionAgainstArrayOfMixed' => [
'<?php
Expand All @@ -68,20 +64,15 @@ function assertInArray($x, $y) {
/**
* @param int|string|bool $x
* @param non-empty-list<int|string> $y
* @return int|string|bool
* @return int|string
*/
function assertInArray($x, $y) {
if (in_array($x, $y, true)) {
acceptIntAndStr($x);
return $x;
}
return $x;
throw new \Exception();
}
/**
* @param int|string $x
*/
function acceptIntAndStr($x): void {
}',
',
],
'unionTypesReducedToIntersectionWithinAssertion' => [
'<?php
Expand Down Expand Up @@ -150,8 +141,8 @@ function assertInArray($x, $y) {
'<?php
/**
* @param string|bool $x
* @param non-empty-list<\'a\'|\'b\'|int> $y
* @return \'a\'|\'b\'
* @param non-empty-list<"a"|"b"|int> $y
* @return "a"|"b"
*/
function assertInArray($x, $y) {
if (in_array($x, $y, true)) {
Expand All @@ -164,8 +155,8 @@ function assertInArray($x, $y) {
'assertAgainstListOfLiteralsAndScalarUnionTypeHint' => [
'<?php
/**
* @param non-empty-list<\'a\'|\'b\'|int> $y
* @return \'a\'|\'b\'
* @param non-empty-list<"a"|"b"|int> $y
* @return "a"|"b"
*/
function assertInArray(string|bool $x, $y) {
if (in_array($x, $y, true)) {
Expand All @@ -192,42 +183,32 @@ public function providerInvalidCodeParse(): iterable
/**
* @param int|null $x
* @param non-empty-list<mixed> $y
* @return int|null
* @return int
*/
function assertInArray($x, $y) {
if (!in_array($x, $y, true)) {
acceptInt($x);
return $x;
}
return $x;
throw new \Exception();
}
/**
* @param int $x
*/
function acceptInt($x): void {
}',
'error_message' => 'PossiblyNullArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:39 - Argument 1 of acceptInt cannot be null, possibly null value provided',
',
'error_message' => 'NullableReturnStatement',
],
'typeNotChangedAfterNegatedAssertionAgainstUnsealedArrayOfUnionType' => [
'<?php
/**
* @param int|null $x
* @param non-empty-list<int|null> $y
* @return int|null
* @return int
*/
function assertInArray($x, $y) {
if (!in_array($x, $y, true)) {
acceptInt($x);
return $x;
}
return $x;
throw new \Exception();
}
/**
* @param int $x
*/
function acceptInt($x): void {
}',
'error_message' => 'PossiblyNullArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:39 - Argument 1 of acceptInt cannot be null, possibly null value provided',
',
'error_message' => 'NullableReturnStatement',
],
'initialTypeRemainsOutsideOfAssertion' => [
'<?php
Expand Down

0 comments on commit a4b6fbc

Please sign in to comment.