|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the KleijnWeb\SwaggerBundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
6
|
|
|
* file that was distributed with this source code. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace KleijnWeb\SwaggerBundle\Tests\Dev\Document; |
|
10
|
|
|
|
|
11
|
|
|
use KleijnWeb\SwaggerBundle\Dev\DocumentFixer\Fixers\SwaggerBundleResponseFixer; |
|
12
|
|
|
use KleijnWeb\SwaggerBundle\Document\DocumentRepository; |
|
13
|
|
|
use org\bovigo\vfs\vfsStream; |
|
14
|
|
|
use org\bovigo\vfs\vfsStreamDirectory; |
|
15
|
|
|
use org\bovigo\vfs\vfsStreamWrapper; |
|
16
|
|
|
use Symfony\Component\Console\Application; |
|
17
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
18
|
|
|
use KleijnWeb\SwaggerBundle\Dev\Command\AmendSwaggerDocumentCommand; |
|
19
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author John Kleijn <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class AmendSwaggerDocumentCommandTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var CommandTester |
|
28
|
|
|
*/ |
|
29
|
|
|
private $commandTester; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Set up the command tester |
|
33
|
|
|
*/ |
|
34
|
|
|
protected function setUp() |
|
35
|
|
|
{ |
|
36
|
|
|
$application = new Application(); |
|
37
|
|
|
$application->add(new AmendSwaggerDocumentCommand(new DocumentRepository(), new SwaggerBundleResponseFixer())); |
|
38
|
|
|
|
|
39
|
|
|
$command = $application->find(AmendSwaggerDocumentCommand::NAME); |
|
40
|
|
|
$this->commandTester = new CommandTester($command); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
*/ |
|
46
|
|
|
public function willAddResponsesToDocument() |
|
47
|
|
|
{ |
|
48
|
|
|
$minimalDocumentPath = __DIR__ . '/../DocumentFixer/assets/minimal.yml'; |
|
49
|
|
|
vfsStreamWrapper::register(); |
|
50
|
|
|
vfsStreamWrapper::setRoot(new vfsStreamDirectory('willAddResponsesToDocument')); |
|
51
|
|
|
|
|
52
|
|
|
$amendedPath = vfsStream::url('willAddResponsesToDocument/modified.yml'); |
|
53
|
|
|
$this->commandTester->execute( |
|
54
|
|
|
[ |
|
55
|
|
|
'command' => AmendSwaggerDocumentCommand::NAME, |
|
56
|
|
|
'file' => $minimalDocumentPath, |
|
57
|
|
|
'--out' => $amendedPath |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$modifiedContent = file_get_contents($amendedPath); |
|
62
|
|
|
$this->assertContains('responses', $modifiedContent); |
|
63
|
|
|
|
|
64
|
|
|
$amendedData = Yaml::parse($modifiedContent); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertArrayHasKey('responses', $amendedData); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|