|
4 | 4 |
|
5 | 5 | namespace RoaveTest\BackwardCompatibility\Formatter;
|
6 | 6 |
|
| 7 | +use EnricoStahn\JsonAssert\AssertClass as JsonAssert; |
7 | 8 | use PHPUnit\Framework\TestCase;
|
8 | 9 | use Psl\Env;
|
9 | 10 | use Psl\Filesystem;
|
|
13 | 14 | use Roave\BackwardCompatibility\Formatter\JsonFormatter;
|
14 | 15 | use Roave\BackwardCompatibility\Git\CheckedOutRepository;
|
15 | 16 | use Symfony\Component\Console\Output\BufferedOutput;
|
16 |
| -use function Psl\Filesystem; |
17 | 17 |
|
18 | 18 | /** @covers \Roave\BackwardCompatibility\Formatter\JsonFormatter */
|
19 | 19 | final class JsonFormatterTest extends TestCase
|
@@ -56,30 +56,32 @@ public function testWrite(): void
|
56 | 56 |
|
57 | 57 | $expected = [
|
58 | 58 | 'errors' => [
|
59 |
| - ['description' => 'foo', 'path'=>null, 'line'=>null, 'column'=>null], |
60 |
| - ['description' => 'bar', 'path'=>null, 'line'=>null, 'column'=>null], |
61 |
| - ['description' => 'baz', 'path' => 'baz-file.php', 'line'=>null, 'column'=>null], |
62 |
| - ['description' => 'tab', 'path' => 'tab-file.php', 'line'=>5, 'column'=>null], |
63 |
| - ['description' => 'taz', 'path' => 'taz-file.php', 'line'=>6, 'column'=>15], |
64 |
| - ['description' => 'tar', 'path' => 'tar-file.php', 'line'=>-1, 'column'=>-1], |
65 |
| - ['description' => 'file-in-checked-out-dir', 'path' => 'subpath/file-in-checked-out-dir.php', 'line'=>10, 'column'=>20], |
| 59 | + ['description' => 'foo', 'path' => null, 'line' => null, 'column' => null], |
| 60 | + ['description' => 'bar', 'path' => null, 'line' => null, 'column' => null], |
| 61 | + ['description' => 'baz', 'path' => 'baz-file.php', 'line' => null, 'column' => null], |
| 62 | + ['description' => 'tab', 'path' => 'tab-file.php', 'line' => 5, 'column' => null], |
| 63 | + ['description' => 'taz', 'path' => 'taz-file.php', 'line' => 6, 'column' => 15], |
| 64 | + ['description' => 'tar', 'path' => 'tar-file.php', 'line' => -1, 'column' => -1], |
| 65 | + ['description' => 'file-in-checked-out-dir', 'path' => 'subpath/file-in-checked-out-dir.php', 'line' => 10, 'column' => 20], |
66 | 66 | ]
|
67 | 67 | ];
|
68 | 68 |
|
69 |
| - $result = $output->fetch(); |
70 |
| - self::assertJson($result); |
| 69 | + $json = $output->fetch(); |
| 70 | + self::assertJson($json); |
71 | 71 |
|
72 |
| - $data = json_decode(trim($result), true); |
| 72 | + $data = json_decode(trim($json), true); |
73 | 73 | self::assertIsArray($data);
|
74 | 74 | self::assertEquals($expected, $data);
|
75 | 75 |
|
| 76 | + JsonAssert::assertJsonMatchesSchema($json, dirname(__DIR__, 3).'/Resources/errors.schema.json'); |
| 77 | + |
76 | 78 | self::assertJsonStringEqualsJsonString(
|
77 | 79 | <<<'OUTPUT'
|
78 | 80 | {"errors":[{"description":"foo","path":null,"line":null,"column":null},{"description":"bar","path":null,"line":null,"column":null},{"description":"baz","path":"baz-file.php","line":null,"column":null},{"description":"tab","path":"tab-file.php","line":5,"column":null},{"description":"taz","path":"taz-file.php","line":6,"column":15},{"description":"tar","path":"tar-file.php","line":-1,"column":-1},{"description":"file-in-checked-out-dir","path":"subpath\/file-in-checked-out-dir.php","line":10,"column":20}]}
|
79 | 81 |
|
80 | 82 | OUTPUT
|
81 | 83 | ,
|
82 |
| - $result, |
| 84 | + $json, |
83 | 85 | );
|
84 | 86 | }
|
85 | 87 | }
|
0 commit comments