1
|
|
|
<?php declare(strict_types = 1); |
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\Specification; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author John Kleijn <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class SwaggerSpecificationTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @test |
21
|
|
|
*/ |
22
|
|
|
public function canGetPathDefinitions() |
23
|
|
|
{ |
24
|
|
|
$actual = self::getPetStoreDocument()->getPaths(); |
25
|
|
|
$this->assertinstanceOf('\stdClass', $actual); |
26
|
|
|
|
27
|
|
|
// Check a few attributes |
28
|
|
|
$this->assertObjectHasAttribute('/pet', $actual); |
29
|
|
|
$this->assertObjectHasAttribute('/pet/findByStatus', $actual); |
30
|
|
|
$this->assertObjectHasAttribute('/store/inventory', $actual); |
31
|
|
|
$this->assertObjectHasAttribute('/user', $actual); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function canGetResourceTypeDefinition() |
38
|
|
|
{ |
39
|
|
|
$actual = self::getPetStoreDocument()->getResourceDefinition('Pet'); |
40
|
|
|
$this->assertinstanceOf('\stdClass', $actual); |
41
|
|
|
$this->assertObjectHasAttribute('properties', $actual); |
42
|
|
|
$this->assertObjectHasAttribute('id', $actual->properties); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @test |
47
|
|
|
* @expectedException \InvalidArgumentException |
48
|
|
|
*/ |
49
|
|
|
public function canFailToGetResourceTypeDefinition() |
50
|
|
|
{ |
51
|
|
|
self::getPetStoreDocument()->getResourceDefinition('Zebra'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
*/ |
57
|
|
|
public function getOperationDefinition() |
58
|
|
|
{ |
59
|
|
|
$actual = self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'get'); |
|
|
|
|
60
|
|
|
$this->assertinstanceOf('\stdClass', $actual); |
61
|
|
|
|
62
|
|
|
// Check a few attributes |
63
|
|
|
$this->assertObjectHasAttribute('parameters', $actual); |
64
|
|
|
$this->assertObjectHasAttribute('responses', $actual); |
65
|
|
|
$this->assertObjectHasAttribute('security', $actual); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @test |
70
|
|
|
*/ |
71
|
|
|
public function getOperationDefinitionHttpMethodIsCaseInsensitive() |
72
|
|
|
{ |
73
|
|
|
self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'GET'); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @expectedException \InvalidArgumentException |
78
|
|
|
* @test |
79
|
|
|
*/ |
80
|
|
|
public function getOperationDefinitionWillFailOnUnknownHttpMethod() |
81
|
|
|
{ |
82
|
|
|
self::getPetStoreDocument()->getOperationDefinition('/store/inventory', 'post'); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @expectedException \InvalidArgumentException |
87
|
|
|
* @test |
88
|
|
|
*/ |
89
|
|
|
public function getOperationDefinitionWillFailOnUnknownPath() |
90
|
|
|
{ |
91
|
|
|
self::getPetStoreDocument()->getOperationDefinition('/this/is/total/bogus', 'post'); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return Specification |
96
|
|
|
*/ |
97
|
|
|
public static function getPetStoreDocument() |
98
|
|
|
{ |
99
|
|
|
$repository = new DocumentRepository('src/Tests/Functional/PetStore'); |
100
|
|
|
|
101
|
|
|
return $repository->get('app/swagger/petstore.yml'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This method has been deprecated.