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

Deprecate assertions (and helper methods) that operate on (non-public) attributes #3338

Closed
sebastianbergmann opened this issue Oct 11, 2018 · 9 comments
Assignees
Milestone

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Oct 11, 2018

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
@sebastianbergmann sebastianbergmann added this to the PHPUnit 8.0 milestone Oct 11, 2018
@sebastianbergmann sebastianbergmann self-assigned this Oct 11, 2018
@sebastianbergmann sebastianbergmann changed the title Deprecate assertions that operate on (non-public) attributes Deprecate assertions (and helper methods) that operate on (non-public) attributes Oct 11, 2018
@TomasVotruba
Copy link

TomasVotruba commented Dec 10, 2018

What should be used instead?

@gmponos
Copy link

gmponos commented Dec 10, 2018

@TomasVotruba #3339

@TomasVotruba
Copy link

TomasVotruba commented Dec 10, 2018

@gmponos Thanks!

malukenho added a commit to malukenho/ProxyManager that referenced this issue Feb 27, 2019
- Remove unnecessary assertions
- Avoid using deprecated assertions
(sebastianbergmann/phpunit#3338)

Signed-off-by: Jefersson Nathan <malukenho.dev@gmail.com>
malukenho added a commit to malukenho/ProxyManager that referenced this issue Feb 27, 2019
* 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>
malukenho added a commit to malukenho/ProxyManager that referenced this issue Feb 27, 2019
* 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>
malukenho added a commit to malukenho/ProxyManager that referenced this issue Feb 27, 2019
* 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>
malukenho added a commit to malukenho/ProxyManager that referenced this issue Feb 27, 2019
* 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>
@geoidesic
Copy link

How do I figure out what replaces these?

@sebastianbergmann
Copy link
Owner Author

@geoidesic There is no replacement. The correct course of action is to refactor your code to not require dirty tricks like this.

@aogg
Copy link

aogg commented Aug 6, 2020

@geoidesic There is no replacement. The correct course of action is to refactor your code to not require dirty tricks like this.

why not

stronk7 added a commit to stronk7/moodle that referenced this issue Aug 31, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 15, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 15, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 15, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 17, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 20, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 24, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Sep 29, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 2, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 7, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 7, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 7, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 9, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 9, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 13, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 13, 2020
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"
@ishifoev
Copy link

@sebastianbergmann What alternative using readAttribute(). If it deprecated almost for a secure reason what method I just need for use?

@sebastianbergmann
Copy link
Owner Author

@AlexMalikov94 There is no replacement. The correct course of action is to refactor your code to not require dirty tricks like this.

@ishifoev
Copy link

@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.

stronk7 added a commit to stronk7/moodle that referenced this issue Oct 16, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 16, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 21, 2020
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"
stronk7 added a commit to stronk7/moodle that referenced this issue Oct 21, 2020
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"
encreinformatique added a commit to encreinformatique/FOSMessageBundle that referenced this issue Mar 10, 2021
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)
pkruithof pushed a commit to socialcarenetwork/FOSMessageBundle that referenced this issue Nov 28, 2022
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants