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\Document; |
10
|
|
|
|
11
|
|
|
use KleijnWeb\SwaggerBundle\Document\DocumentRepository; |
12
|
|
|
use KleijnWeb\SwaggerBundle\Document\SwaggerDocument; |
13
|
|
|
use org\bovigo\vfs\vfsStream; |
14
|
|
|
use org\bovigo\vfs\vfsStreamDirectory; |
15
|
|
|
use org\bovigo\vfs\vfsStreamWrapper; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author John Kleijn <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class SwaggerDocumentTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @test |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
public function canGetPathDefinitions() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$actual = self::getPetStoreDocument()->getPathDefinitions(); |
28
|
|
|
$this->assertInternalType('object', $actual); |
29
|
|
|
|
30
|
|
|
// Check a few attributes |
31
|
|
|
$this->assertObjectHasAttribute('/pet', $actual); |
32
|
|
|
$this->assertObjectHasAttribute('/pet/findByStatus', $actual); |
33
|
|
|
$this->assertObjectHasAttribute('/store/inventory', $actual); |
34
|
|
|
$this->assertObjectHasAttribute('/user', $actual); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @test |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
public function getOperationDefinition() |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$actual = self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'get'); |
43
|
|
|
$this->assertInternalType('object', $actual); |
44
|
|
|
|
45
|
|
|
// Check a few attributes |
46
|
|
|
$this->assertObjectHasAttribute('parameters', $actual); |
47
|
|
|
$this->assertObjectHasAttribute('responses', $actual); |
48
|
|
|
$this->assertObjectHasAttribute('security', $actual); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
|
public function getOperationDefinitionHttpMethodIsCaseInsensitive() |
55
|
|
|
{ |
56
|
|
|
self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'GET'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException \InvalidArgumentException |
62
|
|
|
* @test |
63
|
|
|
*/ |
64
|
|
|
public function getOperationDefinitionWillFailOnUnknownHttpMethod() |
65
|
|
|
{ |
66
|
|
|
self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'post'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @expectedException \InvalidArgumentException |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function getOperationDefinitionWillFailOnUnknownPath() |
74
|
|
|
{ |
75
|
|
|
self::getPetStoreDocument()->getOperationDefinition('/this/is/total/bogus', 'post'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return SwaggerDocument |
80
|
|
|
*/ |
81
|
|
|
public static function getPetStoreDocument() |
82
|
|
|
{ |
83
|
|
|
$repository = new DocumentRepository('src/Tests/Functional/PetStore'); |
84
|
|
|
|
85
|
|
|
return $repository->get('app/swagger/petstore.yml'); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.