Skip to content

Commit 8d99b0b

Browse files
committed
Add test case when is null
1 parent 7776cdc commit 8d99b0b

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

tests/TestCase/Model/Behavior/InsertBehaviorTest.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,30 @@ public function testInsertOnceWhenDuplicated()
222222
$this->assertCount(1, $actual, 'fail insert once.');
223223
}
224224

225+
/**
226+
* insertOnce() test when is null
227+
*
228+
* @return void
229+
*/
230+
public function testInsertOnceWhenIsNull()
231+
{
232+
$newData = [
233+
'title' => 'First Article',
234+
'body' => null,
235+
'published' => 1
236+
];
237+
$entity = $this->Articles->newEntity($newData);
238+
239+
$this->Articles->insertOnce($entity);
240+
241+
$actual = $this->Articles
242+
->find()
243+
->where($newData)
244+
->all();
245+
246+
$this->assertCount(1, $actual, 'fail insert once.');
247+
}
248+
225249
/**
226250
* insertOnce() test with conditions
227251
*
@@ -236,12 +260,12 @@ public function testInsertOnceWithConditions()
236260
];
237261
$entity = $this->Articles->newEntity($newData);
238262

239-
$condition = [
263+
$conditions = [
240264
'title' => 'Brand New First Article',
241265
'body' => 'Brand New First Article Body',
242266
];
243267

244-
$this->Articles->insertOnce($entity, $condition);
268+
$this->Articles->insertOnce($entity, $conditions);
245269

246270
$actual = $this->Articles
247271
->find()
@@ -268,16 +292,16 @@ public function testInsertOnceWhenDuplicatedWithConditions()
268292
];
269293
$entity = $this->Articles->newEntity($newData);
270294

271-
$condition = [
295+
$conditions = [
272296
'title' => 'First Article',
273297
'body' => 'First Article Body',
274298
];
275299

276-
$this->Articles->insertOnce($entity, $condition);
300+
$this->Articles->insertOnce($entity, $conditions);
277301

278302
$actual = $this->Articles
279303
->find()
280-
->where($condition)
304+
->where($conditions)
281305
->all();
282306

283307
$this->assertCount(1, $actual, 'fail insert once.');

0 commit comments

Comments
 (0)