-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
132 additions
and
7,821 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Leeovery\LaravelPlaywright\Actions; | ||
|
||
use Dotenv\Dotenv; | ||
use Illuminate\Support\Facades\Artisan; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
abstract class BaseEnvAction | ||
{ | ||
protected string $backupEnvName = '.env.backup'; | ||
|
||
protected function restoreEnvironment(): void | ||
{ | ||
copy(base_path($this->backupEnvName), base_path('.env')); | ||
unlink(base_path($this->backupEnvName)); | ||
} | ||
|
||
protected function swapEnvironment(): void | ||
{ | ||
copy(base_path('.env'), base_path($this->backupEnvName)); | ||
copy(base_path($this->getPlaywrightEnvFile()), base_path('.env')); | ||
} | ||
|
||
protected function getPlaywrightEnvFile(): string | ||
{ | ||
$envName = config('laravel-playwright.env.name'); | ||
$environment = app()->environment(); | ||
if (file_exists(base_path($file = "{$envName}.{$environment}"))) { | ||
return $file; | ||
} | ||
|
||
if (file_exists(base_path($envName))) { | ||
return $envName; | ||
} | ||
|
||
abort(404, 'Playwright env file missing'); | ||
} | ||
|
||
protected function refreshEnvironment(): void | ||
{ | ||
Artisan::call('optimize:clear'); | ||
Dotenv::createMutable(base_path())->load(); | ||
Artisan::call('optimize'); | ||
DB::reconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Leeovery\LaravelPlaywright\Actions; | ||
|
||
class EnvSetupAction extends BaseEnvAction | ||
{ | ||
public function __invoke() | ||
{ | ||
if (! file_exists($envFile = base_path($this->getPlaywrightEnvFile()))) { | ||
return; | ||
} | ||
|
||
if (file_get_contents(base_path('.env')) !== file_get_contents($envFile)) { | ||
$this->swapEnvironment(); | ||
} | ||
|
||
$this->refreshEnvironment(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Leeovery\LaravelPlaywright\Actions; | ||
|
||
class EnvTeardownAction extends BaseEnvAction | ||
{ | ||
public function __invoke() | ||
{ | ||
if (file_exists(base_path($this->backupEnvName))) { | ||
$this->restoreEnvironment(); | ||
$this->refreshEnvironment(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters