1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Tests\Functional\Command; |
13
|
|
|
|
14
|
|
|
use Overblog\GraphQLBundle\Command\DebugCommand; |
15
|
|
|
use Overblog\GraphQLBundle\Tests\Functional\TestCase; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
17
|
|
|
use Symfony\Component\Console\Command\Command; |
18
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
19
|
|
|
|
20
|
|
|
class DebugCommandTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Command |
24
|
|
|
*/ |
25
|
|
|
private $command; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var CommandTester |
29
|
|
|
*/ |
30
|
|
|
private $commandTester; |
31
|
|
|
|
32
|
|
|
private $logs = []; |
33
|
|
|
|
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); |
37
|
|
|
$client = static::createClient(['test_case' => 'mutation']); |
38
|
|
|
$kernel = $client->getKernel(); |
39
|
|
|
|
40
|
|
|
$application = new Application($kernel); |
41
|
|
|
$application->add(new DebugCommand()); |
42
|
|
|
$this->command = $application->find('graphql:debug'); |
43
|
|
|
$this->commandTester = new CommandTester($this->command); |
44
|
|
|
foreach (DebugCommand::getCategories() as $category) { |
45
|
|
|
$this->logs[$category] = trim(str_replace('ø', '', file_get_contents(__DIR__.'/fixtures/debug-'.$category.'.txt'))); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param array $categories |
51
|
|
|
* @dataProvider categoryDataProvider |
52
|
|
|
*/ |
53
|
|
|
public function testProcess(array $categories) |
54
|
|
|
{ |
55
|
|
|
$input = [ |
56
|
|
|
'command' => $this->command->getName(), |
57
|
|
|
]; |
58
|
|
|
if (empty($categories)) { |
59
|
|
|
$categories = DebugCommand::getCategories(); |
60
|
|
|
} else { |
61
|
|
|
$input['--category'] = $categories; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->commandTester->execute($input); |
65
|
|
|
$this->assertEquals(0, $this->commandTester->getStatusCode()); |
66
|
|
|
$expected = "\n"; |
67
|
|
|
foreach ($categories as $category) { |
68
|
|
|
$expected .= $this->logs[$category]." \n\n\n\n"; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->assertEquals($expected, $this->commandTester->getDisplay()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @expectedException \InvalidArgumentException |
76
|
|
|
* @expectedExceptionMessage Invalid category (fake) |
77
|
|
|
*/ |
78
|
|
|
public function testInvalidFormat() |
79
|
|
|
{ |
80
|
|
|
$this->commandTester->execute([ |
81
|
|
|
'command' => $this->command->getName(), |
82
|
|
|
'--category' => 'fake', |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function categoryDataProvider() |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
[[]], |
90
|
|
|
[['type']], |
91
|
|
|
[['resolver']], |
92
|
|
|
[['mutation']], |
93
|
|
|
[['type', 'mutation']], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|