-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathTestCase.php
60 lines (45 loc) · 1.3 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
<?php
abstract class TestCase extends Laravel\Lumen\Testing\TestCase
{
// protected $baseUrl = 'http://realworld.test:8080';
protected $loggedInUser;
protected $user;
protected $headers;
protected static $migrationsRun = false;
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
return require __DIR__ . '/../bootstrap/app.php';
}
public function setUp(): void
{
parent::setUp();
if (!static::$migrationsRun) {
$this->artisan('migrate:refresh');
$this->artisan('db:seed');
static::$migrationsRun = true;
}
$this->beforeApplicationDestroyed(function () {
// $this->artisan('migrate:rollback');
});
$users = factory(\App\Models\User::class)->times(2)->create();
$this->loggedInUser = $users[0];
$this->user = $users[1];
$this->headers = [
'Authorization' => "Token {$this->loggedInUser->token}"
];
}
/**
* Get the JSON data from the response and return as assoc. array
*
* @return array
*/
public function getResponseData()
{
return json_decode(json_encode($this->response->getData()), true);
}
}