I have something like the following set up in Laravel:
100年:
class MyController extends BaseController {
const MAX_FILE_SIZE = 10000;
// ....
}
In /app/tests/MyControllerTest.php
:
class MyControllerTest extends TestCase {
public function myDataProvider() {
return [
[ MyController::MAX_FILE_SIZE ]
];
}
/**
* @dataProvider myDataProvider
*/
public function testMyController($a) {
// Just an example
$this->assertTrue(1 == 1);
}
}
但是,当我运行vendor/bin/phpunit
时,我得到以下错误:
PHP Fatal error: Class 'Controller' not found in /home/me/my-app/app/controllers/BaseController.php on line 3 Fatal error: Class 'Controller' not found in /home/me/my-app/app/controllers/BaseController.php on line 3
如果我删除myDataProvider()
中对MyController
类的引用并将其替换为文字常量,则测试成功完成.
In addition, I can place references to MyController::MAX_FILE_SIZE
inside the actual testMyController()
method, and the test also completes successfully.
It appears that the autoloading setup for Laravel framework classes isn't being set up until after the data provider method is being called, but before the actual test methods are called. Is there any way around this so that I can access Laravel framework classes from within a PHPUnit data provider?
NOTE:我直接从命令行调用PHPUnit,而不是从IDE(比如NetBeans)中调用.我知道有些人对此有意见,但我认为这不适用于我的问题.