Skip to content

Commit

Permalink
fix issue #214
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Oct 11, 2024
1 parent bd75e03 commit ffe1f6a
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<testsuite name="finder">
<directory>tests/Finder</directory>
</testsuite>
<testsuite name="output">
<directory>tests/Output</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
Expand Down
2 changes: 1 addition & 1 deletion src/Output/JunitOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public function format(LinterOutput $results): void
$error->setAttribute('message', $value['error']);
}

$this->write($document->saveXML());
$this->write($document->saveXML(), false, self::OUTPUT_RAW);
}
}
1 change: 1 addition & 0 deletions tests/Finder/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function testSearchPhpFilesWithCondition(): void
'EndToEnd/LintCommandTest.php',
'EndToEnd/[email protected]',
'Finder/FinderTest.php',
'Output/OutputTest.php',
'TestCase.php',
],
$this->getRelativePathFiles($finder->getFiles()->getIterator(), $basePath)
Expand Down
91 changes: 91 additions & 0 deletions tests/Output/OutputTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

/*
* This file is part of the overtrue/phplint package
*
* (c) overtrue
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Overtrue\PHPLint\Tests\Output;

use Overtrue\PHPLint\Command\LintCommand;
use Overtrue\PHPLint\Configuration\ConsoleOptionsResolver;
use Overtrue\PHPLint\Configuration\OptionDefinition;
use Overtrue\PHPLint\Event\EventDispatcher;
use Overtrue\PHPLint\Finder;
use Overtrue\PHPLint\Linter;
use Overtrue\PHPLint\Output\JunitOutput;
use Overtrue\PHPLint\Output\LinterOutput;
use Overtrue\PHPLint\Tests\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\OutputInterface;

use Throwable;

use function fopen;
use function microtime;
use function rewind;

use const DIRECTORY_SEPARATOR;

/**
* @author Laurent Laville
* @since Release 9.5.3
*/
final class OutputTest extends TestCase
{
private LinterOutput $linterOutput;

/**
* @throws Throwable
*/
protected function setUp(): void
{
$dispatcher = new EventDispatcher([]);

$basePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'fixtures';

$arguments = [
OptionDefinition::PATH => [$basePath],
'--no-configuration' => true,
'--no-cache' => true,
'--' . OptionDefinition::WARNING => true,
'--' . OptionDefinition::EXTENSIONS => ['php']
];
$definition = (new LintCommand($dispatcher))->getDefinition();
$input = new ArrayInput($arguments, $definition);

$configResolver = new ConsoleOptionsResolver($input);

$finder = new Finder($configResolver);

$linter = new Linter($configResolver, $dispatcher);

$startTime = microtime(true);
$defaults = ['application_version' => ['short' => '9.x-dev', 'long' => '9.x-dev']];

$this->linterOutput = $linter->lintFiles($finder->getFiles(), $startTime);
$this->linterOutput->setContext($configResolver, $startTime, 2, $defaults);
}

/**
* @covers \Overtrue\PHPLint\Output\JunitOutput::format
*/
public function testJunitOutput(): void
{
$stream = fopen('php://memory', 'w+');
$output = new JunitOutput($stream, OutputInterface::VERBOSITY_VERBOSE, false);
$output->format($this->linterOutput);

rewind($stream);
$xml = stream_get_contents($stream);

$this->assertStringContainsString('syntax_error.php</error>', $xml);
$this->assertStringContainsString('syntax_warning.php</error>', $xml);
}
}

0 comments on commit ffe1f6a

Please sign in to comment.