forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCase.php
More file actions
118 lines (102 loc) · 3.35 KB
/
TestCase.php
File metadata and controls
118 lines (102 loc) · 3.35 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Tests;
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
use Illuminate\Database\DatabaseManager;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Bus;
use PDOException;
use ProcessMaker\Jobs\RefreshArtisanCaches;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestLock;
use ProcessMaker\Models\SecurityLog;
use ProcessMaker\Models\Setting;
abstract class TestCase extends BaseTestCase
{
use DatabaseTransactions;
use CreatesApplication;
use ArraySubsetAsserts;
public $withPermissions = false;
protected $skipTeardownPDOException = false;
/**
* Run additional setUps from traits.
*/
protected function setUp(): void
{
$this->skipTeardownPDOException = false;
parent::setUp();
$this->disableSetContentMiddleware();
foreach (get_class_methods($this) as $method) {
$imethod = strtolower($method);
if (strpos($imethod, 'setup') === 0 && $imethod !== 'setup') {
$this->$method();
}
}
}
/**
* Disable middleware that calls setContent() otherwise we can't use assertViewIs()
*/
private function disableSetContentMiddleware()
{
if (class_exists(\ProcessMaker\Package\SavedSearch\Http\Middleware\InjectJavascript::class)) {
$this->withoutMiddleware(\ProcessMaker\Package\SavedSearch\Http\Middleware\InjectJavascript::class);
}
if (class_exists(\ProcessMaker\Package\ProductAnalytics\Http\Middleware\ProductAnalyticsMiddleware::class)) {
$this->withoutMiddleware(\ProcessMaker\Package\ProductAnalytics\Http\Middleware\ProductAnalyticsMiddleware::class);
}
}
public function setUpMockScriptRunners(): void
{
config()->set('script-runners.php.runner', 'MockRunner');
config()->set('script-runners.lua.runner', 'MockRunner');
}
/**
* Calling the real config:cache command reconnects the database
* and since we're using transactions for our tests, we lose any data
* saved before the command is run. Instead, mock it out here.
*/
public function setUpMockConfigCache(): void
{
Bus::fake([
RefreshArtisanCaches::class,
]);
}
/**
* Run additional tearDowns from traits.
*/
protected function tearDown(): void
{
try {
parent::tearDown();
} catch (PDOException $e) {
if (!$this->skipTeardownPDOException) {
throw $e;
}
}
foreach (get_class_methods($this) as $method) {
$imethod = strtolower($method);
if (strpos($imethod, 'teardown') === 0 && $imethod !== 'teardown') {
$this->$method();
}
}
}
protected function withPersonalAccessClient()
{
$clients = app()->make('Laravel\Passport\ClientRepository');
try {
$clients->personalAccessClient();
} catch (\RuntimeException $e) {
Artisan::call('passport:install');
}
}
/**
* Connections transacts
*
* @return array
*/
protected function connectionsToTransact()
{
return ['processmaker', 'data'];
}
}