-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLibraryTest.php
69 lines (56 loc) · 2.26 KB
/
LibraryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Jane\Component\JsonSchema\Tests;
use Jane\Component\JsonSchema\Jane;
use Jane\Component\JsonSchema\Printer;
use Jane\Component\JsonSchema\Registry\Registry;
use Jane\Component\JsonSchema\Registry\Schema;
use PhpParser\PrettyPrinter\Standard;
use PHPUnit\Framework\TestCase;
class LibraryTest extends TestCase
{
use CodeStyleFixerTrait;
/**
* @var Jane
*/
protected $jane;
protected $printer;
protected function setUp(): void
{
$this->jane = Jane::build([
'reference' => true,
'strict' => false,
'skip-null-values' => false,
]);
$this->printer = new Printer(new Standard(['shortArraySyntax' => true]), '');
$this->printer->setCleanGenerated(false);
}
/**
* Unique test with ~70% coverage, library generated from json schema must be the same as the library used.
*/
public function testLibrary(): void
{
$path = __DIR__ . '/generated';
$registry = new Registry();
$registry->addSchema(new Schema(__DIR__ . '/data/json-schema.json', 'Jane\Component\JsonSchema\JsonSchema', $path, 'JsonSchema'));
$registry->addOutputDirectory($path);
$this->jane->generate($registry);
$this->printer->output($registry);
$this->fixCodeStyle(__DIR__ . '/../JsonSchema');
$this->fixCodeStyle($path);
$this->assertFileExists(__DIR__ . '/generated/Model/JsonSchema.php');
$this->assertFileExists(__DIR__ . '/generated/Normalizer/JsonSchemaNormalizer.php');
$this->assertFileExists(__DIR__ . '/generated/Normalizer/JaneObjectNormalizer.php');
$this->assertEquals(
file_get_contents(__DIR__ . '/../JsonSchema/Model/JsonSchema.php'),
file_get_contents(__DIR__ . '/generated/Model/JsonSchema.php')
);
$this->assertEquals(
file_get_contents(__DIR__ . '/../JsonSchema/Normalizer/JsonSchemaNormalizer.php'),
file_get_contents(__DIR__ . '/generated/Normalizer/JsonSchemaNormalizer.php'),
);
$this->assertEquals(
file_get_contents(__DIR__ . '/../JsonSchema/Normalizer/JaneObjectNormalizer.php'),
file_get_contents(__DIR__ . '/generated/Normalizer/JaneObjectNormalizer.php'),
);
}
}