Browse Source

Add additional test for findOrCreate()

Show that the callback is optional.
mark_story 11 years ago
parent
commit
3701fd0572
1 changed files with 6 additions and 2 deletions
  1. 6 2
      tests/TestCase/ORM/TableTest.php

+ 6 - 2
tests/TestCase/ORM/TableTest.php

@@ -3537,19 +3537,23 @@ class TableTest extends \Cake\TestSuite\TestCase {
  */
 	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);