From 2487ebb71afa5fdde7e09ff5fef3d34e818f6e85 Mon Sep 17 00:00:00 2001
From: lucashedding <lucashedding@1463982.no-reply.drupal.org>
Date: Wed, 19 Dec 2018 10:29:06 -0600
Subject: [PATCH] Issue #3019796 by heddn, mikelutz: Run D.O. tests with
 deprecation notices enabled

---
 src/Plugin/migrate/process/EntityLookup.php               | 5 +++++
 .../Kernel/Plugin/migrate/process/EntityGenerateTest.php  | 8 ++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/Plugin/migrate/process/EntityLookup.php b/src/Plugin/migrate/process/EntityLookup.php
index 0d044b44..7ed4e84d 100644
--- a/src/Plugin/migrate/process/EntityLookup.php
+++ b/src/Plugin/migrate/process/EntityLookup.php
@@ -261,6 +261,11 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
     $query = $this->entityManager->getStorage($this->lookupEntityType)
       ->getQuery()
       ->condition($this->lookupValueKey, $value, $multiple ? 'IN' : NULL);
+    // Sqlite and possibly others returns data in a non-deterministic order.
+    // Make it deterministic.
+    if ($multiple) {
+      $query->sort($this->lookupValueKey, 'DESC');
+    }
 
     if ($this->lookupBundleKey) {
       $query->condition($this->lookupBundleKey, $this->lookupBundle);
diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php
index fb9f7891..3a529181 100644
--- a/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php
+++ b/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php
@@ -171,14 +171,14 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
                 foreach ($valueToCheck as $key => $expectedValue) {
                   if (empty($expectedValue)) {
                     if (!$entity->{$property}->isEmpty()) {
-                      $this->assertTrue($entity->{$property}[0]->entity->$key->isEmpty(), "Expected value is empty but field $property.$key is not empty.");
+                      $this->assertTrue($entity->{$property}[0]->entity->{$key}->isEmpty(), "Expected value is empty but field $property.$key is not empty.");
                     }
                     else {
-                      $this->assertTrue($entity->{$property}->isEmpty(), "FOOBAR Expected value is empty but field $property is not empty.");
+                      $this->assertTrue($entity->{$property}->isEmpty(), "Expected value is empty but field $property is not empty.");
                     }
                   }
                   elseif ($entity->{$property}->getValue()) {
-                    $this->assertEquals($expectedValue, $entity->{$property}[$valueID]->entity->$key->value);
+                    $this->assertEquals($expectedValue, $entity->get($property)->offsetGet($valueID)->entity->{$key}->value);
                   }
                   else {
                     $this->fail("Expected value: $expectedValue does not exist in $property.");
@@ -192,7 +192,7 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa
               foreach ($value as $key => $expectedValue) {
                 if (empty($expectedValue)) {
                   if (!$entity->{$property}->isEmpty()) {
-                    $this->assertTrue($entity->{$property}[0]->entity->$key->isEmpty(), "Expected value is empty but field $property.$key is not empty.");
+                    $this->assertTrue($entity->{$property}[0]->entity->{$key}->isEmpty(), "Expected value is empty but field $property.$key is not empty.");
                   }
                   else {
                     $this->assertTrue($entity->{$property}->isEmpty(), "BINBAZ Expected value is empty but field $property is not empty.");
-- 
GitLab