-
-
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
Remove assertions that operate on class/object properties #4601
Comments
Checked a (private) code base of mine and found a few uses of The use-case is when having to work with |
… and indeed, replacing/removing them was a no-brainer 😄 |
Will there be an alternative replacement or are we supposed to use plain-old-php for this? - $this->assertObjectHasAttribute('c', $sut->a->b);
+ $this->assertIsObject($sut->a->b);
+ $this->assertTrue(property_exists($sut->a->b, 'c')); |
Remove deprecated `assertObjectHasAttribute` calls. See sebastianbergmann/phpunit#4601 for the deprecation decision. In some cases, we can rely on PHP errors when the attribute is not present, in other cases (where errors would be very confusing or where the existence of the property is the only test) we implement our own check and message.
Thank you mate, @sebastianbergmann , you made us extra nonsense work for fixing our test environment |
That's a bit harsh... especially when considering that:
|
Same for XML |
The attribute assertion was really handy thing.. and if the issue only with new PHP attribute features, couldn't it be to rename them, something like? instead of this:
we will have something like this:
|
@armanist please check the following comment a few places up: #4601 (comment) In short it has been implemented in PHPUnit 10.1, similar to your suggestion. |
Found an usage of
Is there functional reasons NOT to use this replacement approach? |
@joneiros There are some minor differences:
Anyway, you can see all that by checking the phpunit implementation (the deprecated version or the new one, linked above). (in short and in my opinion, I'd keep using the one provided by phpunit) @sebastianbergmann may I suggest updating the description of the issue to say that there will be in fact a replacement, to avoid more "me too" comments? |
That's fine and dandy, but currently I get the warning with the hint to replace it with a method, which doesn't exist yet. |
Hi ! |
Stay sticky to PHPUnit 9.6.0 (the warnings were introduced in 9.6.1, AFAIK). It's really unfortunate that the new alternatives ( Ciao :-) |
@stronk7 - they have been backported in 9.6.11 ;) https://github.com/sebastianbergmann/phpunit/blob/9.6.11/ChangeLog-9.6.md |
Yeah, @swiffer, I was following the other issue, awesome! Problem for us is that we also faced a similar problem with other deprecation messages (for example, the removal in PHPUnit 10 of Still analysing if to add PHPUnit Polyfills may be a possible solution or we'll stay sticky to 9.5.x for the life of our released (stable) branches. Ciao :-) |
…ute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() sebastianbergmann/phpunit#4601
…ibute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists() (#438) sebastianbergmann/phpunit#4601
PHPUnit currently refers to "fields" (see above) as "attributes". This is (or will become) confusing considering the introduction of attributes in PHP 8 and their support in PHPUnit.
PHPUnit will be changed to use the term "property" instead of "attribute" where "field" is meant.
The following methods of
PHPUnit\Framework\Assert
will be removed in PHPUnit 10:assertClassHasAttribute()
assertClassNotHasAttribute()
assertClassHasStaticAttribute()
assertClassNotHasStaticAttribute()
assertObjectHasAttribute()
assertObjectNotHasAttribute()
classHasAttribute()
classHasStaticAttribute()
objectHasAttribute()
The following classes will be removed in PHPUnit 10:
PHPUnit\Framework\Constraint\ClassHasAttribute
PHPUnit\Framework\Constraint\ClassHasStaticAttribute
PHPUnit\Framework\Constraint\ObjectHasAttribute
At this time, no replacements are planned as these assertions are not wildly used (to the best of my knowledge) and, if at all, should only be used in edge case situations that I consider outside the scope of PHPUnit's standard distribution.
The text was updated successfully, but these errors were encountered: