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/image/editor.php

    r47198 r48937  
    7575
    7676        // Check default value.
    77         $this->assertEquals( 82, $editor->get_quality() );
     77        $this->assertSame( 82, $editor->get_quality() );
    7878
    7979        // Ensure the quality filters do not have precedence if created after editor instantiation.
    8080        $func_100_percent = array( $this, 'return_integer_100' );
    8181        add_filter( 'wp_editor_set_quality', $func_100_percent );
    82         $this->assertEquals( 82, $editor->get_quality() );
     82        $this->assertSame( 82, $editor->get_quality() );
    8383
    8484        $func_95_percent = array( $this, 'return_integer_95' );
    8585        add_filter( 'jpeg_quality', $func_95_percent );
    86         $this->assertEquals( 82, $editor->get_quality() );
     86        $this->assertSame( 82, $editor->get_quality() );
    8787
    8888        // Ensure set_quality() works and overrides the filters.
    8989        $this->assertTrue( $editor->set_quality( 75 ) );
    90         $this->assertEquals( 75, $editor->get_quality() );
     90        $this->assertSame( 75, $editor->get_quality() );
    9191
    9292        // Get a new editor to clear default quality state.
     
    9696
    9797        // Ensure jpeg_quality filter applies if it exists before editor instantiation.
    98         $this->assertEquals( 95, $editor->get_quality() );
     98        $this->assertSame( 95, $editor->get_quality() );
    9999
    100100        // Get a new editor to clear jpeg_quality state.
     
    104104
    105105        // Ensure wp_editor_set_quality filter applies if it exists before editor instantiation.
    106         $this->assertEquals( 100, $editor->get_quality() );
     106        $this->assertSame( 100, $editor->get_quality() );
    107107
    108108        // Clean up.
     
    131131
    132132        // Test with no parameters.
    133         $this->assertEquals( 'canola-100x50.jpg', wp_basename( $editor->generate_filename() ) );
     133        $this->assertSame( 'canola-100x50.jpg', wp_basename( $editor->generate_filename() ) );
    134134
    135135        // Test with a suffix only.
    136         $this->assertEquals( 'canola-new.jpg', wp_basename( $editor->generate_filename( 'new' ) ) );
     136        $this->assertSame( 'canola-new.jpg', wp_basename( $editor->generate_filename( 'new' ) ) );
    137137
    138138        // Test with a destination dir only.
    139         $this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) );
     139        $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) );
    140140
    141141        // Test with a suffix only.
    142         $this->assertEquals( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) );
     142        $this->assertSame( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) );
    143143
    144144        // Combo!
    145         $this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );
     145        $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );
    146146    }
    147147
     
    167167        $property->setValue( $editor, $size );
    168168
    169         $this->assertEquals( $size, $editor->get_size() );
     169        $this->assertSame( $size, $editor->get_size() );
    170170    }
    171171
     
    190190        $property->setValue( $editor, $size );
    191191
    192         $this->assertEquals( '100x50', $editor->get_suffix() );
     192        $this->assertSame( '100x50', $editor->get_suffix() );
    193193    }
    194194}
Note: See TracChangeset for help on using the changeset viewer.