-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCase.php
69 lines (58 loc) · 2.31 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Getsno\Relesys\Tests;
use Mockery;
use Getsno\Relesys\HttpClient\HttpClient;
use Getsno\Relesys\RelesysServiceProvider;
use Getsno\Relesys\Api\UserManagement\Users;
use Getsno\Relesys\Api\UserManagement\UserGroups;
use Getsno\Relesys\Api\UserManagement\Departments;
use Getsno\Relesys\Facades\RelesysFacade as Relesys;
use Getsno\Relesys\Api\UserManagement\CustomFields;
use Getsno\Relesys\Api\Communication\Communication;
class TestCase extends \Orchestra\Testbench\TestCase
{
public const TEST_CLIENT_ID = '00000000-0000-0000-0000-000000000000';
public const TEST_CLIENT_SECRET = '666';
protected function getPackageProviders($app): array
{
return [
RelesysServiceProvider::class,
];
}
protected function defineEnvironment($app): void
{
// Set relesys config as it's required for Service provider to test via facade
$clientId = config('relesys.client_id');
$clientSecret = config('relesys.client_secret');
if (empty($clientId) && empty($clientSecret)) {
$app['config']->set('relesys.client_id', self::TEST_CLIENT_ID);
$app['config']->set('relesys.client_secret', self::TEST_CLIENT_SECRET);
}
}
/**
* Fake the requests if credentials are missing
*/
protected function isTestingInIsolation(): bool
{
$clientId = config('relesys.client_id');
$clientSecret = config('relesys.client_secret');
return $clientId === self::TEST_CLIENT_ID && $clientSecret === self::TEST_CLIENT_SECRET;
}
protected function mockFacadeIfTestingInIsolation(string $apiType, ?callable $mockCallback = null): void
{
if ($this->isTestingInIsolation()) {
$relesysHttpClientMock = $this->mock(HttpClient::class, $mockCallback);
$target = match ($apiType) {
'users' => Users::class,
'departments' => Departments::class,
'userGroups' => UserGroups::class,
'customFields' => CustomFields::class,
'communication' => Communication::class,
};
$apiMock = Mockery::mock($target, [$relesysHttpClientMock])->makePartial();
Relesys::shouldReceive($apiType)
->once()
->andReturn($apiMock);
}
}
}