Skip to content

Commit

Permalink
refactor: Remove TogglesHeadlessMode redundant methods
Browse files Browse the repository at this point in the history
laravel/dusk#1098

Laravel Dusk 8.x now defines these methods in class
Laravel\Dusk\TestCase so the stub classes that extend
TestCase don't need to redefine hasHeadlessDisabled()
and shouldStartMaximized().
  • Loading branch information
derekmd committed Oct 20, 2024
1 parent d798ea5 commit 0690a59
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
22 changes: 0 additions & 22 deletions src/Concerns/TogglesHeadlessMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,4 @@ protected function filterHeadlessArguments(array $args = [])
]);
})->values()->all();
}

/**
* Determine whether the Dusk command has disabled headless mode.
*
* @return bool
*/
protected function hasHeadlessDisabled()
{
return isset($_SERVER['DUSK_HEADLESS_DISABLED']) ||
isset($_ENV['DUSK_HEADLESS_DISABLED']);
}

/**
* Determine if the browser window should start maximized.
*
* @return bool
*/
protected function shouldStartMaximized()
{
return isset($_SERVER['DUSK_START_MAXIMIZED']) ||
isset($_ENV['DUSK_START_MAXIMIZED']);
}
}
23 changes: 23 additions & 0 deletions tests/Stubs/TogglesHeadlessStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Derekmd\Dusk\Tests\Stubs;

use Derekmd\Dusk\Concerns\TogglesHeadlessMode;
use Laravel\Dusk\TestCase;

class TogglesHeadlessStub extends TestCase
{
use TogglesHeadlessMode {
filterHeadlessArguments as filterHeadlessArgumentsProtected;
}

public function __construct()
{
parent::__construct('TogglesHeadless');
}

public function filterHeadlessArguments($args)
{
return $this->filterHeadlessArgumentsProtected($args);
}
}
10 changes: 4 additions & 6 deletions tests/TogglesHeadlessModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Derekmd\Dusk\Tests;

use Derekmd\Dusk\Concerns\TogglesHeadlessMode;
use Derekmd\Dusk\Tests\Stubs\TogglesHeadlessStub;
use PHPUnit\Framework\TestCase;

class TogglesHeadlessModeTest extends TestCase
{
use TogglesHeadlessMode;

protected function tearDown() : void
protected function tearDown(): void
{
unset($_ENV['DUSK_HEADLESS_DISABLED']);

Expand All @@ -20,7 +18,7 @@ public function test_building_arguments_with_headless_mode()
{
unset($_ENV['DUSK_HEADLESS_DISABLED']);

$args = $this->filterHeadlessArguments([
$args = (new TogglesHeadlessStub)->filterHeadlessArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
Expand All @@ -37,7 +35,7 @@ public function test_building_arguments_when_headless_mode_is_disabled()
{
$_ENV['DUSK_HEADLESS_DISABLED'] = true;

$args = $this->filterHeadlessArguments([
$args = (new TogglesHeadlessStub)->filterHeadlessArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
Expand Down

0 comments on commit 0690a59

Please sign in to comment.