-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCase.php
76 lines (65 loc) · 2.42 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
70
71
72
73
74
75
76
<?php
namespace EscolaLms\Consultations\Tests;
use EscolaLms\Auth\EscolaLmsAuthServiceProvider;
use EscolaLms\Auth\Models\User;
use EscolaLms\Auth\Tests\Models\Client;
use EscolaLms\Categories\EscolaLmsCategoriesServiceProvider;
use EscolaLms\Consultations\AuthServiceProvider;
use EscolaLms\Consultations\EscolaLmsConsultationsServiceProvider;
use EscolaLms\Consultations\Providers\EventServiceProvider;
use EscolaLms\ModelFields\ModelFieldsServiceProvider;
use Illuminate\Testing\TestResponse;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use Spatie\Permission\PermissionServiceProvider;
class TestCase extends \EscolaLms\Core\Tests\TestCase
{
protected ?TestResponse $response;
protected function setUp(): void
{
parent::setUp();
Passport::useClientModel(Client::class);
}
protected function getPackageProviders($app)
{
return [
...parent::getPackageProviders($app),
EscolaLmsAuthServiceProvider::class,
EscolaLmsConsultationsServiceProvider::class,
EscolaLmsCategoriesServiceProvider::class,
PermissionServiceProvider::class,
PassportServiceProvider::class,
AuthServiceProvider::class,
EventServiceProvider::class,
ModelFieldsServiceProvider::class,
];
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('auth.providers.users.model', User::class);
$app['config']->set('passport.client_uuids', true);
$app['config']->set('database.connections.mysql.strict', false);
$app['config']->set('app.debug', (bool) env('APP_DEBUG', true));
}
public function assertApiResponse(array $actualData)
{
$this->assertApiSuccess();
$response = json_decode($this->response->getContent(), true);
$responseData = $response['data'];
$this->assertNotEmpty($responseData['id']);
$this->assertModelData($actualData, $responseData);
}
public function assertApiSuccess()
{
$this->response->assertJson(['success' => true]);
}
public function assertModelData(array $actualData, array $expectedData)
{
foreach ($actualData as $key => $value) {
if (in_array($key, ['created_at', 'updated_at'])) {
continue;
}
$this->assertEquals($actualData[$key], $expectedData[$key]);
}
}
}