[wp-trac] [WordPress Trac] #53123: Tests: review of assertTrue or assertFalse with in_array

WordPress Trac noreply at wordpress.org
Fri Apr 30 19:35:40 UTC 2021


#53123: Tests: review of assertTrue or assertFalse with in_array
------------------------------+-----------------------------
 Reporter:  hellofromTonya    |      Owner:  (none)
     Type:  task (blessed)    |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:
 Severity:  minor             |   Keywords:
  Focuses:  docs              |
------------------------------+-----------------------------
 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:

 {{{#!php
 $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:

 {{{#!php
 $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()`

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53123>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list