情况如下:
我正在尝试为使用数据源的模型创建测试用例。数据源连接到 API。
我尝试了什么:
我尝试$useDbConfig
像这样将夹具的 var 设置为数据源。
class ProjectFixture extends CakeTestFixture {
public $useDbConfig = 'project';
public $useTable = false;
}
然后在我的模型测试中,这就是我所做的:
App::uses('Project', 'Model');
class ProjectTest extends CakeTestCase {
public $fixtures = array('app.project');
public function setUp() {
parent::setUp();
$this->Project = ClassRegistry::init('Project');
}
...
但是,当我运行测试时,我收到此错误消息:
Invalid datasource project for object Project
Error: An Internal Error Has Occurred.
Stack Trace
CORE/Cake/TestSuite/Fixture/CakeFixtureManager.php line 144 → CakeTestFixture->__construct()
CORE/Cake/TestSuite/Fixture/CakeFixtureManager.php line 78 → CakeFixtureManager->_loadFixtures(array)
CORE/Cake/TestSuite/CakeTestRunner.php line 52 → CakeFixtureManager->fixturize(ProjectTest)
CORE/Cake/TestSuite/CakeTestSuiteCommand.php line 111 → CakeTestRunner->doRun(PHPUnit_Framework_TestSuite, array)
CORE/Cake/TestSuite/CakeTestSuiteDispatcher.php line 242 → CakeTestSuiteCommand->run(array)
CORE/Cake/TestSuite/CakeTestSuiteDispatcher.php line 99 → CakeTestSuiteDispatcher->_runTestCase()
CORE/Cake/TestSuite/CakeTestSuiteDispatcher.php line 116 → CakeTestSuiteDispatcher->dispatch()
APP/webroot/test.php line 92 → CakeTestSuiteDispatcher::run()
有没有人尝试过这样做?我一直在网上搜索,但似乎找不到任何类似的资源。