Skip to content

Commit d56e1ff

Browse files
committed
Update api docs and add test for exception case.
1 parent 2cf8641 commit d56e1ff

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

Cake/ORM/Associations.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public function drop($alias) {
9191
* @param array $associations The list of associations to save parents from.
9292
* associations not in this list will not be saved.
9393
* @param array $options The options for the save operation.
94-
* @return Entity modified entity
95-
* @throws new \InvalidArgumentExceptio when an unknown alias is used.
94+
* @return Entity Modified entity
9695
*/
9796
public function saveParents(Table $table, Entity $entity, $associations, $options = []) {
9897
if (empty($associations)) {
@@ -113,7 +112,7 @@ public function saveParents(Table $table, Entity $entity, $associations, $option
113112
* @param array $associations The list of associations to save children from.
114113
* associations not in this list will not be saved.
115114
* @param array $options The options for the save operation.
116-
* @return boolean success
115+
* @return Entity Modified entity
117116
*/
118117
public function saveChildren(Table $table, Entity $entity, $associations, $options) {
119118
if (empty($associations)) {
@@ -131,7 +130,8 @@ public function saveChildren(Table $table, Entity $entity, $associations, $optio
131130
* @param array $options Original options
132131
* @param boolean $owningSide Compared with association classes'
133132
* isOwningSide method.
134-
* @return void
133+
* @return Entity modified entity.
134+
* @throws new \InvalidArgumentException When an unknown alias is used.
135135
*/
136136
protected function _saveAssociations($table, $entity, $associations, $options, $owningSide) {
137137
foreach ($associations as $alias => $nested) {

Cake/Test/TestCase/ORM/AssociationsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,28 @@ public function testSaveChildrenFiltered() {
214214
);
215215
$this->assertSame($entity, $result);
216216
}
217+
218+
/**
219+
* Test exceptional case.
220+
*
221+
* @expectedException \InvalidArgumentException
222+
* @expectedExceptionMessage Cannot save Profiles, it is not associated to Users
223+
*/
224+
public function testErrorOnUnknownAlias() {
225+
$table = $this->getMock(
226+
'Cake\ORM\Table',
227+
['save'],
228+
[['alias' => 'Users']]);
229+
230+
$entity = new Entity();
231+
$entity->set('profile', ['key' => 'value']);
232+
233+
$this->associations->saveChildren(
234+
$table,
235+
$entity,
236+
['Profiles'],
237+
['atomic' => true]
238+
);
239+
}
240+
217241
}

0 commit comments

Comments
 (0)