-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from phug-php/1.x
Provide cleanup tools
- Loading branch information
Showing
13 changed files
with
244 additions
and
67 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Phug\DevTool\Command; | ||
|
||
use Phug\DevTool\AbstractCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class CoverageReportPrepareCommand extends AbstractCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setName('coverage:report:prepare') | ||
->setHelp('This command install the coverage report utils.'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$phpVersion = $input->getOption('php-version'); | ||
|
||
if (!empty($phpVersion)) { | ||
if (!preg_match('/^'.preg_quote($phpVersion).'(\D.*)?$/', PHP_VERSION)) { | ||
$output->writeln( | ||
'Test report ignored since PHP version ('.PHP_VERSION.')'. | ||
' does not match '.$phpVersion.'.' | ||
); | ||
|
||
return 0; | ||
} | ||
$output->writeln( | ||
'<fg=green>Proceed test report since PHP version ('.PHP_VERSION.') '. | ||
'matches '.$phpVersion.'.</>' | ||
); | ||
} | ||
|
||
return $this->getApplication()->runCoverageReporterPreparation(); | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
|
||
namespace Phug\DevTool; | ||
|
||
use PHPUnit\Framework\TestCase as PHPUnitTestCase; | ||
|
||
class TestCase extends PHPUnitTestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $tempDirectory; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected $tempDirectoryFiles; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function saveTempDirectoryFilesList() | ||
{ | ||
$this->tempDirectory = $this->tempDirectory ?: sys_get_temp_dir(); | ||
|
||
$this->tempDirectoryFiles = scandir($this->tempDirectory); | ||
} | ||
|
||
/** | ||
* @after | ||
*/ | ||
public function cleanupTempDirectory() | ||
{ | ||
$files = scandir($this->tempDirectory); | ||
|
||
foreach (array_diff($files, $this->tempDirectoryFiles) as $file) { | ||
$this->removeFile($this->tempDirectory.DIRECTORY_SEPARATOR.$file); | ||
} | ||
} | ||
|
||
protected function removeFile($file) | ||
{ | ||
if (is_dir($file)) { | ||
$this->emptyDirectory($file); | ||
rmdir($file); | ||
|
||
return; | ||
} | ||
|
||
unlink($file); | ||
} | ||
|
||
protected function emptyDirectory($dir) | ||
{ | ||
if (!is_dir($dir)) { | ||
return; | ||
} | ||
|
||
foreach (scandir($dir) as $file) { | ||
if ($file !== '.' && $file !== '..') { | ||
$this->removeFile($dir.'/'.$file); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.