From 4acec33562e4e1230092eee7d76c2b8061ffc914 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 29 Mar 2018 14:46:34 +0100 Subject: [PATCH] FIX Fixed bug in config merging priorities so that config values set by extensions are now least important instead of most important --- .../Config/Middleware/ExtensionMiddleware.php | 2 +- tests/php/ORM/DataObjectTest.php | 116 ++++++++++-------- 2 files changed, 67 insertions(+), 51 deletions(-) diff --git a/src/Core/Config/Middleware/ExtensionMiddleware.php b/src/Core/Config/Middleware/ExtensionMiddleware.php index 3edbc5b0d..a79eaa44d 100644 --- a/src/Core/Config/Middleware/ExtensionMiddleware.php +++ b/src/Core/Config/Middleware/ExtensionMiddleware.php @@ -39,7 +39,7 @@ class ExtensionMiddleware implements Middleware } foreach ($this->getExtraConfig($class, $config, $excludeMiddleware) as $extra) { - $config = Priority::mergeArray($extra, $config); + $config = Priority::mergeArray($config, $extra); } return $config; } diff --git a/tests/php/ORM/DataObjectTest.php b/tests/php/ORM/DataObjectTest.php index 7aaf739a5..dbc46f090 100644 --- a/tests/php/ORM/DataObjectTest.php +++ b/tests/php/ORM/DataObjectTest.php @@ -1062,72 +1062,88 @@ class DataObjectTest extends SapphireTest // Test logical fields (including composite) $teamSpecifications = $schema->fieldSpecs(DataObjectTest\Team::class); + $expected = array( + 'ID', + 'ClassName', + 'LastEdited', + 'Created', + 'Title', + 'DatabaseField', + 'ExtendedDatabaseField', + 'CaptainID', + 'FounderID', + 'HasOneRelationshipID', + 'ExtendedHasOneRelationshipID' + ); + $actual = array_keys($teamSpecifications); + sort($expected); + sort($actual); $this->assertEquals( - array( - 'ID', - 'ClassName', - 'LastEdited', - 'Created', - 'Title', - 'DatabaseField', - 'ExtendedDatabaseField', - 'CaptainID', - 'FounderID', - 'HasOneRelationshipID', - 'ExtendedHasOneRelationshipID' - ), - array_keys($teamSpecifications), + $expected, + $actual, 'fieldSpecifications() contains all fields defined on instance: base, extended and foreign keys' ); $teamFields = $schema->databaseFields(DataObjectTest\Team::class, false); + $expected = array( + 'ID', + 'ClassName', + 'LastEdited', + 'Created', + 'Title', + 'DatabaseField', + 'ExtendedDatabaseField', + 'CaptainID', + 'FounderID', + 'HasOneRelationshipID', + 'ExtendedHasOneRelationshipID' + ); + $actual = array_keys($teamFields); + sort($expected); + sort($actual); $this->assertEquals( - array( - 'ID', - 'ClassName', - 'LastEdited', - 'Created', - 'Title', - 'DatabaseField', - 'ExtendedDatabaseField', - 'CaptainID', - 'FounderID', - 'HasOneRelationshipID', - 'ExtendedHasOneRelationshipID' - ), - array_keys($teamFields), + $expected, + $actual, 'databaseFields() contains only fields defined on instance, including base, extended and foreign keys' ); $subteamSpecifications = $schema->fieldSpecs(DataObjectTest\SubTeam::class); + $expected = array( + 'ID', + 'ClassName', + 'LastEdited', + 'Created', + 'Title', + 'DatabaseField', + 'ExtendedDatabaseField', + 'CaptainID', + 'FounderID', + 'HasOneRelationshipID', + 'ExtendedHasOneRelationshipID', + 'SubclassDatabaseField', + 'ParentTeamID', + ); + $actual = array_keys($subteamSpecifications); + sort($expected); + sort($actual); $this->assertEquals( - array( - 'ID', - 'ClassName', - 'LastEdited', - 'Created', - 'Title', - 'DatabaseField', - 'ExtendedDatabaseField', - 'CaptainID', - 'FounderID', - 'HasOneRelationshipID', - 'ExtendedHasOneRelationshipID', - 'SubclassDatabaseField', - 'ParentTeamID', - ), - array_keys($subteamSpecifications), + $expected, + $actual, 'fieldSpecifications() on subclass contains all fields, including base, extended and foreign keys' ); $subteamFields = $schema->databaseFields(DataObjectTest\SubTeam::class, false); + $expected = array( + 'ID', + 'SubclassDatabaseField', + 'ParentTeamID', + ); + $actual = array_keys($subteamFields); + sort($expected); + sort($actual); $this->assertEquals( - array( - 'ID', - 'SubclassDatabaseField', - 'ParentTeamID', - ), - array_keys($subteamFields), + $expected, + $actual, 'databaseFields() on subclass contains only fields defined on instance' ); }