我可能在这里遗漏了一些东西,但我有一个非常简单的帮助类,它创建了一个目录:
// Helper class <?PHP namespace MyApp\Helpers; use User; use File; class FileSystemHelper { protected $userBin = 'users/uploads'; public function createUserUploadBin(User $user) { $path = $this->userBin . '/' . $user->id; if ( ! File::isDirectory($path)) { File::makeDirectory($path); } } }
以及相关的测试:
// Associated test class <?PHP use MyApp\Helpers\FileSystemHelper; class FileSystemHelperTest extends TestCase { protected $fileSystemHelper; public function setUp() { $this->fileSystemHelper = new FileSystemHelper; } public function testNewUploadBinCreatedWhenNotExists() { $user = new User; // this would be mocked File::shouldReceive('makeDirectory')->once(); $this->fileSystemHelper->createUserUploadBin($user); } }
但是在运行测试时出现致命错误:
PHP Fatal error: Class ‘File’ not found in /my/app/folder/app/tests/lib/myapp/helpers/FileSystemHelperTest.PHP
我看过嘲笑门面的文档,我看不出我哪里出错了.有什么建议?
谢谢
我在文档中错过了这个:
Note: If you define your own setUp method,be sure to call parent::setUp.
打电话说就是解决了这个问题.卫生署!