@@ -3531,29 +3531,34 @@ public function testDebugInfo() {
3531
3531
}
3532
3532
3533
3533
/**
3534
- * Test the findOrNew method.
3534
+ * Test the findOrCreate method.
3535
3535
*
3536
3536
* @return void
3537
3537
*/
3538
- public function testFindOrNew () {
3538
+ public function testFindOrCreate () {
3539
3539
$ articles = TableRegistry::get ('Articles ' );
3540
- $ article = $ articles ->findOrCreate (['title ' => 'Not there ' ], ['body ' => 'New body ' ]);
3540
+ $ article = $ articles ->findOrCreate (['title ' => 'Not there ' ], function ($ article ) {
3541
+ $ article ->body = 'New body ' ;
3542
+ });
3541
3543
3542
3544
$ this ->assertFalse ($ article ->isNew ());
3543
3545
$ this ->assertNotNull ($ article ->id );
3544
3546
$ this ->assertEquals ('Not there ' , $ article ->title );
3545
3547
$ this ->assertEquals ('New body ' , $ article ->body );
3546
3548
3547
- $ article = $ articles ->findOrCreate (['title ' => 'First Article ' ], ['body ' => 'New body ' ]);
3549
+ $ article = $ articles ->findOrCreate (['title ' => 'First Article ' ], function ($ article ) {
3550
+ $ this ->fail ('Should not be called for existing entities. ' );
3551
+ });
3548
3552
3549
3553
$ this ->assertFalse ($ article ->isNew ());
3550
3554
$ this ->assertNotNull ($ article ->id );
3551
3555
$ this ->assertEquals ('First Article ' , $ article ->title );
3552
- $ this ->assertNotEquals ('New body ' , $ article ->body );
3553
3556
3554
3557
$ article = $ articles ->findOrCreate (
3555
3558
['author_id ' => 2 , 'title ' => 'First Article ' ],
3556
- ['published ' => 'N ' , 'body ' => 'New body ' ]
3559
+ function ($ article ) {
3560
+ $ article ->set (['published ' => 'N ' , 'body ' => 'New body ' ]);
3561
+ }
3557
3562
);
3558
3563
$ this ->assertFalse ($ article ->isNew ());
3559
3564
$ this ->assertNotNull ($ article ->id );
0 commit comments