1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Functional\Command; |
4
|
|
|
|
5
|
|
|
use Overblog\GraphQLBundle\Generator\TypeGenerator; |
6
|
|
|
use Overblog\GraphQLBundle\Tests\Functional\TestCase; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Output\Output; |
9
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
10
|
|
|
|
11
|
|
|
class CompileCommandTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** @var Command */ |
14
|
|
|
private $command; |
15
|
|
|
|
16
|
|
|
/** @var CommandTester */ |
17
|
|
|
private $commandTester; |
18
|
|
|
|
19
|
|
|
/** @var array */ |
20
|
|
|
private $typesMapping; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
private $cacheDir; |
24
|
|
|
|
25
|
|
|
public function setUp() |
26
|
|
|
{ |
27
|
|
|
parent::setUp(); |
28
|
|
|
static::bootKernel(['test_case' => 'generatorCommand']); |
29
|
|
|
|
30
|
|
|
$this->command = static::$kernel->getContainer()->get('overblog_graphql.command.compile'); |
31
|
|
|
$this->typesMapping = static::$kernel->getContainer()->get('overblog_graphql.cache_compiler') |
32
|
|
|
->compile(TypeGenerator::MODE_MAPPING_ONLY); |
33
|
|
|
$this->cacheDir = static::$kernel->getContainer()->get('overblog_graphql.cache_compiler')->getCacheDir(); |
34
|
|
|
$this->commandTester = new CommandTester($this->command); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testFilesNotExistsBeforeGeneration() |
38
|
|
|
{ |
39
|
|
|
foreach ($this->typesMapping as $class => $path) { |
40
|
|
|
$this->assertFileNotExists($path); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGeneration() |
45
|
|
|
{ |
46
|
|
|
$this->commandTester->execute([]); |
47
|
|
|
$this->assertEquals(0, $this->commandTester->getStatusCode()); |
48
|
|
|
$this->assertEquals($this->displayExpected(), $this->commandTester->getDisplay()); |
49
|
|
|
foreach ($this->typesMapping as $class => $path) { |
50
|
|
|
$this->assertFileExists($path); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testVerboseGeneration() |
55
|
|
|
{ |
56
|
|
|
$this->commandTester->execute([], ['verbosity' => Output::VERBOSITY_VERBOSE]); |
57
|
|
|
$this->assertEquals(0, $this->commandTester->getStatusCode()); |
58
|
|
|
$this->assertRegExp( |
59
|
|
|
'@'.$this->displayExpected(true).'@', |
60
|
|
|
preg_replace('@\.php[^\n]*\n@', ".php\n", $this->commandTester->getDisplay()) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function displayExpected($isVerbose = false) |
65
|
|
|
{ |
66
|
|
|
$display = <<<'OUTPUT' |
67
|
|
|
Types compilation starts |
68
|
|
|
Types compilation ends successfully |
69
|
|
|
|
70
|
|
|
OUTPUT; |
71
|
|
|
|
72
|
|
|
if ($isVerbose) { |
73
|
|
|
$display .= <<<'OUTPUT' |
74
|
|
|
|
75
|
|
|
Summary |
76
|
|
|
======= |
77
|
|
|
|
78
|
|
|
\-[\-]+\s+\-[\-]+\s |
79
|
|
|
class\s+path\s* |
80
|
|
|
\-[\-]+\s+\-[\-]+\s |
81
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\PageInfoType {{PATH}}/PageInfoType.php |
82
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\QueryType {{PATH}}/QueryType.php |
83
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\UserType {{PATH}}/UserType.php |
84
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\friendConnectionType {{PATH}}/friendConnectionType.php |
85
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\userConnectionType {{PATH}}/userConnectionType.php |
86
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\friendEdgeType {{PATH}}/friendEdgeType.php |
87
|
|
|
Overblog\\GraphQLBundle\\Connection\\__DEFINITIONS__\\userEdgeType {{PATH}}/userEdgeType.php |
88
|
|
|
\-[\-]+\s+\-[\-]+\s |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
OUTPUT; |
92
|
|
|
$display = str_replace('{{PATH}}', $this->cacheDir, $display); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $display; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|