models.
Models looks like:
class User extends AppModel {
public $hasAndBelongsToMany = array(
'RatePlan',
);
}
class RatePlan extends AppModel {
public $hasAndBelongsToMany = array(
'User',
);
}
Test:
class SomeControllerTest extends CakeTestCase {
public function setUp() {
parent::setUp();
$this->RatePlanMock = $this->getMock(
'RatePlan',
array(),
array(),
'RatePlanMock'
);
$this->UserMock = $this->getMock(
'User',
array(),
array(),
'UserMock'
);
}
function testApiLevel() {
...
}
}
When I run test I got an error:
PHPUnit_Framework_Error_Notice
Trying to get property of non-object
Test case: SomeControllerTest(testApiLevel)
Stack trace:
D:\web_site\site\lib\Cake\Model\Model.php : 988
D:\web_site\site\lib\Cake\Model\Model.php : 914
D:\web_site\site\lib\Cake\Model\Model.php : 704
C:\Program Files (x86)\wamp\bin\php\php5.2.9-2\PEAR\PHPUnit\Framework
\MockObject\Generator.php : 190
D:\web_site\site\app\Vendor\PHPUnit\Framework\TestCase.php : 1035
D:\web_site\site\app\Test\Case\Controller\SomeControllerTest.php : 43
D:\web_site\site\app\Test\Case\Controller\SomeControllerTest.php : 27
D:\web_site\site\app\Vendor\PHPUnit\Framework\TestCase.php : 626
D:\web_site\site\app\Vendor\PHPUnit\Framework\TestResult.php : 666
D:\web_site\site\app\Vendor\PHPUnit\Framework\TestCase.php : 576
D:\web_site\site\lib\Cake\TestSuite\CakeTestCase.php : 81
D:\web_site\site\app\Vendor\PHPUnit\Framework\TestSuite.php : 757
D:\web_site\site\app\Vendor\PHPUnit\Framework\TestSuite.php : 733
D:\web_site\site\app\Vendor\PHPUnit\TextUI\TestRunner.php : 305
D:\web_site\site\lib\Cake\TestSuite\CakeTestRunner.php : 58
D:\web_site\site\lib\Cake\TestSuite\CakeTestSuiteCommand.php : 113
D:\web_site\site\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 252
D:\web_site\site\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 97
D:\web_site\site\lib\Cake\TestSuite\CakeTestSuiteDispatcher.php : 114
D:\web_site\site\app\webroot\test.php : 92
This points to D:\web_site\site\lib\Cake\Model\Model.php : 988
987: case 'joinTable':
988: $tables = array($this->table, $this->{$class}->table);
989: sort ($tables);
990: $data = $tables[0] . '_' . $tables[1];
991: break;
And $this->{$class}->table is really not set there for RatePlan table
So how to make mock for a model?
I need to test some methods inside model so it would be ok if it is
possible to mock only those methods, but not the whole class
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment