1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Testing; |
4
|
|
|
|
5
|
|
|
use Facebook\WebDriver\Chrome\ChromeOptions; |
6
|
|
|
use Facebook\WebDriver\Remote\DesiredCapabilities; |
7
|
|
|
use Facebook\WebDriver\Remote\RemoteWebDriver; |
8
|
|
|
use Illuminate\Support\Facades\Facade; |
9
|
|
|
use Laravel\Dusk\Browser; |
10
|
|
|
use Laravel\Dusk\TestCase as BaseTestCase; |
11
|
|
|
use LaravelZero\Framework\Providers\CommandRecorder\CommandRecorderRepository; |
12
|
|
|
use NunoMaduro\Collision\ArgumentFormatter; |
13
|
|
|
use Tests\CreatesApplication; |
14
|
|
|
|
15
|
|
|
abstract class DuskTestCase extends BaseTestCase |
16
|
|
|
{ |
17
|
|
|
use CreatesApplication; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Setup the test environment. |
21
|
|
|
*/ |
22
|
|
|
protected function setUp(): void |
23
|
|
|
{ |
24
|
|
|
// \LaravelZero\Framework\Testing\TestCase instead \Illuminate\Foundation\Testing\TestCase |
25
|
|
|
if (! $this->app) { |
26
|
|
|
$this->refreshApplication(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$this->setUpTraits(); |
30
|
|
|
|
31
|
|
|
foreach ($this->afterApplicationCreatedCallbacks as $callback) { |
32
|
|
|
call_user_func($callback); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
Facade::clearResolvedInstances(); |
36
|
|
|
|
37
|
|
|
if (class_exists(\Illuminate\Database\Eloquent\Model::class)) { |
|
|
|
|
38
|
|
|
\Illuminate\Database\Eloquent\Model::setEventDispatcher($this->app['events']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$this->setUpHasRun = true; |
42
|
|
|
|
43
|
|
|
// \Laravel\Dusk\TestCase |
44
|
|
|
|
45
|
|
|
Browser::$baseUrl = 'http://localhost:8080'; |
46
|
|
|
// Browser::$baseUrl = $this->baseUrl(); |
47
|
|
|
|
48
|
|
|
Browser::$storeScreenshotsAt = base_path('tests/Browser/screenshots'); |
49
|
|
|
|
50
|
|
|
Browser::$storeConsoleLogAt = base_path('tests/Browser/console'); |
51
|
|
|
|
52
|
|
|
Browser::$storeSourceAt = base_path('tests/Browser/source'); |
53
|
|
|
|
54
|
|
|
Browser::$userResolver = function () { |
55
|
|
|
return $this->user(); |
56
|
|
|
}; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Assert that a command was called using the given arguments. |
61
|
|
|
* |
62
|
|
|
* @param string $command |
63
|
|
|
* @param array $arguments |
64
|
|
|
*/ |
65
|
|
|
protected function assertCommandCalled(string $command, array $arguments = []): void |
66
|
|
|
{ |
67
|
|
|
$argumentsAsString = (new ArgumentFormatter)->format($arguments); |
68
|
|
|
$recorder = app(CommandRecorderRepository::class); |
69
|
|
|
|
70
|
|
|
static::assertTrue($recorder->exists($command, $arguments), |
71
|
|
|
'Failed asserting that \''.$command.'\' was called with the given arguments: '.$argumentsAsString); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Assert that a command was not called using the given arguments. |
76
|
|
|
* |
77
|
|
|
* @param string $command |
78
|
|
|
* @param array $arguments |
79
|
|
|
*/ |
80
|
|
|
protected function assertCommandNotCalled(string $command, array $arguments = []): void |
81
|
|
|
{ |
82
|
|
|
$argumentsAsString = (new ArgumentFormatter)->format($arguments); |
83
|
|
|
$recorder = app(CommandRecorderRepository::class); |
84
|
|
|
|
85
|
|
|
static::assertFalse($recorder->exists($command, $arguments), |
86
|
|
|
'Failed asserting that \''.$command.'\' was not called with the given arguments: '.$argumentsAsString); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Prepare for Dusk test execution. |
91
|
|
|
* |
92
|
|
|
* @beforeClass |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
public static function prepare() |
97
|
|
|
{ |
98
|
|
|
if (! static::runningInSail()) { |
99
|
|
|
static::startChromeDriver(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Create the RemoteWebDriver instance. |
105
|
|
|
* |
106
|
|
|
* @return \Facebook\WebDriver\Remote\RemoteWebDriver |
107
|
|
|
*/ |
108
|
|
|
protected function driver() |
109
|
|
|
{ |
110
|
|
|
$options = (new ChromeOptions)->addArguments(collect([ |
|
|
|
|
111
|
|
|
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080', |
112
|
|
|
])->unless($this->hasHeadlessDisabled(), function ($items) { |
113
|
|
|
return $items->merge([ |
114
|
|
|
'--disable-gpu', |
115
|
|
|
'--headless', |
116
|
|
|
]); |
117
|
|
|
})->all()); |
118
|
|
|
|
119
|
|
|
return RemoteWebDriver::create( |
120
|
|
|
$_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515', |
121
|
|
|
DesiredCapabilities::chrome()->setCapability( |
122
|
|
|
ChromeOptions::CAPABILITY, $options |
123
|
|
|
) |
124
|
|
|
); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Determine whether the Dusk command has disabled headless mode. |
129
|
|
|
* |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
protected function hasHeadlessDisabled() |
133
|
|
|
{ |
134
|
|
|
return isset($_SERVER['DUSK_HEADLESS_DISABLED']) || |
135
|
|
|
isset($_ENV['DUSK_HEADLESS_DISABLED']); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Determine if the browser window should start maximized. |
140
|
|
|
* |
141
|
|
|
* @return bool |
142
|
|
|
*/ |
143
|
|
|
protected function shouldStartMaximized() |
144
|
|
|
{ |
145
|
|
|
return isset($_SERVER['DUSK_START_MAXIMIZED']) || |
146
|
|
|
isset($_ENV['DUSK_START_MAXIMIZED']); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths