I wrote the testAdd() method and try to debug the $this->Article->getInsertID(); which currently returns null while debug($articles) correctly shows the newly inserted data.
public function testAdd() {
$data = array(
'Article' => array(
'title' => 'Fourth Title',
'content' => 'Fourth Title Body',
'published' => '1',
'created' => '2015-05-18 10:40:34',
'updated' => '2015-05019 10:23:34'
)
);
$this->_testAction('/articles/add', array('method' => 'post', 'data' => $data));
$articles = $this->Article->find('first', array('order' => array('id DESC')));
debug($articles);
debug($this->Article->getInsertID);
// return null.
}
Why does $this->Article->getInsertID() return null?
$this->Article->getInsertIDin your example code, should it not read$this->Article->getInsertID()?$this->assertEqual(4, $this->Article->getInsertID)and it shows the `Failed asserting that 4 matches expected null' errors.