diff --git a/src/Console/DuskCommand.php b/src/Console/DuskCommand.php index e924c7cda..40b21a438 100644 --- a/src/Console/DuskCommand.php +++ b/src/Console/DuskCommand.php @@ -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-*' + ); } /** @@ -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' + ); } /** @@ -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());