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

Proposal: split assertContains for iterables and non-iterables #3422

Closed
keradus opened this issue Nov 28, 2018 · 7 comments
Closed

Proposal: split assertContains for iterables and non-iterables #3422

keradus opened this issue Nov 28, 2018 · 7 comments
Assignees
Labels
type/enhancement A new idea that should be implemented
Milestone

Comments

@keradus
Copy link
Contributor

keradus commented Nov 28, 2018

currently, one can do both with a single assertion:

$this->assertContains('b', ['a', 'b', 'c']);
$this->assertContains('b', 'abc');

which is confusing if someone use it like the following, and for that error prone due to accidental lack of types control

$this->assertContains('b', $haystack);

what about splitting the responsibility of that assertion, to have one for strings and one for iterables ?

ref PHP-CS-Fixer/PHP-CS-Fixer#4061

@sebastianbergmann
Copy link
Owner

I interpret this as

  • Add assertIterableContains() and assertStringContains() in PHPUnit 7.5
  • Deprecate (soft) assertContains() in PHPUnit 7.5
  • Deprecate (hard) assertContains() in PHPUnit 8.0

Correct?

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Nov 28, 2018

Going further, we probably want to get rid of the optional parameters and introduce

  • assertStringContainsString() (uses new StringContains($needle, false))
  • assertStringContainsStringIgnoringCase() (uses new StringContains($needle, true))
  • assertIterableContains() (uses new TraversableContains($needle, false, false))
  • assertIterableContainsSame() (uses new TraversableContains($needle, true, true))

etc.

@sebastianbergmann sebastianbergmann self-assigned this Nov 28, 2018
@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Nov 28, 2018
@sebastianbergmann sebastianbergmann added this to the PHPUnit 7.5 milestone Nov 28, 2018
sebastianbergmann added a commit that referenced this issue Nov 28, 2018
@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Nov 28, 2018

@keradus Can you please have a look at master...686d153? Thanks!

@keradus
Copy link
Contributor Author

keradus commented Nov 28, 2018

Hi ! First of all, glad you like the idea !

Deprecate (soft) assertContains() in PHPUnit 7.5
Deprecate (hard) assertContains() in PHPUnit 8.0

can you elaborate how you define difference of hard and soft deprecation? if hard is removal of functionality, then that's how I would see this to happen indeed ;)

assertIterableContains() (uses new TraversableContains($needle, false, false))
assertIterableContainsSame() (uses new TraversableContains($needle, true, true))

I would rather promote strict comparison by default. Language itself is promoting to be strict about types now, let's not promote (by more convenient (/shorter) name) being not strict.
that saying, I would suggest following naming instead:
assertIterableContains to check strict
assertIterableContainsEqual to check non-strict

Can you please have a look at master...686d153? Thanks!

can you raise it as a PR? with link provided, I can't do the comments :(

@sebastianbergmann
Copy link
Owner

  1. Soft Deprecation in PHPUnit 7.5
  2. Hard Deprecation in PHPUnit 8
  3. Removal in PHPUnit 9

@sebastianbergmann
Copy link
Owner

Sorry, but I do not send myself pull requests.

@sebastianbergmann
Copy link
Owner

I agree with promoting strict comparison, but the naming as-is makes more sense to me somehow.

sebastianbergmann added a commit that referenced this issue Nov 29, 2018
sebastianbergmann added a commit that referenced this issue Dec 2, 2018
* Revert deprecation of assertContains() and assertNotContains()
* Revert addition of assertIterableContains(), assertIterableContainsSame(), assertIterableNotContains(), and assertIterableNotContainsSame()
* Deprecate using assertContains() and assertNotContains() on string haystacks
* Deprecate the optional parameters $ignoreCase, $checkForObjectIdentity, and $checkForNonObjectIdentity of assertContains() and assertNotContains()
bjuppa added a commit to bjuppa/laravel-blog that referenced this issue Feb 28, 2019
bjuppa added a commit to kontenta/kontour that referenced this issue Sep 20, 2019
...and require phpunit  >7.5 for assertStringContainsString

See sebastianbergmann/phpunit#3422
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 16, 2020
…sString()`

... when used with strings.

Using `assertContains()` and `assertNotContains()` with string haystacks was soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

For string haystacks, the `assertStringContainsString()`, `assertStringContainsStringIgnoringCase()`, `assertStringNotContainsString()` and `assertStringNotContainsStringIgnoringCase()` were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3422
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 16, 2020
…sString()`

... when used with strings.

Using `assertContains()` and `assertNotContains()` with string haystacks was soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

For string haystacks, the `assertStringContainsString()`, `assertStringContainsStringIgnoringCase()`, `assertStringNotContainsString()` and `assertStringNotContainsStringIgnoringCase()` were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3422
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 21, 2020
…sString()`

... when used with strings.

Using `assertContains()` and `assertNotContains()` with string haystacks was soft deprecated in PHPUnit 7.5, hard deprecated in PHPUnit 8.0 and the functionality was removed in PHPUnit 9.0.

For string haystacks, the `assertStringContainsString()`, `assertStringContainsStringIgnoringCase()`, `assertStringNotContainsString()` and `assertStringNotContainsStringIgnoringCase()` were introduced as replacements in PHPUnit 7.5.

Ref:
* https://github.com/sebastianbergmann/phpunit/blob/7.5.20/ChangeLog-7.5.md#750---2018-12-07
* sebastianbergmann/phpunit#3422
stronk7 added a commit to stronk7/moodle that referenced this issue Aug 31, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Aug 31, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Aug 31, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Aug 31, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 1, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 12, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 15, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 15, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 15, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 17, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 20, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 24, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 29, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 2, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 4, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 4, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 7, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 7, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 7, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 9, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 9, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 13, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 13, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 16, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 16, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 21, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 21, 2020
Both assertContains() and assertNotContains() are deprecated in PHPUnit 8
for operations on strings. Also the optional case parameter is. All uses
must be changed to one of:

- assertStringContainsString()
- assertStringContainsStringIgnoringCase()
- assertStringNotContainsString()
- assertStringNotContainsStringIgnoringCase()

More info: sebastianbergmann/phpunit#3422

Regexp to find all uses:

ag 'assert(Not)?Contains\('
eliashaeussler added a commit to eliashaeussler/composer-update-reporter that referenced this issue Dec 26, 2021
eliashaeussler added a commit to eliashaeussler/composer-update-reporter that referenced this issue Dec 26, 2021
eliashaeussler added a commit to eliashaeussler/composer-update-check that referenced this issue Dec 26, 2021
eliashaeussler added a commit to eliashaeussler/cache-warmup that referenced this issue Dec 27, 2021
superstarlancer added a commit to superstarlancer/Laravel-Blog-Client that referenced this issue Mar 27, 2023
dawitengageiq pushed a commit to dawitengageiq/NLR that referenced this issue Sep 29, 2023
debaste pushed a commit to debaste/yii that referenced this issue Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

2 participants