From 8c33a391a089c105dae619209149e72ca54a84a0 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 14 Mar 2019 14:53:41 +0100 Subject: [PATCH] Fix assertArrayEquals() calls with bogus 3rd parameter This issue came up in I8a49143, see https://integration.wikimedia.org/ci/job/mediawiki-quibble-vendor-postgres-php70-docker/2453/console The third parameter of assertArrayEquals() is called $ordered and is meant to take the order of elements into account. Providing a string sets this to true. The SQL query in ChangesListSpecialPageTest seems to behave a bit random in Postgres and does not always return the elements in the same order. This is fine. It's just the assertion that was to strict, by accident. I found a few more instances of the same issue with a regular expression. In most cases I intentionally changed it to assertSame() because the order of elements is actually guaranteed by the code, and needs to be (e.g. mixing width and height of an image would be fatal). Change-Id: Ice66cab873a7271d55809a486ce28cf637e43e33 --- tests/phpunit/includes/media/DjVuTest.php | 6 +++--- .../includes/specialpage/ChangesListSpecialPageTest.php | 3 +-- tests/phpunit/maintenance/categoryChangesAsRdfTest.php | 4 ++-- tests/phpunit/structure/ResourcesTest.php | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/includes/media/DjVuTest.php b/tests/phpunit/includes/media/DjVuTest.php index dbc0d2fbd5..d9b5d824dd 100644 --- a/tests/phpunit/includes/media/DjVuTest.php +++ b/tests/phpunit/includes/media/DjVuTest.php @@ -25,7 +25,7 @@ class DjVuTest extends MediaWikiMediaTestCase { } public function testGetImageSize() { - $this->assertArrayEquals( + $this->assertSame( [ 2480, 3508, 'DjVu', 'width="2480" height="3508"' ], $this->handler->getImageSize( null, $this->filePath . '/LoremIpsum.djvu' ), 'Test file LoremIpsum.djvu should have a size of 2480 * 3508' @@ -51,8 +51,8 @@ class DjVuTest extends MediaWikiMediaTestCase { public function testGetPageDimensions() { $file = $this->dataFile( 'LoremIpsum.djvu', 'image/x.djvu' ); - $this->assertArrayEquals( - [ 2480, 3508 ], + $this->assertSame( + [ 'width' => 2480, 'height' => 3508 ], $this->handler->getPageDimensions( $file, 1 ), 'Page 1 of test file LoremIpsum.djvu should have a size of 2480 * 3508' ); diff --git a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php index 584b141c2c..2ce097b5be 100644 --- a/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php +++ b/tests/phpunit/includes/specialpage/ChangesListSpecialPageTest.php @@ -613,8 +613,7 @@ class ChangesListSpecialPageTest extends AbstractChangesListSpecialPageTestCase 'Learner1', 'Learner2', 'Learner3', 'Learner4', 'Experienced1', ], - $this->fetchUsers( [ 'learner', 'experienced' ], $now ), - 'Learner and more experienced' + $this->fetchUsers( [ 'learner', 'experienced' ], $now ) ); } diff --git a/tests/phpunit/maintenance/categoryChangesAsRdfTest.php b/tests/phpunit/maintenance/categoryChangesAsRdfTest.php index f5a47d5101..521705e16e 100644 --- a/tests/phpunit/maintenance/categoryChangesAsRdfTest.php +++ b/tests/phpunit/maintenance/categoryChangesAsRdfTest.php @@ -242,7 +242,7 @@ class CategoryChangesAsRdfTest extends MediaWikiLangTestCase { $this->assertFileContains( $testFileName, $sparql ); $processed = $processedProperty->getValue( $dumpScript ); - $expectedProcessed = $preProcessed; + $expectedProcessed = array_keys( $preProcessed ); foreach ( $result as $row ) { if ( isset( $row->_processed ) ) { $this->assertArrayHasKey( $row->_processed, $processed, @@ -250,7 +250,7 @@ class CategoryChangesAsRdfTest extends MediaWikiLangTestCase { $expectedProcessed[] = $row->_processed; } } - $this->assertArrayEquals( $expectedProcessed, array_keys( $processed ), + $this->assertSame( $expectedProcessed, array_keys( $processed ), 'Processed array has wrong items' ); } diff --git a/tests/phpunit/structure/ResourcesTest.php b/tests/phpunit/structure/ResourcesTest.php index 776dee1b4f..f41ab3a11f 100644 --- a/tests/phpunit/structure/ResourcesTest.php +++ b/tests/phpunit/structure/ResourcesTest.php @@ -155,7 +155,7 @@ class ResourcesTest extends MediaWikiTestCase { $css = file_get_contents( $basepath . 'comments.css' ); $files = CSSMin::getLocalFileReferences( $css, $basepath ); $expected = [ $basepath . 'not-commented.gif' ]; - $this->assertArrayEquals( + $this->assertSame( $expected, $files, 'Url(...) expression in comment should be omitted.' -- 2.20.1