Skip to content

Commit

Permalink
make it possible to run this test on its own
Browse files Browse the repository at this point in the history
Without setting up paths to the test_app - two of the tests will fail

Verify/demonstrate how to mock a model without a model existing
  • Loading branch information
AD7six committed Aug 3, 2013
1 parent 46b28aa commit 35b4ac0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/Cake/Test/Case/TestSuite/CakeTestCaseTest.php
Expand Up @@ -353,6 +353,11 @@ public function testAssertTextNotContains() {
* @return void
*/
public function testGetMockForModel() {
App::build(array(
'Model' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Model' . DS
)
), App::RESET);
$Post = $this->getMockForModel('Post');

$this->assertInstanceOf('Post', $Post);
Expand All @@ -372,6 +377,13 @@ public function testGetMockForModel() {
* @return void
*/
public function testGetMockForModelWithPlugin() {
App::build(array(
'Plugin' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
)
), App::RESET);
CakePlugin::load('TestPlugin');
$this->getMockForModel('TestPlugin.TestPluginAppModel');
$TestPluginComment = $this->getMockForModel('TestPlugin.TestPluginComment');

$result = ClassRegistry::init('TestPlugin.TestPluginComment');
Expand All @@ -389,4 +401,26 @@ public function testGetMockForModelWithPlugin() {
$this->assertTrue($TestPluginComment->save(array()));
$this->assertFalse($TestPluginComment->save(array()));
}

/**
* testGetMockForModelModel
*
* @return void
*/
public function testGetMockForModelModel() {
$Mock = $this->getMockForModel('Model', array('save'), array('name' => 'Comment'));

$result = ClassRegistry::init('Comment');
$this->assertInstanceOf('Model', $result);

$Mock->expects($this->at(0))
->method('save')
->will($this->returnValue(true));
$Mock->expects($this->at(1))
->method('save')
->will($this->returnValue(false));

$this->assertTrue($Mock->save(array()));
$this->assertFalse($Mock->save(array()));
}
}

0 comments on commit 35b4ac0

Please sign in to comment.