【发布时间】:2017-05-11 08:47:55
【问题描述】:
在使用 ./cake test app AllModel 在 Cakephp 应用程序中测试我的所有模型之前,我必须进行一些操作。我使用 Cakephp 2.9.7。这个函数在AllModelTest.php 中声明,看起来像下面这样:
class AllModelTest extends CakeTestSuite {
public static function suite() {
$suite = new CakeTestSuite('All model tests');
$suite->addTestDirectory(TESTS . 'Case/Model');
return $suite;
}
}
如何访问我的模型并直接从该文件进行一些操作?我试过App::uses('MyModel', 'Model'); - 那是行不通的。 $this我不能使用,因为它给了我错误PHP Fatal error: Using $this when not in object context in path....
【问题讨论】:
-
你能试试 $this->loadModel('CakeTestSuite');
-
$this->loadModel('Your Model Name'); -
@AlivetoDie 我不能打电话给
$this因为我收到错误PHP Fatal error: Using $this when not in object context in path... -
这可能对你有用:andy-carter.com/blog/…
标签: php cakephp cakephp-2.9