mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
make it possible to run this test on its own
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
This commit is contained in:
parent
46b28aae50
commit
35b4ac0286
1 changed files with 34 additions and 0 deletions
|
@ -353,6 +353,11 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
* @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);
|
||||
|
@ -372,6 +377,13 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
* @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');
|
||||
|
@ -389,4 +401,26 @@ class CakeTestCaseTest extends CakeTestCase {
|
|||
$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()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue