Skip to content

Commit

Permalink
Use piping instead of creating a file for php -l linting commandline
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Apr 9, 2018
1 parent cac00f5 commit 0fe2318
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions tests/Mutator/AbstractMutatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Infection\Mutator\Util\Mutator;
use Infection\Mutator\Util\MutatorConfig;
use Infection\Tests\Fixtures\SimpleMutatorVisitor;
use Infection\Utils\TmpDirectoryCreator;
use Infection\Visitor\CloneVisitor;
use Infection\Visitor\FullyQualifiedClassNameVisitor;
use Infection\Visitor\ParentConnectorVisitor;
Expand All @@ -22,7 +21,6 @@
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;

abstract class AbstractMutatorTestCase extends TestCase
{
Expand All @@ -31,21 +29,6 @@ abstract class AbstractMutatorTestCase extends TestCase
*/
protected $mutator;

/**
* @var Filesystem
*/
private $fileSystem;

/**
* @var string
*/
private $workspace;

/**
* @var string
*/
private $tmpDir;

public function doTest(string $inputCode, string $expectedCode = null)
{
if ($inputCode === $expectedCode) {
Expand All @@ -72,16 +55,6 @@ protected function getMutator(): Mutator
protected function setUp()
{
$this->mutator = $this->getMutator();

$this->workspace = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'infection-test' . \microtime(true) . \random_int(100, 999);

$this->fileSystem = new Filesystem();
$this->tmpDir = (new TmpDirectoryCreator($this->fileSystem))->createAndGet($this->workspace);
}

protected function tearDown()
{
$this->fileSystem->remove($this->workspace);
}

protected function getNodes(string $code): array
Expand Down Expand Up @@ -110,20 +83,16 @@ protected function mutate(string $code)
return $prettyPrinter->prettyPrintFile($mutatedNodes);
}

private function assertSyntaxIsValid($realMutatedCode)
private function assertSyntaxIsValid(string $realMutatedCode)
{
$filename = $this->fileSystem->tempnam($this->tmpDir, 'mutator');
file_put_contents($filename, $realMutatedCode);

exec(sprintf('php -l %s', $filename), $output, $returnCode);
exec(sprintf('echo %s | php -l', escapeshellarg($realMutatedCode)), $output, $returnCode);

$this->assertSame(
0,
$returnCode,
sprintf(
'Mutator %s produces invalid code in %s',
$this->getMutator()::getName(),
$filename
'Mutator %s produces invalid code in',
$this->getMutator()::getName()
)
);
}
Expand Down

0 comments on commit 0fe2318

Please sign in to comment.