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

Add assertObjectHasProperty() and assertObjectNotHasProperty() to PHPUnit 9.6 #5478

Closed
sebastianbergmann opened this issue Aug 19, 2023 · 0 comments
Assignees
Labels
feature/assertion Issues related to assertions and expectations type/backward-compatibility Something will be/is intentionally broken version/9 Something affects PHPUnit 9

Comments

@sebastianbergmann
Copy link
Owner

The assertions assertObjectHasAttribute() and assertObjectNotHasAttribute() were removed in PHPUnit 10.0. When this decision was made and the change implemented, there was no replacement planned for these methods.

PHPUnit 9.6 was released alongside PHPUnit 10.0 to warn about functionality that was removed in PHPUnit 10.0. This is why PHPUnit 9.6.0 deprecated assertObjectHasAttribute() and assertObjectNotHasAttribute() without suggesting an alternative.

The functionality was reintroduced, using new methods names assertObjectHasProperty() and assertObjectNotHasProperty(), in PHPUnit 10.1 because users convinced me that it is useful (I never had to use it myself). As of PHPUnit 9.6.7, the deprecations suggest to use these new methods.

This series of events lead to a mess that was discussed in #5448 as well as here and here, for instance.

To fix this mess, I will add assertObjectHasProperty() and assertObjectNotHasProperty() to PHPUnit 9.6.

@sebastianbergmann sebastianbergmann added type/backward-compatibility Something will be/is intentionally broken feature/assertion Issues related to assertions and expectations version/9 Something affects PHPUnit 9 labels Aug 19, 2023
@sebastianbergmann sebastianbergmann self-assigned this Aug 19, 2023
sebastianbergmann added a commit that referenced this issue Aug 19, 2023
jrfnl added a commit to Yoast/PHPUnit-Polyfills that referenced this issue Aug 19, 2023
…ertObject[Not]HasProperty() methods

PHPUnit 10.1.0 introduced the new `Assert::assertObjectHasProperty()` and `Assert::assertObjectNotHasProperty()` methods.

These methods have now been backported to PHPUnit 9.6.11, so should be made available in the PHPUnit Polyfills 1.x series.

This commit:
* Adds two traits with the same name.
    One to polyfill the methods when not available in PHPUnit.
    The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available.
* Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used.
* An availability test and functional tests for the functionality polyfilled.

Includes:
* Adding the new polyfill to the existing `TestCases` classes.

Refs:
* sebastianbergmann/phpunit#5220
* sebastianbergmann/phpunit#5231 (and follow up commits/PRs)
* sebastianbergmann/phpunit#5478

Co-authored-by: Jan-Sverre Riksfjord <jasverix@gmail.com>
Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
jrfnl added a commit to Yoast/PHPUnit-Polyfills that referenced this issue Aug 19, 2023
…ertObject[Not]HasProperty() methods

PHPUnit 10.1.0 introduced the new `Assert::assertObjectHasProperty()` and `Assert::assertObjectNotHasProperty()` methods.

These methods have now been backported to PHPUnit 9.6.11, so should be made available in the PHPUnit Polyfills 1.x series.

This commit:
* Adds two traits with the same name.
    One to polyfill the methods when not available in PHPUnit.
    The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available.
* Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used.
* An availability test and functional tests for the functionality polyfilled.

Includes:
* Adding the new polyfill to the existing `TestCases` classes.

Refs:
* sebastianbergmann/phpunit#5220
* sebastianbergmann/phpunit#5231 (and follow up commits/PRs)
* sebastianbergmann/phpunit#5478

Co-authored-by: Jan-Sverre Riksfjord <jasverix@gmail.com>
Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
jrfnl added a commit to Yoast/PHPUnit-Polyfills that referenced this issue Aug 19, 2023
…ertObject[Not]HasProperty() methods

PHPUnit 10.1.0 introduced the new `Assert::assertObjectHasProperty()` and `Assert::assertObjectNotHasProperty()` methods.

These methods have now been backported to PHPUnit 9.6.11, so should be made available in the PHPUnit Polyfills 1.x series.

This commit:
* Adds two traits with the same name.
    One to polyfill the methods when not available in PHPUnit.
    The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available.
* Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used.
* An availability test and functional tests for the functionality polyfilled.

Includes:
* Adding the new polyfill to the existing `TestCases` classes.

Refs:
* sebastianbergmann/phpunit#5220
* sebastianbergmann/phpunit#5231 (and follow up commits/PRs)
* sebastianbergmann/phpunit#5478

Co-authored-by: Jan-Sverre Riksfjord <jasverix@gmail.com>
Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
jrfnl added a commit to Yoast/PHPUnit-Polyfills that referenced this issue Aug 19, 2023
…ertObject[Not]HasProperty() methods

PHPUnit 10.1.0 introduced the new `Assert::assertObjectHasProperty()` and `Assert::assertObjectNotHasProperty()` methods.

These methods have now been backported to PHPUnit 9.6.11, so should be made available in the PHPUnit Polyfills 1.x series.

This commit:
* Adds two traits with the same name.
    One to polyfill the methods when not available in PHPUnit.
    The other - an empty trait - to allow for `use`-ing the trait in PHPUnit versions in which the methods are already natively available.
* Logic to the custom autoloader which will load the correct trait depending on the PHPUnit version used.
* An availability test and functional tests for the functionality polyfilled.

Includes:
* Adding the new polyfill to the existing `TestCases` classes.

Refs:
* sebastianbergmann/phpunit#5220
* sebastianbergmann/phpunit#5231 (and follow up commits/PRs)
* sebastianbergmann/phpunit#5478

Co-authored-by: Jan-Sverre Riksfjord <jasverix@gmail.com>
Co-authored-by: Sebastian Bergmann <sb@sebastian-bergmann.de>
VerifiedJoseph added a commit to VerifiedJoseph/ntfy-php-library that referenced this issue Aug 21, 2023
Updates tests to use phpunit method `assertObjectHasProperty()`.

sebastianbergmann/phpunit#5478
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/assertion Issues related to assertions and expectations type/backward-compatibility Something will be/is intentionally broken version/9 Something affects PHPUnit 9
Projects
None yet
Development

No branches or pull requests

1 participant