-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Method assertNotContains fails with string needle if array contains 0. #3940
Comments
This behavior doesn't depend on type of the array or its values. I've got the same result for indexed, associative arrays and indexed arrays with mixed data inside. use PHPUnit\Framework\TestCase;
class SomeTest extends TestCase
{
public function testAssociativeArrayNumbersOnlyWillPass()
{
$arr = [
'x' => 1,
'y' => 1,
];
$this->assertNotContains('test', $arr);
}
public function testAssociativeArrayNumbersOnlyWillFail()
{
$arr = [
'x' => 1,
'y' => 0,
];
$this->assertNotContains('test', $arr);
}
public function testIndexedArrayNumbersOnlyWillPass()
{
$arr = [
1,
1,
];
$this->assertNotContains('test', $arr);
}
public function testIndexedArrayNumbersOnlyWillFail()
{
$arr = [
1,
0,
];
$this->assertNotContains('test', $arr);
}
public function testIndexedArrayWithStringsWillPass()
{
$arr = [
'php',
'phpunit',
1
];
$this->assertNotContains('test', $arr);
}
public function testIndexedArrayWithStringsWillFail()
{
$arr = [
'php',
'phpunit',
0,
];
$this->assertNotContains('test', $arr);
}
} The result is:
|
Verified. Thank you for the report. |
This is basically due to The issue can be worked around by passing |
Unfortunately this is expected behaviour in PHPUnit 8. Starting with PHPUnit 9, due in February 2020, |
Summary
I want to check that an array doesn't contain some string value.
If the array contains 0 as one of the values, assertNotContains fails assertion.
Current behavior
How to reproduce
Make fresh install of PHPUnit then execute this test:
Was tested on 8, 7, 6 versions with same result.
Expected behavior
The second test should pass too, because array doesn't contain 'test' value.
The text was updated successfully, but these errors were encountered: