Skip to content

Commit ed25dbb

Browse files
authored
[8.x] Remove 204 response and instead be explicit with ignores (#1187)
* Update UserController.php * Update Browser.php * Update UserController.php * Update Browser.php * some kinda test * void
1 parent 7f32e5a commit ed25dbb

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

src/Browser.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ class Browser
8585
*/
8686
public static $storeSourceAt;
8787

88+
/**
89+
* Console log messages to ignore when storing console logs.
90+
*
91+
* @var array
92+
*/
93+
public static $ignoreConsoleMessages = [
94+
'favicon.ico',
95+
];
96+
8897
/**
8998
* The browsers that support retrieving logs.
9099
*
@@ -481,7 +490,10 @@ public function screenshotElement($selector, $name)
481490
public function storeConsoleLog($name)
482491
{
483492
if (in_array($this->driver->getCapabilities()->getBrowserName(), static::$supportsRemoteLogs)) {
484-
$console = $this->driver->manage()->getLog('browser');
493+
$console = collect($this->driver->manage()->getLog('browser'))
494+
->reject(fn ($entry) => Str::contains($entry['message'] ?? '', static::$ignoreConsoleMessages))
495+
->values()
496+
->all();
485497

486498
if (! empty($console)) {
487499
$filePath = sprintf('%s/%s.log', rtrim(static::$storeConsoleLogAt, '/'), $name);

src/Http/Controllers/UserController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function user($guard = null)
3333
*
3434
* @param string $userId
3535
* @param string|null $guard
36-
* @return \Illuminate\Http\Response
36+
* @return void
3737
*/
3838
public function login($userId, $guard = null)
3939
{
@@ -46,15 +46,13 @@ public function login($userId, $guard = null)
4646
: $provider->retrieveById($userId);
4747

4848
Auth::guard($guard)->login($user);
49-
50-
return response(status: 204);
5149
}
5250

5351
/**
5452
* Log the user out of the application.
5553
*
5654
* @param string|null $guard
57-
* @return \Illuminate\Http\Response
55+
* @return void
5856
*/
5957
public function logout($guard = null)
6058
{
@@ -63,8 +61,6 @@ public function logout($guard = null)
6361
Auth::guard($guard)->logout();
6462

6563
Session::forget('password_hash_'.$guard);
66-
67-
return response(status: 204);
6864
}
6965

7066
/**

tests/Unit/BrowserTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,21 @@ public function test_can_enable_fit_on_failure()
314314
$this->assertTrue($this->browser->fitOnFailure);
315315
}
316316

317+
public function test_ignores_favicon_console_messages()
318+
{
319+
$driver = m::mock(stdClass::class);
320+
$driver->shouldReceive('manage->getLog')->with('browser')->andReturn([
321+
['message' => 'https://example.com/favicon.ico - Failed to load resource: the server responded with a status of 404 ()', 'level' => 'SEVERE'],
322+
]);
323+
$driver->shouldReceive('getCapabilities->getBrowserName')->andReturn(WebDriverBrowserType::CHROME);
324+
$browser = new Browser($driver);
325+
Browser::$storeConsoleLogAt = sys_get_temp_dir();
326+
327+
$browser->storeConsoleLog('ignore-test');
328+
329+
$this->assertFileDoesNotExist(sys_get_temp_dir().'/ignore-test.log');
330+
}
331+
317332
public function test_source_code_can_be_stored()
318333
{
319334
$this->driver->shouldReceive('getPageSource')->andReturn('source content');

0 commit comments

Comments
 (0)