From 15638b1a2aa3e8d6ea1fdebac60baef6b63fa20b Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 19 Dec 2015 12:34:29 -0500 Subject: [PATCH] Increase coverage by covering another failure case. This path was untested before. --- .../ORM/Association/BelongsToManyTest.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/TestCase/ORM/Association/BelongsToManyTest.php b/tests/TestCase/ORM/Association/BelongsToManyTest.php index 7f7007748f4..9345fb972b0 100644 --- a/tests/TestCase/ORM/Association/BelongsToManyTest.php +++ b/tests/TestCase/ORM/Association/BelongsToManyTest.php @@ -671,6 +671,28 @@ public function emptyProvider() ]; } + /** + * Test that saveAssociated() fails on non-empty, non-iterable value + * + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Could not save tags, it cannot be traversed + * @return void + */ + public function testSaveAssociatedNotEmptyNotIterable() + { + $articles = TableRegistry::get('Articles'); + $assoc = $articles->belongsToMany('Tags', [ + 'saveStrategy' => BelongsToMany::SAVE_APPEND, + 'joinTable' => 'articles_tags', + ]); + $entity = new Entity([ + 'id' => 1, + 'tags' => 'oh noes', + ], ['markNew' => true]); + + $assoc->saveAssociated($entity); + } + /** * Test that saving an empty set on create works. *