Skip to content

Commit

Permalink
Update api docs and add test for exception case.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 19, 2013
1 parent 2cf8641 commit d56e1ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Cake/ORM/Associations.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public function drop($alias) {
* @param array $associations The list of associations to save parents from.
* associations not in this list will not be saved.
* @param array $options The options for the save operation.
* @return Entity modified entity
* @throws new \InvalidArgumentExceptio when an unknown alias is used.
* @return Entity Modified entity
*/
public function saveParents(Table $table, Entity $entity, $associations, $options = []) {
if (empty($associations)) {
Expand All @@ -113,7 +112,7 @@ public function saveParents(Table $table, Entity $entity, $associations, $option
* @param array $associations The list of associations to save children from.
* associations not in this list will not be saved.
* @param array $options The options for the save operation.
* @return boolean success
* @return Entity Modified entity
*/
public function saveChildren(Table $table, Entity $entity, $associations, $options) {
if (empty($associations)) {
Expand All @@ -131,7 +130,8 @@ public function saveChildren(Table $table, Entity $entity, $associations, $optio
* @param array $options Original options
* @param boolean $owningSide Compared with association classes'
* isOwningSide method.
* @return void
* @return Entity modified entity.
* @throws new \InvalidArgumentException When an unknown alias is used.
*/
protected function _saveAssociations($table, $entity, $associations, $options, $owningSide) {
foreach ($associations as $alias => $nested) {
Expand Down
24 changes: 24 additions & 0 deletions Cake/Test/TestCase/ORM/AssociationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,28 @@ public function testSaveChildrenFiltered() {
);
$this->assertSame($entity, $result);
}

/**
* Test exceptional case.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Cannot save Profiles, it is not associated to Users
*/
public function testErrorOnUnknownAlias() {
$table = $this->getMock(
'Cake\ORM\Table',
['save'],
[['alias' => 'Users']]);

$entity = new Entity();
$entity->set('profile', ['key' => 'value']);

$this->associations->saveChildren(
$table,
$entity,
['Profiles'],
['atomic' => true]
);
}

}

0 comments on commit d56e1ff

Please sign in to comment.