|
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\Command\GenerateResourceClassesCommand; |
|
12
|
|
|
use KleijnWeb\SwaggerBundle\Dev\Generator\ResourceGenerator; |
|
13
|
|
|
use KleijnWeb\SwaggerBundle\Document\DocumentRepository; |
|
14
|
|
|
use org\bovigo\vfs\vfsStreamDirectory; |
|
15
|
|
|
use org\bovigo\vfs\vfsStreamWrapper; |
|
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
18
|
|
|
use Symfony\Component\Console\Tester\CommandTester; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author John Kleijn <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class GenerateResourceClassesCommandTest extends KernelTestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var CommandTester |
|
27
|
|
|
*/ |
|
28
|
|
|
private $commandTester; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Set up the command tester |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function setUp() |
|
34
|
|
|
{ |
|
35
|
|
|
self::bootKernel(); |
|
36
|
|
|
$application = new Application(self::$kernel); |
|
37
|
|
|
|
|
38
|
|
|
$application->add( |
|
39
|
|
|
new GenerateResourceClassesCommand(new DocumentRepository(), new ResourceGenerator()) |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$command = $application->find(GenerateResourceClassesCommand::NAME); |
|
43
|
|
|
$this->commandTester = new CommandTester($command); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @test |
|
48
|
|
|
*/ |
|
49
|
|
|
public function canExecute() |
|
50
|
|
|
{ |
|
51
|
|
|
$petStoreDocumentPath = __DIR__ . '/../../Functional/PetStore/app/swagger/petstore.yml'; |
|
52
|
|
|
vfsStreamWrapper::register(); |
|
53
|
|
|
vfsStreamWrapper::setRoot(new vfsStreamDirectory('willAddResponsesToDocument')); |
|
54
|
|
|
|
|
55
|
|
|
$namespace = 'GenerateResourceClassesCommandTest'; |
|
56
|
|
|
$this->commandTester->execute( |
|
57
|
|
|
[ |
|
58
|
|
|
'command' => GenerateResourceClassesCommand::NAME, |
|
59
|
|
|
'file' => $petStoreDocumentPath, |
|
60
|
|
|
'bundle' => 'PetStoreBundle', |
|
61
|
|
|
'--namespace' => $namespace |
|
62
|
|
|
] |
|
63
|
|
|
); |
|
64
|
|
|
$bundle = self::$kernel->getBundle('PetStoreBundle'); |
|
65
|
|
|
$filePathName = $bundle->getPath() . '/GenerateResourceClassesCommandTest/Pet.php'; |
|
66
|
|
|
|
|
67
|
|
|
$this->assertTrue( |
|
68
|
|
|
file_exists($filePathName), |
|
69
|
|
|
sprintf('%s has not been generated', $filePathName) |
|
70
|
|
|
); |
|
71
|
|
|
$content = file_get_contents($filePathName); |
|
72
|
|
|
$this->assertContains("namespace {$bundle->getNamespace()}\\GenerateResourceClassesCommandTest;", $content); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|