I might be missing something here but I have a very simple helper class that creates a directory:
// 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);
}
}
}
And associated test here:
// 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);
}
}
However I get a fatal error when running the test:
PHP Fatal error: Class 'File' not found in /my/app/folder/app/tests/lib/myapp/helpers/FileSystemHelperTest.php
I've looked at the docs for mocking a facade and I can't see where I'm going wrong. Any suggestions?
Thanks
Call to undefined method Illuminate\Support\Facades\Log::channel()
without it. – Sainthood