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() and object equality #3511

Closed
sebastianbergmann opened this issue Feb 5, 2019 · 0 comments
Closed

assertContains() and object equality #3511

sebastianbergmann opened this issue Feb 5, 2019 · 0 comments
Labels
type/enhancement A new idea that should be implemented

Comments

@sebastianbergmann
Copy link
Owner

As part of #3422, assertStringContainsString(), assertStringContainsStringIgnoringCase(), assertStringNotContainsString(), and assertStringNotContainsStringIgnoringCase() were introduced in PHPUnit 7.5 to separate the use cases that operate on strings from assertContains(). This was good.

Also as part of #3422, and implemented in #3425, optional parameters for assertContains() that have an effect when non-string haystacks (read: iterable haystacks) are used, were deprecated. The result of this is that, once these optional parameters are completely removed in PHPUnit 9 (see #3426), there is currently no way to assert that an object is contained in an iterable while using == instead of ===. This is bad and something should be done about it.

The original implementation of #3422 in 2975888 introduced new assertions assertIterableContains() and assertIterableContainsSame(), for instance, to support the two separate use cases of asserting that an object is contained in an iterable, once using == and once using ===, respectively. This idea was abandoned in order to avoid additional backward compatibility breaks that would have resulted from deprecating the original assertContains() methods.

@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Feb 5, 2019
@sebastianbergmann sebastianbergmann modified the milestone: PHPUnit 8.1 Feb 5, 2019
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 16, 2020
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 16, 2020
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 16, 2020
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 21, 2020
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Jul 22, 2021
…ng due to `assertContains()` using strict checking

Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Jul 26, 2021
…ng due to `assertContains()` using strict checking

Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Jul 30, 2021
…ng due to `assertContains()` using strict checking

Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 6, 2021
…ng due to `assertContains()` using strict checking

Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 6, 2021
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 7, 2021
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
jrfnl added a commit to jrfnl/wordpress-develop-official that referenced this issue Aug 7, 2021
Since PHPUnit 8.0.2, the `assertContains()` method when checking whether a value exists in an array will do a strict type comparison of the values.

This caused a couple of tests to fail.

Using the correct data type in the test fixes that.

Refs:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33
pento pushed a commit to WordPress/wordpress-develop that referenced this issue Aug 7, 2021
…ing.

Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33

Follow-up to [51559-51570].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51571 602fd350-edb4-49c9-b593-d223f7449a82
nylen pushed a commit to nylen/wordpress-develop-svn that referenced this issue Aug 7, 2021
…ing.

Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33

Follow-up to [51559-51570].

Props jrf.
See #46149.

git-svn-id: https://develop.svn.wordpress.org/trunk@51571 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this issue Aug 7, 2021
…ing.

Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33

Follow-up to [51559-51570].

Props jrf.
See #46149.
Built from https://develop.svn.wordpress.org/trunk@51571


git-svn-id: http://core.svn.wordpress.org/trunk@51182 1a063a9b-81f0-0310-95a4-ce76da25c4cd
gMagicScott pushed a commit to gMagicScott/core.wordpress-mirror that referenced this issue Aug 7, 2021
…ing.

Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.md#802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33

Follow-up to [51559-51570].

Props jrf.
See #46149.
Built from https://develop.svn.wordpress.org/trunk@51571


git-svn-id: https://core.svn.wordpress.org/trunk@51182 1a063a9b-81f0-0310-95a4-ce76da25c4cd
mattyrob added a commit to ClassicPress/ClassicPress that referenced this issue Nov 18, 2022
* Remove unused PHPUnit7 files

* WP-r51570: Build/Test Tools: Alias the `Getopt` class conditionally, as the class no longer exists in PHPUnit 9.x.

Most of the aliasing in this `compat.php` file is redundant as PHPUnit 5.7.21+ contains a forward compatibility layer for these classes anyway (= PHPUnit provides both the namespaced and underscore named versions of these classes in PHPUnit 5.7.21+).

All the same, the file and the aliases are left in place for the time being, as plugins/themes using the WP test suite as the basis for their integration tests may rely on it, though WP itself should not really need it anymore, save for maybe one or two classes.

Follow-up to https://core.trac.wordpress.org/log/?revs=51559-51569.

WP:Props jrf.
See https://core.trac.wordpress.org/ticket/46149.

Conflicts:
- tests/phpunit/includes/phpunit6/compat.php

---

Merges https://core.trac.wordpress.org/changeset/51570 / WordPress/wordpress-develop@fcd4aa4700 to ClassicPress.

* Fix merge conflicts from 51570

* WP-r51462: Tests: Replace `assertContains()` with `assertStringContainsString()` when used with strings.

Using the `assertContains()` and `assertNotContains()` methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

* `assertStringContainsString()`
* `assertStringContainsStringIgnoringCase`
* `assertStringNotContainsString()`
* `assertStringNotContainsStringIgnoringCase`

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the `WP_UnitTestCase` class for PHPUnit < 7.5.

Follow-up to https://core.trac.wordpress.org/changeset/51331, https://core.trac.wordpress.org/changeset/51451, https://core.trac.wordpress.org/changeset/51461.

WP:Props jrf, dd32, SergeyBiryukov.
See https://core.trac.wordpress.org/ticket/53363, https://core.trac.wordpress.org/ticket/46149.

Conflicts:
- tests/phpunit/tests/admin/includesListTable.php
- tests/phpunit/tests/admin/includesTemplate.php
- tests/phpunit/tests/admin/wpPrivacyRequestsTable.php
- tests/phpunit/tests/blocks/block-editor.php
- tests/phpunit/tests/blocks/render.php
- tests/phpunit/tests/category/wpListCategories.php
- tests/phpunit/tests/comment.php
- tests/phpunit/tests/comment/commentForm.php
- tests/phpunit/tests/comment/getCommentReplyLink.php
- tests/phpunit/tests/comment/query.php
- tests/phpunit/tests/customize/nav-menus.php
- tests/phpunit/tests/customize/widgets.php
- tests/phpunit/tests/formatting/MakeClickable.php
- tests/phpunit/tests/l10n.php
- tests/phpunit/tests/media.php
- tests/phpunit/tests/meta/query.php
- tests/phpunit/tests/post/output.php
- tests/phpunit/tests/privacy/wpPrivacyGeneratePersonalDataExportGroupHtml.php
- tests/phpunit/tests/privacy/wpPrivacySendErasureFulfillmentNotification.php
- tests/phpunit/tests/privacy/wpPrivacySendPersonalDataExportEmail.php
- tests/phpunit/tests/privacy/wpPrivacySendRequestConfirmationNotification.php
- tests/phpunit/tests/query/invalidQueries.php
- tests/phpunit/tests/rest-api/rest-attachments-controller.php
- tests/phpunit/tests/rest-api/rest-block-renderer-controller.php
- tests/phpunit/tests/rest-api/rest-posts-controller.php
- tests/phpunit/tests/rest-api/rest-revisions-controller.php
- tests/phpunit/tests/rest-api/rest-tags-controller.php
- tests/phpunit/tests/robots.php
- tests/phpunit/tests/sitemaps/sitemaps.php
- tests/phpunit/tests/term/getTermLink.php
- tests/phpunit/tests/term/wpGenerateTagCloud.php
- tests/phpunit/tests/user/author.php
- tests/phpunit/tests/user/wpDropdownUsers.php
- tests/phpunit/tests/user/wpSendUserRequest.php
- tests/phpunit/tests/widgets.php
- tests/phpunit/tests/widgets/custom-html-widget.php
- tests/phpunit/tests/widgets/media-image-widget.php
- tests/phpunit/tests/widgets/media-video-widget.php
- tests/phpunit/tests/widgets/text-widget.php
- tests/phpunit/tests/widgets/wpWidgetRss.php

---

Merges https://core.trac.wordpress.org/changeset/51462 / WordPress/wordpress-develop@c70fe62ed1 to ClassicPress.

* Fix merge conflicts from 51462

* WP-r51571: Tests: Fix tests failing due to `assertContains()` using strict checking.

Since PHPUnit 8.0.2, the `assertContains()` method, when checking whether a value exists in an array, will do a strict type comparison of the values.

This caused a couple of tests to fail. Using the correct data type in the test fixes that.

References:
* https://github.com/sebastianbergmann/phpunit/blob/8.0.6/ChangeLog-8.0.mdhttps://core.trac.wordpress.org/ticket/802---2019-02-07
* sebastianbergmann/phpunit#3511
* sebastianbergmann/phpunit@6205f33

Follow-up to https://core.trac.wordpress.org/log/?revs=51559-51570.

WP:Props jrf.
See https://core.trac.wordpress.org/ticket/46149.

Conflicts:
- tests/phpunit/tests/rest-api/rest-term-meta-fields.php

---

Merges https://core.trac.wordpress.org/changeset/51571 / WordPress/wordpress-develop@60dcae95ea to ClassicPress.

* Add composer scripts for local tests

* Fix composer script for tests

* Corrections based on PR review

Co-authored-by: Sergey Biryukov <sergeybiryukov@git.wordpress.org>
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

1 participant