* Dariusz RumiƄski * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Tests\Report; use GeckoPackages\PHPUnit\Constraints\XML\XMLMatchesXSDConstraint; use PhpCsFixer\Report\JunitReporter; use PhpCsFixer\Report\ReportSummary; use PHPUnit\Framework\TestCase; /** * @author Boris Gorbylev * * @internal * * @covers \PhpCsFixer\Report\JunitReporter */ final class JunitReporterTest extends TestCase { /** * @var JunitReporter */ private $reporter; /** * JUnit XML schema from Jenkins. * * @var string * * @see https://github.com/jenkinsci/xunit-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd */ private $xsd; protected function setUp() { $this->reporter = new JunitReporter(); $this->xsd = file_get_contents(__DIR__.'/../../doc/junit-10.xsd'); } /** * @covers \PhpCsFixer\Report\JunitReporter::getFormat */ public function testGetFormat() { $this->assertSame('junit', $this->reporter->getFormat()); } public function testGenerateNoErrors() { $expectedReport = <<<'XML' XML; $actualReport = $this->reporter->generate( new ReportSummary( [], 0, 0, false, false, false ) ); $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd)); $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport); } public function testGenerateSimple() { $expectedReport = <<<'XML' Wrong code style XML; $actualReport = $this->reporter->generate( new ReportSummary( [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here'], ], ], 0, 0, false, false, false ) ); $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd)); $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport); } public function testGenerateWithDiff() { $expectedReport = <<<'XML' XML; $actualReport = $this->reporter->generate( new ReportSummary( [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here'], 'diff' => 'this text is a diff ;)', ], ], 0, 0, false, false, false ) ); $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd)); $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport); } public function testGenerateWithAppliedFixers() { $expectedReport = <<<'XML' applied fixers: --------------- * some_fixer_name_here_1 * some_fixer_name_here_2 XML; $actualReport = $this->reporter->generate( new ReportSummary( [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here_1', 'some_fixer_name_here_2'], ], ], 0, 0, true, false, false ) ); $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd)); $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport); } public function testGenerateWithTimeAndMemory() { $expectedReport = <<<'XML' Wrong code style XML; $actualReport = $this->reporter->generate( new ReportSummary( [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here'], ], ], 1234, 0, false, false, false ) ); $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd)); $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport); } public function testGenerateComplex() { $expectedReport = <<<'XML' applied fixers: --------------- * some_fixer_name_here_1 * some_fixer_name_here_2 Diff: --------------- this text is a diff ;) applied fixers: --------------- * another_fixer_name_here Diff: --------------- another diff here ;) XML; $actualReport = $this->reporter->generate( new ReportSummary( [ 'someFile.php' => [ 'appliedFixers' => ['some_fixer_name_here_1', 'some_fixer_name_here_2'], 'diff' => 'this text is a diff ;)', ], 'anotherFile.php' => [ 'appliedFixers' => ['another_fixer_name_here'], 'diff' => 'another diff here ;)', ], ], 1234, 0, true, true, false ) ); $this->assertThat($actualReport, new XMLMatchesXSDConstraint($this->xsd)); $this->assertXmlStringEqualsXmlString($expectedReport, $actualReport); } }