Repository navigation
Fix assertNotContains() narrowing a Traversable haystack to never #372
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| use function PHPUnit\Framework\assertArrayHasKey; | ||
| use function PHPUnit\Framework\assertContains; | ||
| use function PHPUnit\Framework\assertContainsEquals; | ||
| use function PHPUnit\Framework\assertNotContains; | ||
| use function PHPUnit\Framework\assertNotContainsEquals; | ||
| use function PHPUnit\Framework\assertContainsOnlyInstancesOf; | ||
| use function PHPUnit\Framework\assertCount; | ||
| use function PHPUnit\Framework\assertNotCount; | ||
|
|
@@ -86,6 +88,30 @@ public function containsEquals(array $a, \Traversable $b): void | |
| assertType('Traversable', $b); | ||
| } | ||
|
|
||
| /** | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add more tests for cases which are fixed by this PR:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in df9174b: the |
||
| * @param 'bar'|'foo' $c | ||
| */ | ||
| public function notContains(array $a, \Traversable $b, string $c): void | ||
| { | ||
| assertNotContains('foo', $a); | ||
| assertType("array<mixed~'foo'>", $a); | ||
|
|
||
| assertNotContains('foo', $b); | ||
| assertType('Traversable', $b); | ||
|
|
||
| assertNotContains($c, ['foo']); | ||
| assertType("'bar'", $c); | ||
| } | ||
|
|
||
| public function notContainsEquals(array $a, \Traversable $b): void | ||
| { | ||
| assertNotContainsEquals('foo', $a); | ||
| assertType('array', $a); | ||
|
|
||
| assertNotContainsEquals('foo', $b); | ||
| assertType('Traversable', $b); | ||
| } | ||
|
|
||
| public function containsOnlyInstancesOf(array $a, \Traversable $b): void | ||
| { | ||
| assertContainsOnlyInstancesOf(\stdClass::class, $a); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trimNamehas more cases which are handled as negated. should we maketrimNamedo the decision and return the "isNegated", so we don't need to keep this logic in sync?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in cbb67e5:
trimName()now returns whether the assertion is negated, andcreateExpression()uses that instead of looking for "Not" in the name. Nothing tested theassertIsNot*()assertions, so I added a case forassertIsNotString()