-
-
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
Add assertObjectHasProperty()
and assertObjectHasNotProperty()
#5220
Comments
I think this can be done, but it should target |
assertObjectHasProperty()
and assertObjectHasNotProperty()
…tObject[Not]HasProperty() methods PHPUnit 10.1.0 introduces the new `Assert::assertObjectHasProperty()` and `Assert::assertObjectNotHasProperty()` methods. 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) Co-authored-by: Jan-Sverre Riksfjord <[email protected]> Co-authored-by: Sebastian Bergmann <[email protected]>
So the solution is to downgrade to 9.6.0 as all minor updates after that breaks since AFAIK there is no way to suppress this and it fails the tests. My library still supports 7.4 so I cannot go up and the fix isn't backported :-( |
Yeah, if the warnings were backported to 9.6.x (by #5160).... then the new methods should be also available there, so cases can be fixed in 9. Without the methods... the warnings are just useless noise and only solutions are:
Both far from ideal, I'd say, sigh. Ciao :-) |
In my mind the methods should be added from same release the deprecation have been added to provide an upgrade path. It's not always possible to update to phpunit 10 (if you are using the symfony/phpunit-bridge for example) you are stuck on phpunit 9.6.x. @sebastianbergmann I can create a PR that targets the 9.6 branch if you are agree with that. |
I would like to avoid changing PHPUnit 9. You can use yoast/phpunit-polyfills to work around this issue. |
@jrfnl Would your polyfills have a problem if PHPUnit 9.6 would get |
@sebastianbergmann Shouldn't be a problem at all. The autoloader does a check for the methods before loading the polyfill. |
@jrfnl Thank you! |
…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 <[email protected]> Co-authored-by: Sebastian Bergmann <[email protected]>
…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 <[email protected]> Co-authored-by: Sebastian Bergmann <[email protected]>
…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 <[email protected]> Co-authored-by: Sebastian Bergmann <[email protected]>
…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 <[email protected]> Co-authored-by: Sebastian Bergmann <[email protected]>
@sebastianbergmann FYI: I've just released PHPUnit Polyfills 1.1.0, which backports the polyfill for these methods to the 1.x (PHPUnit 4.x - 9.x) series. |
@sebastianbergmann @jrfnl Thanks for the consideration of this topic and the solution. |
We want this to get past deprecations: sebastianbergmann/phpunit#5220
We want this to get past deprecations: sebastianbergmann/phpunit#5220
We want this to get past deprecations: sebastianbergmann/phpunit#5220
The assertObjectHasAttribute() is deprecated because the word "attribute" means something different in the PHP world now. But it was deprecated without any replacement, stating that it is bad code causing this assertion, one should use classes etc instead.
The problem is that I am using PhpUnit to unit-test my JSON API, and I cannot see a replacement for just checking the JSON structure. Of course,
assertTrue(property_exists())
works, but the error message yielded is not nearly as good as assertObjectHasAttribute was.Can we consider making assertObjectHasProperty()? That name will never be wrong, because it is the exact same word as in property_exists().
The text was updated successfully, but these errors were encountered: