See the overall status of the issues connected to this meta in the kanban board.
Problem/Motivation
Wherever possible, use specific PHPUnit default assertions, that also provide standard messaging in case of assertion failure. PHPUnit's list @ https://phpunit.readthedocs.io/en/8.5/assertions.html is the best starting point to understand what default PHPUnit provides.
However, beware of PHPUnit's own deprecations -- the most accurate list is PHPUnit 9 at the moment, https://phpunit.readthedocs.io/en/9.1/assertions.html. Drupal does not support PHPUnit 9 yet, but has already removed usage of methods deprecated in PHPUnit 8 in #3110543: [meta] Support PHPUnit 9 in Drupal 9.
For example: assertSame(*, count())
can be replaced by assertCount()
.
Issues open:
- #3131186: Replace assertions involving calls to drupalGetHeader() with session-based assertions, where possible
- #3131348: Replace assertions involving calls to empty() with assertEmpty()/assertNotEmpty()/assertArrayNotHasKey()
- #3128815: Replace assert*() involving greater/less comparison operators with assert(Greater|Less)Than(OrEqual)
- #3131807: Replace assertions involving calls to isset() with assertArrayHasKey()/assertArrayNotHasKey
- #3131900: Refactor assertions that assign return values to variables
- #3132919: Replace assert*() involving equality comparison operators with assert(Not)(Equals|Same)
- #3135027: Replace usages of assertArrayEquals, deprecate it
RTBC'd:
Pending backport to D8:
- None presently.
Done:
- #3082415: Replace assert(Not)Same/Identical() on booleans with assert(Not)True/False() in PHPUnit tests
- #3128905: Replace assert* involving an instanceof operator with assertInstanceOf()/assertNotInstanceOf()
- #3128813: Replace assertEqual() or assertSame() on two calls to count() with assertCount()
- #3128575: Replace assert*(*, is_null()) with assertNotNull()/assertNull()
- #3130396: Replace assertions involving calls to is_file with assertFileExists()/assertFileNotExists()
- #3131090: Replace assertions involving calls to is_dir with assertDirectoryExists()/assertDirectoryNotExists()
- #3130811: Remove redundant $message from assert(Not)InstanceOf calls
- #3131088: Replace assertions involving calls to file_exists with assertFileExists()/assertFileNotExists() or assertDirectoryExists()/assertDirectoryNotExists()
- #3128814: Replace assert* involving count() and an equality operator with assertCount()
- #3131223: Replace assertions involving calls to array_key_exists() with assertArrayHasKey()/assertArrayNotHasKey()
- #3131474: Replace assertions involving calls to array_search() with assertContains()/assertNotContains()
- #3131258: Remove redundant $message from assertFile(Not)Exists and assertDirectory(Not)Exists calls
- #3129074: Refactor assertions that use return values in conditionals
- #3131821: Replace assertions involving calls to is_callable() with assertIsCallable()/assertIsNotCallable()
- #3131820: Replace assertions involving calls to is_string() with assertIsString()/assertIsNotString()
- #3131817: Replace assertions involving calls to is_numeric() with assertIsNumeric()/assertIsNotNumeric()
- #3131816: Replace assertions involving calls to is_array() with assertIsArray()/assertIsNotArray()
- #3131818: Replace assertions involving calls to is_object() with assertIsObject()/assertIsObject()
- #3131819: Replace assertions involving calls to is_resource() with assertIsResource()
- #3128746: Replace assertions involving calls to strpos() with more accurate string assertions
- #3131343: Replace assertions involving calls to in_array() with assertContains()/assertNotContains()
- #3135390: Replace assertions involving calls to is_readable() and is_writeable() on files and directories with PHPUnit assertions
- #3126965: [backport] Replace assert* involving count() and an integer literal with assertCount()
- #3132964: assertResponse() does not actually support a $message parameter, so stop passing one
Proposed resolution
Add child issues for each case and replace them.