-
-
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
Deprecate assertions (and helper methods) that operate on (non-public) attributes #3338
Comments
What should be used instead? |
@gmponos Thanks! |
- Remove unnecessary assertions - Avoid using deprecated assertions (sebastianbergmann/phpunit#3338) Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
* Remove unnecessary assertions * Avoid using deprecated assertions (sebastianbergmann/phpunit#3338) * Add more entropy when needed * Use static methods whenever possible (providers, test cases that don't access object context) Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
* Remove unnecessary assertions * Avoid using deprecated assertions (sebastianbergmann/phpunit#3338) * Add more entropy when needed * Use static methods whenever possible (providers, test cases that don't access object context) Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
* Remove unnecessary assertions * Avoid using deprecated assertions (sebastianbergmann/phpunit#3338) * Add more entropy when needed * Use static methods whenever possible (providers, test cases that don't access object context) Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
* Remove unnecessary assertions * Avoid using deprecated assertions (sebastianbergmann/phpunit#3338) * Add more entropy when needed * Use static methods whenever possible (providers, test cases that don't access object context) Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
How do I figure out what replaces these? |
@geoidesic There is no replacement. The correct course of action is to refactor your code to not require dirty tricks like this. |
why not |
With PHPUnit 8 a good number of assertions, all them related with operations on non-public attributes have been deprecated. And will be removed with PHPUnit 9. The main point is that unit tests shouldn't be testing non-public APIs (good practice) and those assertions were an error originally. See sebastianbergmann/phpunit#3338 for the complete list and other details. When possible (the attributes being checked are public), the change is simple, just switching to normal assertions. When the attributes are not public we need to find a workaround to be able to test the same using public APIs, or use Reflection, or remove the tests. For the records, this is the regexp used to find all the cases: ag '>(assertAttribute|attribute\(|readAttributte|getStaticAttribute| \ getObjectAttribute)' -G "test.php"
@sebastianbergmann What alternative using |
@AlexMalikov94 There is no replacement. The correct course of action is to refactor your code to not require dirty tricks like this. |
@sebastianbergmann Yes you are right is dirty tricks but in the past developers used it just I think you have an alternative I see it is not. I just use another function more flexibly. I will contribute your code in the future. |
With PHPUnit 8 a good number of assertions, all them related with operations on non-public attributes have been deprecated. And will be removed with PHPUnit 9. The main point is that unit tests shouldn't be testing non-public APIs (good practice) and those assertions were an error originally. See sebastianbergmann/phpunit#3338 for the complete list and other details. When possible (the attributes being checked are public), the change is simple, just switching to normal assertions. When the attributes are not public we need to find a workaround to be able to test the same using public APIs, or use Reflection, or remove the tests. For the records, this is the regexp used to find all the cases: ag '>(assertAttribute|attribute\(|readAttributte|getStaticAttribute| \ getObjectAttribute)' -G "test.php"
With PHPUnit 8 a good number of assertions, all them related with operations on non-public attributes have been deprecated. And will be removed with PHPUnit 9. The main point is that unit tests shouldn't be testing non-public APIs (good practice) and those assertions were an error originally. See sebastianbergmann/phpunit#3338 for the complete list and other details. When possible (the attributes being checked are public), the change is simple, just switching to normal assertions. When the attributes are not public we need to find a workaround to be able to test the same using public APIs, or use Reflection, or remove the tests. For the records, this is the regexp used to find all the cases: ag '>(assertAttribute|attribute\(|readAttributte|getStaticAttribute| \ getObjectAttribute)' -G "test.php"
assertAttributeEmpty is deprecated, see deprecated sebastianbergmann/phpunit#3338 Furthermore, getNbUnread() should return an `int` instead of null. It would be worth it to ensure it is an integer. (and test it)
assertAttributeEmpty is deprecated, see deprecated sebastianbergmann/phpunit#3338 Furthermore, getNbUnread() should return an `int` instead of null. It would be worth it to ensure it is an integer. (and test it)
The following methods should be deprecated:
assertAttributeContains()
assertAttributeNotContains()
assertAttributeContainsOnly()
assertAttributeNotContainsOnly()
assertAttributeCount()
assertAttributeNotCount()
assertAttributeEquals()
assertAttributeNotEquals()
assertAttributeEmpty()
assertAttributeNotEmpty()
assertAttributeGreaterThan()
assertAttributeGreaterThanOrEqual()
assertAttributeLessThan()
assertAttributeLessThanOrEqual()
assertAttributeSame()
assertAttributeNotSame()
assertAttributeInstanceOf()
assertAttributeNotInstanceOf()
assertAttributeInternalType()
assertAttributeNotInternalType()
attribute()
attributeEqualTo()
readAttribute()
getStaticAttribute()
getObjectAttribute
The text was updated successfully, but these errors were encountered: