-
-
Notifications
You must be signed in to change notification settings - Fork 79
/
TestCase.php
103 lines (86 loc) · 2.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace Apiato\Core\Abstracts\Tests\PhpUnit;
use Apiato\Core\Traits\HashIdTrait;
use Apiato\Core\Traits\TestCaseTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsAuthHelperTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsMockHelperTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsRequestHelperTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsResponseHelperTrait;
use Apiato\Core\Traits\TestsTraits\PhpUnit\TestsUploadHelperTrait;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Illuminate\Foundation\Testing\TestCase as LaravelTestCase;
/**
* Class TestCase
*
* @author Mahmoud Zalt <mahmoud@zalt.me>
*/
abstract class TestCase extends LaravelTestCase
{
use TestCaseTrait,
TestsRequestHelperTrait,
TestsResponseHelperTrait,
TestsMockHelperTrait,
TestsAuthHelperTrait,
TestsUploadHelperTrait,
HashIdTrait,
RefreshDatabase;
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl;
/**
* Setup the test environment, before each test.
*
* @return void
*/
public function setUp()
{
parent::setUp();
}
/**
* Reset the test environment, after each test.
*/
public function tearDown()
{
$this->usingInMemoryDatabase()
? $this->artisan('migrate:reset')
: parent::tearDown();
}
/**
* Refresh the in-memory database.
* Overridden refreshTestDatabase Trait
*
* @return void
*/
protected function refreshInMemoryDatabase()
{
// migrate the database
$this->migrateDatabase();
// seed the database
$this->seed();
// Install Passport Client for Testing
$this->setupPassportOAuth2();
$this->app[Kernel::class]->setArtisan(null);
}
/**
* Refresh a conventional test database.
* Overridden refreshTestDatabase Trait
*
* @return void
*/
protected function refreshTestDatabase()
{
if (! RefreshDatabaseState::$migrated) {
$this->artisan('migrate:fresh');
$this->seed();
$this->setupPassportOAuth2();
$this->app[Kernel::class]->setArtisan(null);
RefreshDatabaseState::$migrated = true;
}
$this->beginDatabaseTransaction();
}
}