123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Console\Report\FixReport;
- use PhpCsFixer\Console\Application;
- use PhpCsFixer\Console\Report\FixReport\JsonReporter;
- use PhpCsFixer\Console\Report\FixReport\ReporterInterface;
- use PhpCsFixer\Tests\Test\Assert\AssertJsonSchemaTrait;
- /**
- * @author Boris Gorbylev <ekho@ekho.name>
- * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Console\Report\FixReport\JsonReporter
- */
- final class JsonReporterTest extends AbstractReporterTestCase
- {
- use AssertJsonSchemaTrait;
- protected static function createSimpleReport(): string
- {
- $about = Application::getAbout();
- $diff = <<<'DIFF'
- --- Original\n+++ New\n@@ -2,7 +2,7 @@\n\n class Foo\n {\n- public function bar($foo = 1, $bar)\n+ public function bar($foo, $bar)\n {\n }\n }
- DIFF;
- return <<<JSON
- {
- "about": "{$about}",
- "files": [
- {
- "diff": "{$diff}",
- "name": "someFile.php"
- }
- ],
- "time": {
- "total": 0
- },
- "memory": 0
- }
- JSON;
- }
- protected static function createWithDiffReport(): string
- {
- $about = Application::getAbout();
- $diff = <<<'DIFF'
- --- Original\n+++ New\n@@ -2,7 +2,7 @@\n\n class Foo\n {\n- public function bar($foo = 1, $bar)\n+ public function bar($foo, $bar)\n {\n }\n }
- DIFF;
- return <<<JSON
- {
- "about": "{$about}",
- "files": [
- {
- "name": "someFile.php",
- "diff": "{$diff}"
- }
- ],
- "time": {
- "total": 0
- },
- "memory": 0
- }
- JSON;
- }
- protected static function createWithAppliedFixersReport(): string
- {
- $about = Application::getAbout();
- return <<<JSON
- {
- "about": "{$about}",
- "files": [
- {
- "name": "someFile.php",
- "appliedFixers":["some_fixer_name_here_1", "some_fixer_name_here_2"]
- }
- ],
- "time": {
- "total": 0
- },
- "memory": 0
- }
- JSON;
- }
- protected static function createWithTimeAndMemoryReport(): string
- {
- $about = Application::getAbout();
- $diff = <<<'DIFF'
- --- Original\n+++ New\n@@ -2,7 +2,7 @@\n\n class Foo\n {\n- public function bar($foo = 1, $bar)\n+ public function bar($foo, $bar)\n {\n }\n }
- DIFF;
- return <<<JSON
- {
- "about": "{$about}",
- "files": [
- {
- "diff": "{$diff}",
- "name": "someFile.php"
- }
- ],
- "memory": 2.5,
- "time": {
- "total": 1.234
- }
- }
- JSON;
- }
- protected static function createComplexReport(): string
- {
- $about = Application::getAbout();
- return <<<JSON
- {
- "about": "{$about}",
- "files": [
- {
- "name": "someFile.php",
- "appliedFixers":["some_fixer_name_here_1", "some_fixer_name_here_2"],
- "diff": "this text is a diff ;)"
- },
- {
- "name": "anotherFile.php",
- "appliedFixers":["another_fixer_name_here"],
- "diff": "another diff here ;)"
- }
- ],
- "memory": 2.5,
- "time": {
- "total": 1.234
- }
- }
- JSON;
- }
- protected function createReporter(): ReporterInterface
- {
- return new JsonReporter();
- }
- protected function getFormat(): string
- {
- return 'json';
- }
- protected static function createNoErrorReport(): string
- {
- $about = Application::getAbout();
- return <<<JSON
- {
- "about": "{$about}",
- "files": [
- ],
- "time": {
- "total": 0
- },
- "memory": 0
- }
- JSON;
- }
- protected function assertFormat(string $expected, string $input): void
- {
- self::assertJsonSchema(__DIR__.'/../../../../doc/schemas/fix/schema.json', $input);
- self::assertJsonStringEqualsJsonString($expected, $input);
- }
- }
|