我可能在这里遗漏了一些东西,但我有一个非常简单的帮助类来创建一个目录:
// 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 致命错误:在 /my/app/folder/app/tests/lib/myapp/helpers/FileSystemHelperTest.php 中找不到类“文件”
我查看了模拟外观的文档,但我看不出哪里出错了。有什么建议么?
谢谢