WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesPlugin.php

    r47122 r48937  
    2424        foreach ( $default_headers as $name => $value ) {
    2525            $this->assertTrue( isset( $data[ $name ] ) );
    26             $this->assertEquals( $value, $data[ $name ] );
     26            $this->assertSame( $value, $data[ $name ] );
    2727        }
    2828    }
     
    5252
    5353        foreach ( $expected as $name => $value ) {
    54             $this->assertEquals( $value, menu_page_url( $name, false ) );
     54            $this->assertSame( $value, menu_page_url( $name, false ) );
    5555        }
    5656
     
    350350    public function test_get_plugin_files_single() {
    351351        $name = 'hello.php';
    352         $this->assertEquals( array( $name ), get_plugin_files( $name ) );
     352        $this->assertSame( array( $name ), get_plugin_files( $name ) );
    353353    }
    354354
     
    370370            'list_files_test_plugin/subdir/subfile.php',
    371371        );
    372         $this->assertEquals( $expected, $plugin_files );
     372        $this->assertSame( $expected, $plugin_files );
    373373
    374374        unlink( $sub_dir . '/subfile.php' );
     
    390390        }
    391391
    392         $this->assertEquals( array(), get_mu_plugins() );
     392        $this->assertSame( array(), get_mu_plugins() );
    393393
    394394        // Clean up.
     
    411411        }
    412412
    413         $this->assertEquals( array(), get_mu_plugins() );
     413        $this->assertSame( array(), get_mu_plugins() );
    414414
    415415        // Clean up.
     
    433433
    434434        $this->_create_plugin( '<?php\n//Silence is golden.', 'index.php', WPMU_PLUGIN_DIR );
    435         $this->assertEquals( array(), get_mu_plugins() );
     435        $this->assertSame( array(), get_mu_plugins() );
    436436
    437437        // Clean up.
     
    458458        $this->_create_plugin( '<?php\n//Silence is not golden.', 'index.php', WPMU_PLUGIN_DIR );
    459459        $found = get_mu_plugins();
    460         $this->assertEquals( array( 'index.php' ), array_keys( $found ) );
     460        $this->assertSame( array( 'index.php' ), array_keys( $found ) );
    461461
    462462        // Clean up.
     
    484484        $this->_create_plugin( '<?php\n//Test 2', 'bar.txt', WPMU_PLUGIN_DIR );
    485485        $found = get_mu_plugins();
    486         $this->assertEquals( array( 'foo.php' ), array_keys( $found ) );
     486        $this->assertSame( array( 'foo.php' ), array_keys( $found ) );
    487487
    488488        // Clean up.
     
    502502        $this->assertLessThan( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'b' ) ) );
    503503        $this->assertGreaterThan( 0, _sort_uname_callback( array( 'Name' => 'c' ), array( 'Name' => 'b' ) ) );
    504         $this->assertEquals( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'a' ) ) );
     504        $this->assertSame( 0, _sort_uname_callback( array( 'Name' => 'a' ), array( 'Name' => 'a' ) ) );
    505505    }
    506506
     
    511511        $this->_back_up_drop_ins();
    512512
    513         $this->assertEquals( array(), get_dropins() );
     513        $this->assertSame( array(), get_dropins() );
    514514
    515515        // Clean up.
     
    527527
    528528        $dropins = get_dropins();
    529         $this->assertEquals( array( 'advanced-cache.php' ), array_keys( $dropins ) );
     529        $this->assertSame( array( 'advanced-cache.php' ), array_keys( $dropins ) );
    530530
    531531        unlink( $p1[1] );
     
    591591     */
    592592    public function test_validate_active_plugins_empty() {
    593         $this->assertEquals( array(), validate_active_plugins() );
     593        $this->assertSame( array(), validate_active_plugins() );
    594594    }
    595595
Note: See TracChangeset for help on using the changeset viewer.