Make WordPress Core


Ignore:
Timestamp:
05/26/2025 12:03:18 PM (13 months ago)
Author:
johnbillion
Message:

Build/Test Tools: Add assertions that test the tests.

Several tests perform assertions conditionally or iterate dynamic arrays without ensuring they're populated. If the test is faulty and the condition never evaluates to true, or the array being iterated is unexpectedly empty, this will now correctly cause the test to fail.

Props johnbillion, jrf.

See #63167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/taxonomy.php

    r56642 r60251  
    2929
    3030    public function test_get_post_taxonomy() {
    31         foreach ( get_object_taxonomies( 'post' ) as $taxonomy ) {
     31        $taxonomies = get_object_taxonomies( 'post' );
     32
     33        $this->assertNotEmpty( $taxonomies );
     34
     35        foreach ( $taxonomies as $taxonomy ) {
    3236            $tax = get_taxonomy( $taxonomy );
    3337            // Should return an object with the correct taxonomy object type.
     
    111115
    112116    public function test_get_link_taxonomy() {
    113         foreach ( get_object_taxonomies( 'link' ) as $taxonomy ) {
     117        $taxonomies = get_object_taxonomies( 'link' );
     118
     119        $this->assertNotEmpty( $taxonomies );
     120
     121        foreach ( $taxonomies as $taxonomy ) {
    114122            $tax = get_taxonomy( $taxonomy );
    115123            // Should return an object with the correct taxonomy object type.
Note: See TracChangeset for help on using the changeset viewer.