Skip to content

Commit

Permalink
Code refactoring due to comments @ #8824 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoniossss committed May 15, 2016
1 parent 456c6fc commit 7727e20
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 31 deletions.
24 changes: 0 additions & 24 deletions src/ORM/Exception/MissingAssociationException.php

This file was deleted.

10 changes: 5 additions & 5 deletions src/ORM/Marshaller.php
Expand Up @@ -59,6 +59,7 @@ public function __construct(Table $table)
* Build the map of property => association names.
*
* @param array $options List of options containing the 'associated' key.
* @throws \InvalidArgumentException
* @return array
*/
protected function _buildPropertyMap($options)
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase/ORM/MarshallerTest.php
Expand Up @@ -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',
Expand All @@ -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']]);
}

/**
Expand Down

0 comments on commit 7727e20

Please sign in to comment.