I'm trying to test some code that calls the Google Drive API. Here's the code under test:
class GDrive {
...
public function __construct(\Google_Client $client = null) {
...
}
...
$service = new \Google_Service_Drive($this->client);
$root = $service->files->get($this->root, [
"supportsAllDrives" => true
]);
...
}
$this->client is a mock of \Google_Client.
Here's the test:
$mock = Mockery::mock(Google_Client::class);
$this->gDrive = new GDrive($mock);
$gDriveMock = m::mock('overload:\Google_Service_Drive');
$gDriveFilesMock = m::mock('\Google\Service\Drive\Resource\Files');
$gDriveMock->files = $gDriveFilesMock;
I'm trying to mock out the call to $service->files->get, but when the $root = $service->files->get line is executed in GDrive I get:
Undefined property: Google_Service_Drive::$files
If I don't (attempt to) mock the classes out then the code works ok.
I guess there's a problem with either (or both):
- My use of
overloadto mock the directly instantiatedGoogle_Service_Drive - The
->syntax for setting a property on the mock
I've tried not using aliases in the references to the Google Drive API, but it doesn't appear to help.