I have DocumentService class like this:
namespace App\Services;
use App\Api\StorageServiceInterface;
class DocumentService
{
private $storageService;
function __construct(StorageServiceInterface $storageService)
{
$this->storageService = $storageService;
}
public function createFolder(User $user)
{
$folderData = $this->storageService->createFolder(
'/Users/' . $user->email
);
$user->folder = $folderData['folder_id'];
$user->save();
return $user->folder;
}
}
Partial implmentation of the LocalStorageService
.
namespace App\Api;
class LocalStorageService implements StorageServiceInterface
{
public function createFolder($folder)
{
...
return ['folder_id' => $folder_id, 'folder_path' => $folder_path];
}
}
I'm testing the DocumentService
class. I'm trying to mock the createFolder()
method on the LocalStorageService
which implements StorageServiceInterface
.
How do I configure this stub to return the array with PHPUnit?
I've tried this: (partial code from my test)
namespace Tests\Unit\Services;
use App\User;
use App\Api\LocalStorageService;
public function testCreateFolder()
{
$user = factory(User::class)->make();
$localStorageService = $this->createMock(LocalStorageService::class);
$localStorageService->method('createFolder')
->willReturn(array('folder_id' => 'random_id', 'folder_path' => ("/Users/" . $user->email)));
}
But I'm only getting random_id.