Skip to content

Commit

Permalink
Add test for save many with exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Jun 14, 2018
1 parent ba4e523 commit 382273f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -3203,6 +3203,37 @@ public function testSaveManyFailed()
}
}

/**
* Test saveMany() with failed save due to an exception
*
* @return void
*/
public function testSaveManyFailedWithException()
{
$table = $this->getTableLocator()
->get('authors');
$entities = [
new Entity(['name' => 'mark']),
new Entity(['name' => 'jose'])
];

$table->getEventManager()->on('Model.beforeSave', function (Event $event, Entity $entity) {
if ($entity->name === 'jose') {
throw new \Exception('Oh noes');
}
});

$this->expectException(\Exception::class);

try {
$table->saveMany($entities);
} finally {
foreach ($entities as $entity) {
$this->assertTrue($entity->isNew());
}
}
}

/**
* Test simple delete.
*
Expand Down

0 comments on commit 382273f

Please sign in to comment.