diff --git a/src/Rule/Rules/File/Psr1PhpTagsRule.php b/src/Rule/Rules/File/Psr1PhpTagsRule.php index be1919e..8b83bea 100644 --- a/src/Rule/Rules/File/Psr1PhpTagsRule.php +++ b/src/Rule/Rules/File/Psr1PhpTagsRule.php @@ -157,7 +157,7 @@ private function replacementForInvalidTag(int $id, string $text, int $tokenLine, return [ 'offset' => $tagOffset, 'length' => 2, - 'text' => ' preg_match('/^\s/', substr($text, $tagOffset + 2)) === 1 ? 'makeTempDir(); + + try { + mkdir($basePath . '/src'); + file_put_contents($basePath . '/src/Foo.php', ""); + $command = escapeshellarg(PHP_BINARY) + . ' -d short_open_tag=1 ' + . escapeshellarg($basePath . '/src/Foo.php'); + + exec($command, $output, $exitCode); + + $this->assertSame(0, $exitCode); + $this->assertSame(['test'], $output); + + $psr1PhpTagsRule = new Psr1PhpTagsRule(['src/']); + $violations = $psr1PhpTagsRule->evaluateProjectAll($basePath, Architecture::define()); + + $this->assertCount(1, $violations); + $this->assertSame(1, $violations[0]->line); + $this->assertTrue($psr1PhpTagsRule->fix($violations[0])); + $this->assertSame("", file_get_contents($basePath . '/src/Foo.php')); + + $output = []; + exec($command, $output, $exitCode); + + $this->assertSame(0, $exitCode); + $this->assertSame(['test'], $output); + } finally { + unlink($basePath . '/src/Foo.php'); + rmdir($basePath . '/src'); + rmdir($basePath); + } + } + public function testViolatesAssignmentUsingShortOpenTag(): void { $basePath = $this->makeTempDir();