-
Notifications
You must be signed in to change notification settings - Fork 32
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 #343 from johnbacon/checkstyle-support
Add checkstyle reporting option
- Loading branch information
Showing
7 changed files
with
161 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ vendor/ | |
.php-cs-fixer.cache | ||
.phpunit.result.cache | ||
composer.lock | ||
/.idea |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
const TLINT_VERSION = 'v9.0.0'; | ||
const TLINT_VERSION = 'v9.1.0'; | ||
|
||
foreach ( | ||
[ | ||
|
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,88 @@ | ||
<?php | ||
|
||
namespace Tests\Linting; | ||
|
||
use DomDocument; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Tighten\TLint\Commands\LintCommand; | ||
use Tighten\TLint\Linters\OneLineBetweenClassVisibilityChanges; | ||
|
||
class CanOutputLintsAsCheckstyleTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function can_use_checkstyle_flag_with_lints() | ||
{ | ||
$application = new Application; | ||
$command = new LintCommand; | ||
$application->add($command); | ||
$commandTester = new CommandTester($command); | ||
|
||
$file = <<<'file' | ||
<?php | ||
class Test | ||
{ | ||
public $test1; | ||
private $test2; | ||
} | ||
|
||
file; | ||
|
||
$filePath = tempnam(sys_get_temp_dir(), 'test'); | ||
|
||
file_put_contents($filePath, $file); | ||
|
||
$commandTester->execute([ | ||
'command' => $command->getName(), | ||
'file or directory' => $filePath, | ||
'--checkstyle' => true, | ||
]); | ||
|
||
$output = $commandTester->getDisplay(); | ||
$xml = new DomDocument; | ||
$xml->loadXML($output); | ||
$error = $xml->getElementsByTagName('error')->item(0)->attributes; | ||
|
||
$this->assertEquals('6', $error->getNamedItem('line')->nodeValue); | ||
$this->assertEquals('error', $error->getNamedItem('severity')->nodeValue); | ||
$this->assertEquals('! ' . OneLineBetweenClassVisibilityChanges::DESCRIPTION, $error->getNamedItem('message')->nodeValue); | ||
$this->assertEquals('OneLineBetweenClassVisibilityChanges', $error->getNamedItem('source')->nodeValue); | ||
|
||
$this->assertEquals(0, $commandTester->getStatusCode()); | ||
} | ||
|
||
/** @test */ | ||
public function can_use_checkstyle_flag_without_lints() | ||
{ | ||
$application = new Application; | ||
$command = new LintCommand; | ||
$application->add($command); | ||
$commandTester = new CommandTester($command); | ||
|
||
$file = <<<'file' | ||
<?php | ||
echo 'a'; | ||
|
||
file; | ||
|
||
$filePath = tempnam(sys_get_temp_dir(), 'test'); | ||
|
||
file_put_contents($filePath, $file); | ||
|
||
$commandTester->execute([ | ||
'command' => $command->getName(), | ||
'file or directory' => $filePath, | ||
'--checkstyle' => true, | ||
]); | ||
|
||
$output = $commandTester->getDisplay(); | ||
|
||
$xml = new DOMDocument; | ||
$xml->loadXML($output); | ||
$this->assertEquals(0, $xml->getElementsByTagName('file')->length); | ||
$this->assertEquals(0, $commandTester->getStatusCode()); | ||
} | ||
} |
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