[wp-trac] [WordPress Trac] #46073: Off by one error in Imagick testsuite

WordPress Trac noreply at wordpress.org
Tue Jan 22 22:47:41 UTC 2019


#46073: Off by one error in Imagick testsuite
------------------------------+-----------------------------
 Reporter:  Fuegas            |      Owner:  (none)
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:  trunk
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 Since a while we're seeing the test suite fail on our platform (
 https://make.wordpress.org/hosting/test-results/r44689/savviibot-r44689/
 ). We investigated the cause of this failure and saw the following output:

 {{{
 There were 2 failures:

 1) Tests_Image_Editor_Imagick::test_rotate
 Failed asserting that two arrays are equal.
 --- Expected
 +++ Actual
 @@ @@
  Array (
 -    'r' => 127
 -    'g' => 179
 -    'b' => 229
 +    'r' => 126
 +    'g' => 178
 +    'b' => 228
      'a' => 1
  )

 .../wp-test-runner/tests/phpunit/tests/image/editorImagick.php:436

 2) Tests_Image_Editor_Imagick::test_flip
 Failed asserting that two arrays are equal.
 --- Expected
 +++ Actual
 @@ @@
  Array (
 -    'r' => 127
 -    'g' => 179
 -    'b' => 229
 +    'r' => 126
 +    'g' => 178
 +    'b' => 228
      'a' => 1
  )

 .../wp-test-runner/tests/phpunit/tests/image/editorImagick.php:455
 }}}

 We took a closer look at the tests and found the following code in
 tests/phpunit/tests/image/editorImagick.php (starting at line 420):

 {{{#!php
 <?php
   /**
    * Test rotating an image 180 deg
    */
   public function test_rotate() {
     $file = DIR_TESTDATA . '/images/gradient-square.jpg';

     $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
     $imagick_image_editor->load();

     $property = new ReflectionProperty( $imagick_image_editor, 'image' );
     $property->setAccessible( true );

     $color_top_left = $property->getValue( $imagick_image_editor
 )->getImagePixelColor( 1, 1 )->getColor();

     $imagick_image_editor->rotate( 180 );

     $this->assertEquals( $color_top_left, $property->getValue(
 $imagick_image_editor )->getImagePixelColor( 99, 99 )->getColor() );
   }

   /**
    * Test flipping an image
    */
   public function test_flip() {
     $file = DIR_TESTDATA . '/images/gradient-square.jpg';

     $imagick_image_editor = new WP_Image_Editor_Imagick( $file );
     $imagick_image_editor->load();

     $property = new ReflectionProperty( $imagick_image_editor, 'image' );
     $property->setAccessible( true );

     $color_top_left = $property->getValue( $imagick_image_editor
 )->getImagePixelColor( 1, 1 )->getColor();

     $imagick_image_editor->flip( true, false );

     $this->assertEquals( $color_top_left, $property->getValue(
 $imagick_image_editor )->getImagePixelColor( 0, 99 )->getColor() );
   }
 }}}

 The tests uses an image that is 100 x 100 pixels. So the first pixel is at
 (0, 0) and on the far end that is (99, 99). The rotation test compares the
 color of (1, 1) with the color at (99, 99) which is actually one pixel too
 far on x-axis and one too far on the y-axis. The second test flips the
 image on the horizontal axis and tests the color of (1, 1) with (0, 99).
 The movement of one pixel on the x-axis has no effect as the image is a
 linear gradient, but for consistence I'd suggest using X = 1 for the
 sampling and comparison. However, the comparison on row 99 is off by one.
 I've added a diff with a proposed fix, if I run the test suite with this
 patch the suite completes successfully:

 {{{
 $ php phpunit.phar -c phpunit.xml.dist
 tests/phpunit/tests/image/editorImagick.php

 PHP version: 7.2.14

 Installing...
 Running as single site... To run multisite, use -c
 tests/phpunit/multisite.xml
 Not running ajax tests. To execute these, use --group ajax.
 Not running ms-files tests. To execute these, use --group ms-files.
 Not running external-http tests. To execute these, use --group external-
 http.
 PHPUnit 5.7.27 by Sebastian Bergmann and contributors.

 ..............                                                    14 / 14
 (100%)

 You should really fix these slow tests (>150ms)...
  1. 249ms to run Tests_Image_Editor_Imagick:test_multi_resize


 Time: 8.95 seconds, Memory: 32.25MB

 OK (14 tests, 43 assertions)
 }}}

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


More information about the wp-trac mailing list