Problem/Motivation

See https://www.drupal.org/pift-ci-job/1604603

There was 1 failure:

1) Drupal\KernelTests\Core\Database\SelectTest::testUnion
First query returned correct name.
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'George'

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

catch created an issue. See original summary.

mradcliffe’s picture

It looks like there isn't any explicit order by. Not sure why 10 behaves differently here when 9 or 12 do not, but order by is still important in those versions as well. Could it be pg_tgrm?

I'm not sure if we could programmatically add an order when the query is compiled.

The first query includes both George and Ringo, but those could be in any order. I think this should work to change the test. I don't have time to create a patch.

    $query_1 = $this->connection->select('test', 't')
      ->fields('t', ['name'])
      ->condition('age', [27, 28], 'IN')
      ->orderBy('name');
andypost’s picture

Status: Active » Needs review
StatusFileSize
new710 bytes

This test does not use ordering so could be simplified

xjm’s picture

Status: Needs review » Needs work

#3 still seems to fail.

andypost’s picture

pg 12.1 also has 10 a time field errors in queries

catch’s picture

1) Drupal\KernelTests\Core\Database\SelectTest::testUnion
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'George'
-    1 => 'Ringo'
+    0 => 'Ringo'
+    1 => 'George'
 )

We need to sort the arrays before comparison, looks like there is a $canonicalize param to do that:

https://api.drupal.org/api/drupal/vendor%21sebastian%21comparator%21src%...

mondrake’s picture

#7 that argument is deprecated. Maybe assertEqualsCanonicalizing will do, it is supported since PHPUnit8.

catch’s picture

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new724 bytes
new611 bytes
xjm’s picture

Queued a 8.9.x/Postgres 9.5 version to make sure this is safe for backport, as well as a few other flavors of database (Postgres and otherwise) given recent experience. We can expect the Postgres 12 one to fail with different issues, but this one shouldn't be in its list anymore.

xjm’s picture

#10 failed on 8.9.x / Postgres 9.1 with:

Drupal\KernelTests\Core\Database\SchemaTest
fail: [Other] Line 0 of sites/default/files/simpletest/phpunit-239.xml:
PHPunit Test failed to complete; Error: PHPUnit 7.5.20 by Sebastian Bergmann and contributors.

Testing Drupal\KernelTests\Core\Database\SchemaTest
..S...FF......                                                    14 / 14 (100%)

Time: 2.21 minutes, Memory: 4.00 MB

There were 2 failures:

1) Drupal\KernelTests\Core\Database\SchemaTest::testSchemaChangePrimaryKey with data set "composite_primary_key" (array('test_field', 'other_test_field'), array('test_field_renamed', 'other_test_field'))
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'test_field_renamed'
-    1 => 'other_test_field'
+    0 => 'other_test_field'
+    1 => 'test_field_renamed'
 )

/var/www/html/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php:858

2) Drupal\KernelTests\Core\Database\SchemaTest::testSchemaChangePrimaryKey with data set "composite_primary_key_different_order" (array('other_test_field', 'test_field'), array('other_test_field', 'test_field_renamed'))
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => 'other_test_field'
-    1 => 'test_field_renamed'
+    0 => 'test_field_renamed'
+    1 => 'other_test_field'
 )

/var/www/html/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php:858

FAILURES!
Tests: 14, Assertions: 1023, Failures: 2, Skipped: 1.
History

...but that's a fail I see in HEAD sometimes, so requeuing that environment

catch’s picture

Do we have an issue for that? Looks like another possible case for assertEqualsCanonicalizing

andypost’s picture

It sounds like deja vu with assert equals vs identical before

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Meanwhile, the retest passed. I think this fix is ready to go.

xjm’s picture

gábor hojtsy’s picture

Hm, according to #8, the assertEqualsCanonicalizing() method in the fix was introduced in PHPUnit 8. Drupal 9 was updated to require at least PHPUnit 8 in https://www.drupal.org/node/3113653 but Drupal 8.9 still has "phpunit/phpunit": "^6.5 || ^7", in https://git.drupalcode.org/project/drupal/-/blob/8.9.x/composer.json (I was looking to see if we maybe allow PHPUnit 8 with newer PHP versions in Drupal 8.9 as well, but did not find evidence).

Given all of that and that https://phpunit.readthedocs.io/en/7.0/search.html?q=assertEqualsCanonica... comes back empty (assertEqualsCanonicalizing() not mentioned in PHPUnit 7 docs), I am a bit puzzled how can this pass on Drupal 8.9.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Upon further URL hackery I found that it still does not appear in https://phpunit.readthedocs.io/en/7.4/assertions.html#assertequalscanoni... but it starts appearing in https://phpunit.readthedocs.io/en/7.5/assertions.html#assertequalscanoni... so this fix would require us to move to at least PHPUnit 7.5 as well.

catch’s picture

Status: Needs work » Reviewed & tested by the community

Let's get this into 9.0.x then backport to 8.9.x using the deprecated arg to assertEquals. We shouldn't be introducing new deprecated code usages in 9.x either.

  • Gábor Hojtsy committed 3594d55 on 9.0.x
    Issue #3118454 by catch, andypost, xjm, Gábor Hojtsy, mradcliffe,...
gábor hojtsy’s picture

Version: 9.0.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

That's a good approach as well.

catch’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new731 bytes

I couldn't get the $canonicalize parameter to work, but this does the same thing in practice and should pass on 8.9.x

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Added an SQLite test to be safe, but RTBC assuming they all pass.

xjm’s picture

For reviewers: the 10 Postgres 12 failures are expected and will be addressed in #3118591: Datetime-related test failures on PostgreSQL 12 The minimum requirement for this issue is that the test pass on the other databases tested above.

  • Gábor Hojtsy committed dfd8213 on 8.9.x
    Issue #3118454 by catch, andypost, xjm, Gábor Hojtsy, mradcliffe,...

  • Gábor Hojtsy committed 3a86f13 on 8.8.x
    Issue #3118454 by catch, andypost, xjm, Gábor Hojtsy, mradcliffe,...
gábor hojtsy’s picture

Version: 8.9.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Fixed

Superb, thanks for this version.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.