-
Notifications
You must be signed in to change notification settings - Fork 3
/
JaneBaseTest.php
75 lines (63 loc) · 2.9 KB
/
JaneBaseTest.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
70
71
72
73
74
75
<?php
namespace Jane\Component\JsonSchema\Tests;
use Jane\Component\JsonSchema\Console\Command\GenerateCommand;
use Jane\Component\JsonSchema\Console\Loader\ConfigLoader;
use Jane\Component\JsonSchema\Console\Loader\SchemaLoader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
class JaneBaseTest extends TestCase
{
use CodeStyleFixerTrait;
/**
* @dataProvider schemaProvider
*/
public function testResources(SplFileInfo $testDirectory): void
{
// 1. Generate
$command = new GenerateCommand(new ConfigLoader(), new SchemaLoader());
$inputArray = new ArrayInput([
'--config-file' => $testDirectory->getRealPath() . \DIRECTORY_SEPARATOR . '.jane',
], $command->getDefinition());
$command->execute($inputArray, new NullOutput());
// 2. Compare
$expectedFinder = new Finder();
$expectedFinder->in($testDirectory->getRealPath() . \DIRECTORY_SEPARATOR . 'expected');
$this->fixCodeStyle($testDirectory->getRealPath() . \DIRECTORY_SEPARATOR . 'expected');
$generatedFinder = new Finder();
$generatedFinder->in($testDirectory->getRealPath() . \DIRECTORY_SEPARATOR . 'generated');
$this->fixCodeStyle($testDirectory->getRealPath() . \DIRECTORY_SEPARATOR . 'generated');
$generatedData = [];
$this->assertEquals(\count($expectedFinder), \count($generatedFinder), sprintf('No same number of files for %s', $testDirectory->getRelativePathname()));
foreach ($generatedFinder as $generatedFile) {
$generatedData[$generatedFile->getRelativePathname()] = $generatedFile->getRealPath();
}
foreach ($expectedFinder as $expectedFile) {
$this->assertArrayHasKey(
$expectedFile->getRelativePathname(),
$generatedData,
sprintf('File %s does not exist for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname())
);
if ($expectedFile->isFile()) {
$this->assertEquals(
file_get_contents($expectedFile->getRealPath()),
file_get_contents($generatedData[$expectedFile->getRelativePathname()]),
sprintf('File %s does not have the same content for %s', $expectedFile->getRelativePathname(), $testDirectory->getRelativePathname())
);
}
}
}
public function schemaProvider(): array
{
$finder = new Finder();
$finder->directories()->in(__DIR__ . '/fixtures');
$finder->depth('< 1');
$data = [];
foreach ($finder as $key => $directory) {
$data[str_replace(__DIR__ . '/fixtures/', 'fixtures-', $key)] = [$directory];
}
return $data;
}
}