You are first off missing a leading slash here
new \Data\Api\Client
And I assume you are import the other two classes?
Can you show the class you are mocking?
Summer Sale! All accounts are 50% off this week.
Hello!
I'm working on my first ever package, and I'm really trying to keep a testing driven mindset while developing... and I'm struggling to understand how to emulate certain behaviors of the Laravel app in the package's tests.
The general idea is that the package has a main class Analytics and the Analytics object has a property called client, which should be an instance of another class, say Data\Api\Client.
The client credentials are configured in the .env file, so what I am trying to test is that the Analytics object is created properly and that the $client property is in fact an instance of Data\Api\Client.
What I have tried is this, but it gives me an error (shown below)
public function analytics_data_client()
{
//mock creating an instance of Analytics
//and then getting the client via getClient()
//and assert that the client is an instance of BetaAnalyticsDataClient
$this->mock(Analytics::class, function (MockInterface $mock) {
$mock->shouldReceive('getClient')
->andReturn(new Data\Api\Client());
});
}
but I get the error:
1) GarrettMassey\Analytics\Tests\AnalyticsTest::analytics_data_client
ErrorException: file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory
with several other messages beneath.
Any ideas or tips to writing tests like this?
@garrettmassey I would just set the full path in the config. Then you can overwrite it in the test
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . config('analytics.credentials_path') . config('analytics.credentials_file'));
and then in config
'credentials_path' => base_path(env('ANALYTICS_CREDENTIALS_PATH')),
Check the link above to testbench on how to set the config in tests
Please or to participate in this conversation.