From 7727e202cc1a0b5302189bc768dd8372d98192ea Mon Sep 17 00:00:00 2001 From: Sebastian Choina Date: Sun, 15 May 2016 18:09:06 +0200 Subject: [PATCH] Code refactoring due to comments @ https://github.com/cakephp/cakephp/pull/8824#discussion_r63280504 --- .../Exception/MissingAssociationException.php | 24 ------------------- src/ORM/Marshaller.php | 10 ++++---- tests/TestCase/ORM/MarshallerTest.php | 5 ++-- 3 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 src/ORM/Exception/MissingAssociationException.php diff --git a/src/ORM/Exception/MissingAssociationException.php b/src/ORM/Exception/MissingAssociationException.php deleted file mode 100644 index dea6795bb10..00000000000 --- a/src/ORM/Exception/MissingAssociationException.php +++ /dev/null @@ -1,24 +0,0 @@ - association names. * * @param array $options List of options containing the 'associated' key. + * @throws \InvalidArgumentException * @return array */ protected function _buildPropertyMap($options) @@ -78,11 +79,10 @@ protected function _buildPropertyMap($options) $assoc = $this->_table->association($key); if ($assoc) { $map[$assoc->property()] = ['association' => $assoc] + $nested + ['associated' => []]; - } else { - if (substr($key, 0, 1) !== "_") { // if $key is a special underscored field eg _ids or _joinData - throw new MissingAssociationException([$this->_table->alias(), $key]); - } - + continue; + } + if (substr($key, 0, 1) !== "_") { // if $key is not a special underscored field eg _ids or _joinData + throw new \InvalidArgumentException(vsprintf("%s is not associated with %s",[$this->_table->alias(), $key])); } } return $map; diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index c72fc656fb6..883fcf7c95a 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -1135,10 +1135,11 @@ public function testManyAssociations() /** * Test if exceptin is raised when called with [associated=>NonExistingAssociation] * Previously such association has been simply ignored + * @expectedException \InvalidArgumentException + * @return void */ public function testManyInvalidAssociation() { - $this->expectException(MissingAssociationException::class); $data = [ [ 'comment' => 'First post', @@ -1156,7 +1157,7 @@ public function testManyInvalidAssociation() ], ]; $marshall = new Marshaller($this->comments); - $result = $marshall->many($data, ['associated' => ['Users','People']]); + $marshall->many($data, ['associated' => ['Users','People']]); } /**