Skip to content

Commit

Permalink
[6.x] Refactor redundant purging methods. (#886)
Browse files Browse the repository at this point in the history
* [6.x] Refactor redundant purging methods.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* Fixes indent.

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone authored Mar 18, 2021
1 parent 5a40b1a commit aaee050
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions src/Console/DuskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,9 @@ protected function env()
*/
protected function purgeScreenshots()
{
$path = base_path('tests/Browser/screenshots');

if (! is_dir($path)) {
return;
}

$files = Finder::create()->files()
->in($path)
->name('failure-*');

foreach ($files as $file) {
@unlink($file->getRealPath());
}
$this->purgeDebuggingFiles(
base_path('tests/Browser/screenshots'), 'failure-*'
);
}

/**
Expand All @@ -163,19 +153,9 @@ protected function purgeScreenshots()
*/
protected function purgeConsoleLogs()
{
$path = base_path('tests/Browser/console');

if (! is_dir($path)) {
return;
}

$files = Finder::create()->files()
->in($path)
->name('*.log');

foreach ($files as $file) {
@unlink($file->getRealPath());
}
$this->purgeDebuggingFiles(
base_path('tests/Browser/console'), '*.log'
);
}

/**
Expand All @@ -185,15 +165,27 @@ protected function purgeConsoleLogs()
*/
protected function purgeSourceLogs()
{
$path = base_path('tests/Browser/source');
$this->purgeDebuggingFiles(
base_path('tests/Browser/source'), '*.txt'
);
}

/**
* Purge debugging files based on path and patterns.
*
* @param string $path
* @param string $patterns
* @return void
*/
protected function purgeDebuggingFiles($path, $patterns)
{
if (! is_dir($path)) {
return;
}

$files = Finder::create()->files()
->in($path)
->name('*.txt');
->name($patterns);

foreach ($files as $file) {
@unlink($file->getRealPath());
Expand Down

0 comments on commit aaee050

Please sign in to comment.