Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 years 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/upload.php

    r48464 r48937  
    2525                $subdir = gmstrftime( '/%Y/%m' );
    2626
    27                 $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/uploads' . $subdir, $info['url'] );
    28                 $this->assertEquals( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
    29                 $this->assertEquals( $subdir, $info['subdir'] );
    30                 $this->assertEquals( false, $info['error'] );
     27                $this->assertSame( get_option( 'siteurl' ) . '/wp-content/uploads' . $subdir, $info['url'] );
     28                $this->assertSame( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
     29                $this->assertSame( $subdir, $info['subdir'] );
     30                $this->assertFalse( $info['error'] );
    3131        }
    3232
    … …  
    3737                $subdir = gmstrftime( '/%Y/%m' );
    3838
    39                 $this->assertEquals( get_option( 'siteurl' ) . '/foo/bar' . $subdir, $info['url'] );
    40                 $this->assertEquals( ABSPATH . 'foo/bar' . $subdir, $info['path'] );
    41                 $this->assertEquals( $subdir, $info['subdir'] );
    42                 $this->assertEquals( false, $info['error'] );
     39                $this->assertSame( get_option( 'siteurl' ) . '/foo/bar' . $subdir, $info['url'] );
     40                $this->assertSame( ABSPATH . 'foo/bar' . $subdir, $info['path'] );
     41                $this->assertSame( $subdir, $info['subdir'] );
     42                $this->assertFalse( $info['error'] );
    4343        }
    4444
    … …  
    6060                $subdir = gmstrftime( '/%Y/%m' );
    6161
    62                 $this->assertEquals( '/baz' . $subdir, $info['url'] );
    63                 $this->assertEquals( $path . $subdir, $info['path'] );
    64                 $this->assertEquals( $subdir, $info['subdir'] );
    65                 $this->assertEquals( false, $info['error'] );
     62                $this->assertSame( '/baz' . $subdir, $info['url'] );
     63                $this->assertSame( $path . $subdir, $info['path'] );
     64                $this->assertSame( $subdir, $info['subdir'] );
     65                $this->assertFalse( $info['error'] );
    6666        }
    6767
    … …  
    7272                $info = _wp_upload_dir();
    7373
    74                 $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/uploads', $info['url'] );
    75                 $this->assertEquals( ABSPATH . 'wp-content/uploads', $info['path'] );
    76                 $this->assertEquals( '', $info['subdir'] );
    77                 $this->assertEquals( false, $info['error'] );
     74                $this->assertSame( get_option( 'siteurl' ) . '/wp-content/uploads', $info['url'] );
     75                $this->assertSame( ABSPATH . 'wp-content/uploads', $info['path'] );
     76                $this->assertSame( '', $info['subdir'] );
     77                $this->assertFalse( $info['error'] );
    7878        }
    7979
    … …  
    8686                $subdir = gmstrftime( '/%Y/%m' );
    8787
    88                 $this->assertEquals( 'http://' . WP_TESTS_DOMAIN . '/asdf' . $subdir, $info['url'] );
    89                 $this->assertEquals( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
    90                 $this->assertEquals( $subdir, $info['subdir'] );
    91                 $this->assertEquals( false, $info['error'] );
     88                $this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/asdf' . $subdir, $info['url'] );
     89                $this->assertSame( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
     90                $this->assertSame( $subdir, $info['subdir'] );
     91                $this->assertFalse( $info['error'] );
    9292        }
    9393
    … …  
    101101                $subdir = gmstrftime( '/%Y/%m' );
    102102
    103                 $this->assertEquals( get_option( 'siteurl' ) . '/wp-content/uploads' . $subdir, $info['url'] );
    104                 $this->assertEquals( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
    105                 $this->assertEquals( $subdir, $info['subdir'] );
    106                 $this->assertEquals( false, $info['error'] );
     103                $this->assertSame( get_option( 'siteurl' ) . '/wp-content/uploads' . $subdir, $info['url'] );
     104                $this->assertSame( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
     105                $this->assertSame( $subdir, $info['subdir'] );
     106                $this->assertFalse( $info['error'] );
    107107        }
    108108
Note: See TracChangeset for help on using the changeset viewer.