WordPress.org

Make WordPress Core

Opened 7 weeks ago

#53123 new task (blessed)

Tests: review of assertTrue or assertFalse with in_array

Reported by: hellofromTonya Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Build/Test Tools Keywords:
Focuses: docs Cc:

Description

While looking at the tests in the context of another ticket, @jrf and I came across tests checking if a value is in an array by using assertTrue or assertFalse with in_array(). For example:

$this->assertTrue( in_array( $function, $defined, true ), $msg );

PHPUnit provides the following assertions:

  • assertContains: checks if a value exists in an array
  • assertNotContains: checks the opposite, i.e. if a value does not exist in an array

See: - https://phpunit.readthedocs.io/en/7.0/assertions.html#assertcontains

Using the example from above, it could be changed to:

$this->assertContains( $function, $defined, $msg );

This ticket proposes to review the test suite to verify each occurrence and then replace:

  • assertTrue( in_array() ) with assertContains()
  • assertFalse( in_array() ) with assertNotContains()

Change History (0)

Note: See TracTickets for help on using tickets.