Skip to content

Commit

Permalink
Add additional test for findOrCreate()
Browse files Browse the repository at this point in the history
Show that the callback is optional.
  • Loading branch information
markstory committed Sep 22, 2014
1 parent 1f0eb1e commit 3701fd0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -3537,19 +3537,23 @@ public function testDebugInfo() {
*/
public function testFindOrCreate() {
$articles = TableRegistry::get('Articles');

$article = $articles->findOrCreate(['title' => 'Not there'], function ($article) {
$article->body = 'New body';
});

$this->assertFalse($article->isNew());
$this->assertNotNull($article->id);
$this->assertEquals('Not there', $article->title);
$this->assertEquals('New body', $article->body);

$article = $articles->findOrCreate(['title' => 'Not there']);
$this->assertFalse($article->isNew());
$this->assertNotNull($article->id);
$this->assertEquals('Not there', $article->title);

$article = $articles->findOrCreate(['title' => 'First Article'], function ($article) {
$this->fail('Should not be called for existing entities.');
});

$this->assertFalse($article->isNew());
$this->assertNotNull($article->id);
$this->assertEquals('First Article', $article->title);
Expand Down

0 comments on commit 3701fd0

Please sign in to comment.