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

AssertContains : $ignorecase doesn't work #3315

Closed
Tominounet opened this issue Sep 27, 2018 · 4 comments
Closed

AssertContains : $ignorecase doesn't work #3315

Tominounet opened this issue Sep 27, 2018 · 4 comments

Comments

@Tominounet
Copy link

Q A
PHPUnit version 6.5.13
PHP version 7.2
Installation Method PHAR

I'm using and learning how to test my code with PHPUnit. I had some test to make, so I can understand some asserts. Then I tried this one :

image

So I expected this test to be ok, but...

image

It seems the $ignorecase parameter doesn't work, true or false doesn't change anything. Is it normal ?

@sebastianbergmann
Copy link
Owner

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. Do not use screenshots of code.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

@mkasberg
Copy link
Contributor

mkasberg commented Oct 1, 2018

I'm not sure this is actually a bug. I think the code is behaving more or less as expected, and the behavior is documented in the PHPUnit documentation (for both 7 and 6.5).

assertContains() has 2 documented forms:

  • assertContains(string $needle, string $haystack[, string $message = '', boolean $ignoreCase = false]) which accepts a string $haystack and a 4th parameter $ignoreCase
  • assertContains(mixed $needle, Iterator|array $haystack[, string $message = '']), which accepts an array $haystack but does not take a 4th parameter for case sensitivity.

In your example, because your second parameter is an array, PHPUnit assumes you are using the "array" form of the method, and ignores the $ignoreCase parameter.

Perhaps there is some small room for improvement here. PHPUnit could throw an IllegalArgumentException (or similar) in Framework/Assert.php if $ignoreCase=true was passed and the second argument is not a string. I think it would be relatively easy for me to propose some changes along these lines in a pull request and we can see what everyone thinks.

@sebastianbergmann
Copy link
Owner

No feedback, closing.

@epdenouden
Copy link
Contributor

@sebastianbergmann looks like there is an example in the related pull request: #3317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants