Skip to content

Instantly share code, notes, and snippets.

@tareko
Created September 28, 2015 19:55
Show Gist options
  • Save tareko/7d68a06c4a6f512f0384 to your computer and use it in GitHub Desktop.
Save tareko/7d68a06c4a6f512f0384 to your computer and use it in GitHub Desktop.
Failure to properly load model inside model as a fixture
public function lastUpdated($id) {
//Set up new Shift model only if not already set (fixes problems with testing)
if(!$this->Shift) {
App::uses('Shift', 'Model');
$this->Shift = new Shift();
}
$calendar = $this->findById($id, array(
'start_date', 'end_date'));
$lastUpdated = $this->Shift->find('all', array(
'fields' => array('Shift.updated', 'Shift.date'),
'conditions' => array(
'Shift.date >=' => $calendar['Calendar']['start_date'],
'Shift.date <=' => $calendar['Calendar']['end_date'],
),
'order' => array(
'Shift.updated' => 'DESC',
)
));
return $lastUpdated['Shift']['updated'];
}
public function testLastUpdated () {
App::uses('Shift', 'Model');
$this->Shift = ClassRegistry::init('Shift');
$result = $this->Calendar->lastUpdated('1');
debug($result);
$expected = array(
'start_date' => '2011-12-01',
'end_date' => '2011-12-22'
);
//TODO: EXPECTED FAIL DUE TO nested model call.
$this->assertEquals($expected, $result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment