@@ -3,124 +3,124 @@ |
||
3 | 3 | class ContactTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Contact::__construct |
|
20 | - */ |
|
21 | - public function testConstructorEmpty() |
|
22 | - { |
|
23 | - $object = new \SwaggerGen\Swagger\Contact($this->parent); |
|
24 | - |
|
25 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
26 | - |
|
27 | - $this->assertSame(array(), $object->toArray()); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * @covers \SwaggerGen\Swagger\Contact::__construct |
|
32 | - */ |
|
33 | - public function testConstructorName() |
|
34 | - { |
|
35 | - $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name'); |
|
36 | - |
|
37 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
38 | - |
|
39 | - $this->assertSame(array( |
|
40 | - 'name' => 'Name', |
|
41 | - ), $object->toArray()); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @covers \SwaggerGen\Swagger\Contact::__construct |
|
46 | - */ |
|
47 | - public function testConstructorUrl() |
|
48 | - { |
|
49 | - $object = new \SwaggerGen\Swagger\Contact($this->parent, null, 'http://example.com'); |
|
50 | - |
|
51 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
52 | - |
|
53 | - $this->assertSame(array( |
|
54 | - 'url' => 'http://example.com', |
|
55 | - ), $object->toArray()); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @covers \SwaggerGen\Swagger\Contact::__construct |
|
60 | - */ |
|
61 | - public function testConstructorEmail() |
|
62 | - { |
|
63 | - $object = new \SwaggerGen\Swagger\Contact($this->parent, null, null, '[email protected]'); |
|
64 | - |
|
65 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
66 | - |
|
67 | - $this->assertSame(array( |
|
68 | - 'email' => '[email protected]', |
|
69 | - ), $object->toArray()); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @covers \SwaggerGen\Swagger\Contact::handleCommand |
|
74 | - */ |
|
75 | - public function testCommandName() |
|
76 | - { |
|
77 | - $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', '[email protected]'); |
|
78 | - |
|
79 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
80 | - |
|
81 | - $object->handleCommand('name', 'Somebody'); |
|
82 | - |
|
83 | - $this->assertSame(array( |
|
84 | - 'name' => 'Somebody', |
|
85 | - 'url' => 'http://example.com', |
|
86 | - 'email' => '[email protected]', |
|
87 | - ), $object->toArray()); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @covers \SwaggerGen\Swagger\Contact::handleCommand |
|
92 | - */ |
|
93 | - public function testCommandUrl() |
|
94 | - { |
|
95 | - $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', '[email protected]'); |
|
96 | - |
|
97 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
98 | - |
|
99 | - $object->handleCommand('url', 'http://site.test'); |
|
100 | - |
|
101 | - $this->assertSame(array( |
|
102 | - 'name' => 'Name', |
|
103 | - 'url' => 'http://site.test', |
|
104 | - 'email' => '[email protected]', |
|
105 | - ), $object->toArray()); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @covers \SwaggerGen\Swagger\Contact::handleCommand |
|
110 | - */ |
|
111 | - public function testCommandEmail() |
|
112 | - { |
|
113 | - $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', '[email protected]'); |
|
114 | - |
|
115 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
116 | - |
|
117 | - $object->handleCommand('email', '[email protected]'); |
|
118 | - |
|
119 | - $this->assertSame(array( |
|
120 | - 'name' => 'Name', |
|
121 | - 'url' => 'http://example.com', |
|
122 | - 'email' => '[email protected]', |
|
123 | - ), $object->toArray()); |
|
124 | - } |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Contact::__construct |
|
20 | + */ |
|
21 | + public function testConstructorEmpty() |
|
22 | + { |
|
23 | + $object = new \SwaggerGen\Swagger\Contact($this->parent); |
|
24 | + |
|
25 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
26 | + |
|
27 | + $this->assertSame(array(), $object->toArray()); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * @covers \SwaggerGen\Swagger\Contact::__construct |
|
32 | + */ |
|
33 | + public function testConstructorName() |
|
34 | + { |
|
35 | + $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name'); |
|
36 | + |
|
37 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
38 | + |
|
39 | + $this->assertSame(array( |
|
40 | + 'name' => 'Name', |
|
41 | + ), $object->toArray()); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @covers \SwaggerGen\Swagger\Contact::__construct |
|
46 | + */ |
|
47 | + public function testConstructorUrl() |
|
48 | + { |
|
49 | + $object = new \SwaggerGen\Swagger\Contact($this->parent, null, 'http://example.com'); |
|
50 | + |
|
51 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
52 | + |
|
53 | + $this->assertSame(array( |
|
54 | + 'url' => 'http://example.com', |
|
55 | + ), $object->toArray()); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @covers \SwaggerGen\Swagger\Contact::__construct |
|
60 | + */ |
|
61 | + public function testConstructorEmail() |
|
62 | + { |
|
63 | + $object = new \SwaggerGen\Swagger\Contact($this->parent, null, null, '[email protected]'); |
|
64 | + |
|
65 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
66 | + |
|
67 | + $this->assertSame(array( |
|
68 | + 'email' => '[email protected]', |
|
69 | + ), $object->toArray()); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @covers \SwaggerGen\Swagger\Contact::handleCommand |
|
74 | + */ |
|
75 | + public function testCommandName() |
|
76 | + { |
|
77 | + $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', '[email protected]'); |
|
78 | + |
|
79 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
80 | + |
|
81 | + $object->handleCommand('name', 'Somebody'); |
|
82 | + |
|
83 | + $this->assertSame(array( |
|
84 | + 'name' => 'Somebody', |
|
85 | + 'url' => 'http://example.com', |
|
86 | + 'email' => '[email protected]', |
|
87 | + ), $object->toArray()); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @covers \SwaggerGen\Swagger\Contact::handleCommand |
|
92 | + */ |
|
93 | + public function testCommandUrl() |
|
94 | + { |
|
95 | + $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', '[email protected]'); |
|
96 | + |
|
97 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
98 | + |
|
99 | + $object->handleCommand('url', 'http://site.test'); |
|
100 | + |
|
101 | + $this->assertSame(array( |
|
102 | + 'name' => 'Name', |
|
103 | + 'url' => 'http://site.test', |
|
104 | + 'email' => '[email protected]', |
|
105 | + ), $object->toArray()); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @covers \SwaggerGen\Swagger\Contact::handleCommand |
|
110 | + */ |
|
111 | + public function testCommandEmail() |
|
112 | + { |
|
113 | + $object = new \SwaggerGen\Swagger\Contact($this->parent, 'Name', 'http://example.com', '[email protected]'); |
|
114 | + |
|
115 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Contact', $object); |
|
116 | + |
|
117 | + $object->handleCommand('email', '[email protected]'); |
|
118 | + |
|
119 | + $this->assertSame(array( |
|
120 | + 'name' => 'Name', |
|
121 | + 'url' => 'http://example.com', |
|
122 | + 'email' => '[email protected]', |
|
123 | + ), $object->toArray()); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -3,65 +3,65 @@ |
||
3 | 3 | class AbstractDocumentableObjectTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
6 | + protected $parent; |
|
7 | 7 | |
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | - } |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | + } |
|
12 | 12 | |
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Tag::__construct |
|
20 | - * @covers \SwaggerGen\Swagger\AbstractDocumentableObject->handleCommand |
|
21 | - */ |
|
22 | - public function testCommandDocWithoutDescription() |
|
23 | - { |
|
24 | - $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Tag::__construct |
|
20 | + * @covers \SwaggerGen\Swagger\AbstractDocumentableObject->handleCommand |
|
21 | + */ |
|
22 | + public function testCommandDocWithoutDescription() |
|
23 | + { |
|
24 | + $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); |
|
25 | 25 | |
26 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); |
|
26 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); |
|
27 | 27 | |
28 | - $this->assertSame(array( |
|
29 | - 'name' => 'Name', |
|
30 | - ), $object->toArray()); |
|
28 | + $this->assertSame(array( |
|
29 | + 'name' => 'Name', |
|
30 | + ), $object->toArray()); |
|
31 | 31 | |
32 | - $object->handleCommand('doc', 'http://example.test'); |
|
32 | + $object->handleCommand('doc', 'http://example.test'); |
|
33 | 33 | |
34 | - $this->assertSame(array( |
|
35 | - 'name' => 'Name', |
|
36 | - 'externalDocs' => array( |
|
37 | - 'url' => 'http://example.test', |
|
38 | - ), |
|
39 | - ), $object->toArray()); |
|
40 | - } |
|
34 | + $this->assertSame(array( |
|
35 | + 'name' => 'Name', |
|
36 | + 'externalDocs' => array( |
|
37 | + 'url' => 'http://example.test', |
|
38 | + ), |
|
39 | + ), $object->toArray()); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @covers \SwaggerGen\Swagger\Tag::__construct |
|
44 | - * @covers \SwaggerGen\Swagger\AbstractDocumentableObject->handleCommand |
|
45 | - */ |
|
46 | - public function testCommandDocWithDescription() |
|
47 | - { |
|
48 | - $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); |
|
42 | + /** |
|
43 | + * @covers \SwaggerGen\Swagger\Tag::__construct |
|
44 | + * @covers \SwaggerGen\Swagger\AbstractDocumentableObject->handleCommand |
|
45 | + */ |
|
46 | + public function testCommandDocWithDescription() |
|
47 | + { |
|
48 | + $object = new \SwaggerGen\Swagger\Tag($this->parent, 'Name'); |
|
49 | 49 | |
50 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); |
|
50 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Tag', $object); |
|
51 | 51 | |
52 | - $this->assertSame(array( |
|
53 | - 'name' => 'Name', |
|
54 | - ), $object->toArray()); |
|
52 | + $this->assertSame(array( |
|
53 | + 'name' => 'Name', |
|
54 | + ), $object->toArray()); |
|
55 | 55 | |
56 | - $object->handleCommand('doc', 'http://example.test Some words here'); |
|
56 | + $object->handleCommand('doc', 'http://example.test Some words here'); |
|
57 | 57 | |
58 | - $this->assertSame(array( |
|
59 | - 'name' => 'Name', |
|
60 | - 'externalDocs' => array( |
|
61 | - 'url' => 'http://example.test', |
|
62 | - 'description' => 'Some words here', |
|
63 | - ), |
|
64 | - ), $object->toArray()); |
|
65 | - } |
|
58 | + $this->assertSame(array( |
|
59 | + 'name' => 'Name', |
|
60 | + 'externalDocs' => array( |
|
61 | + 'url' => 'http://example.test', |
|
62 | + 'description' => 'Some words here', |
|
63 | + ), |
|
64 | + ), $object->toArray()); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | } |
@@ -3,479 +3,479 @@ |
||
3 | 3 | class ObjectTypeTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = new \SwaggerGen\Swagger\Swagger; |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
20 | - */ |
|
21 | - public function testConstructNotAnObject() |
|
22 | - { |
|
23 | - $this->expectException('\SwaggerGen\Exception', "Not an object: 'wrong'"); |
|
24 | - |
|
25 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'wrong'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
30 | - */ |
|
31 | - public function testConstructNoDefault() |
|
32 | - { |
|
33 | - $this->expectException('\SwaggerGen\Exception', "Unparseable object definition: 'object=a'"); |
|
34 | - |
|
35 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object=a'); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
40 | - */ |
|
41 | - public function testConstructEmptyRange() |
|
42 | - { |
|
43 | - $this->expectException('\SwaggerGen\Exception', "Empty object range: 'object[,]'"); |
|
44 | - |
|
45 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[,]'); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
50 | - */ |
|
51 | - public function testConstructRangeStart() |
|
52 | - { |
|
53 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[0,]'); |
|
54 | - |
|
55 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
56 | - |
|
57 | - $this->assertSame(array( |
|
58 | - 'type' => 'object', |
|
59 | - 'minProperties' => 0, |
|
60 | - ), $object->toArray()); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
65 | - */ |
|
66 | - public function testConstructRangeBoth() |
|
67 | - { |
|
68 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object<2,4]'); |
|
69 | - |
|
70 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
71 | - |
|
72 | - $this->assertSame(array( |
|
73 | - 'type' => 'object', |
|
74 | - 'minProperties' => 3, |
|
75 | - 'maxProperties' => 4, |
|
76 | - ), $object->toArray()); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
81 | - */ |
|
82 | - public function testConstructEmptyProperties() |
|
83 | - { |
|
84 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object()'); |
|
85 | - |
|
86 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
87 | - |
|
88 | - $this->assertSame(array( |
|
89 | - 'type' => 'object', |
|
90 | - ), $object->toArray()); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
95 | - */ |
|
96 | - public function testConstructBadProperties() |
|
97 | - { |
|
98 | - $this->expectException('\SwaggerGen\Exception', "Unparseable property definition: '1'"); |
|
99 | - |
|
100 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(1)'); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
105 | - */ |
|
106 | - public function testConstructTypeProperty() |
|
107 | - { |
|
108 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(foo:string)'); |
|
109 | - |
|
110 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
111 | - |
|
112 | - $this->assertSame(array( |
|
113 | - 'type' => 'object', |
|
114 | - 'required' => array( |
|
115 | - 'foo', |
|
116 | - ), |
|
117 | - 'properties' => array( |
|
118 | - 'foo' => array( |
|
119 | - 'type' => 'string', |
|
120 | - ), |
|
121 | - ), |
|
122 | - ), $object->toArray()); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
127 | - */ |
|
128 | - public function testConstructTypeProperties() |
|
129 | - { |
|
130 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(foo:string,bar?:int[3,10>=5)'); |
|
131 | - |
|
132 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
133 | - |
|
134 | - $this->assertSame(array( |
|
135 | - 'type' => 'object', |
|
136 | - 'required' => array( |
|
137 | - 'foo', |
|
138 | - ), |
|
139 | - 'properties' => array( |
|
140 | - 'foo' => array( |
|
141 | - 'type' => 'string', |
|
142 | - ), |
|
143 | - 'bar' => array( |
|
144 | - 'type' => 'integer', |
|
145 | - 'format' => 'int32', |
|
146 | - 'default' => 5, |
|
147 | - 'minimum' => 3, |
|
148 | - 'maximum' => 10, |
|
149 | - 'exclusiveMaximum' => true, |
|
150 | - ) |
|
151 | - ), |
|
152 | - ), $object->toArray()); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
157 | - */ |
|
158 | - public function testCommandMinUpperBound() |
|
159 | - { |
|
160 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
161 | - |
|
162 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
163 | - |
|
164 | - $this->expectException('\SwaggerGen\Exception', "Minimum greater than maximum: '6'"); |
|
165 | - |
|
166 | - $object->handleCommand('min', '6'); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
171 | - */ |
|
172 | - public function testCommandMinLowerBound() |
|
173 | - { |
|
174 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
175 | - |
|
176 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
177 | - |
|
178 | - $this->expectException('\SwaggerGen\Exception', "Minimum less than zero: '-1'"); |
|
179 | - |
|
180 | - $object->handleCommand('min', '-1'); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
185 | - */ |
|
186 | - public function testCommandMin() |
|
187 | - { |
|
188 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
189 | - |
|
190 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
191 | - |
|
192 | - $object->handleCommand('min', '4'); |
|
193 | - |
|
194 | - $this->assertSame(array( |
|
195 | - 'type' => 'object', |
|
196 | - 'minProperties' => 4, |
|
197 | - 'maxProperties' => 5, |
|
198 | - ), $object->toArray()); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
203 | - */ |
|
204 | - public function testCommandMaxLowerBound() |
|
205 | - { |
|
206 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
207 | - |
|
208 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
209 | - |
|
210 | - $this->expectException('\SwaggerGen\Exception', "Maximum less than minimum: '2'"); |
|
211 | - |
|
212 | - $object->handleCommand('max', '2'); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
217 | - */ |
|
218 | - public function testCommandMaxUpperBound() |
|
219 | - { |
|
220 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
221 | - |
|
222 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
223 | - |
|
224 | - $this->expectException('\SwaggerGen\Exception', "Maximum less than zero: '-1'"); |
|
225 | - |
|
226 | - $object->handleCommand('max', '-1'); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
231 | - */ |
|
232 | - public function testCommandMax() |
|
233 | - { |
|
234 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
235 | - |
|
236 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
237 | - |
|
238 | - $object->handleCommand('max', '4'); |
|
239 | - |
|
240 | - $this->assertSame(array( |
|
241 | - 'type' => 'object', |
|
242 | - 'minProperties' => 3, |
|
243 | - 'maxProperties' => 4, |
|
244 | - ), $object->toArray()); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
249 | - */ |
|
250 | - public function testCommandPropertyMissingDefinition() |
|
251 | - { |
|
252 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
253 | - |
|
254 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
255 | - |
|
256 | - $this->expectException('\SwaggerGen\Exception', "Missing property definition"); |
|
257 | - |
|
258 | - $object->handleCommand('property', ''); |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
263 | - */ |
|
264 | - public function testCommandPropertyMissingName() |
|
265 | - { |
|
266 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
267 | - |
|
268 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
269 | - |
|
270 | - $this->expectException('\SwaggerGen\Exception', "Missing property name: 'string'"); |
|
271 | - |
|
272 | - $object->handleCommand('property', 'string'); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
277 | - */ |
|
278 | - public function testCommandProperty() |
|
279 | - { |
|
280 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
281 | - |
|
282 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
283 | - |
|
284 | - $object->handleCommand('property', 'string foo Some words here'); |
|
285 | - |
|
286 | - $this->assertSame(array( |
|
287 | - 'type' => 'object', |
|
288 | - 'required' => array( |
|
289 | - 'foo', |
|
290 | - ), |
|
291 | - 'properties' => array( |
|
292 | - 'foo' => array( |
|
293 | - 'type' => 'string', |
|
294 | - 'description' => 'Some words here', |
|
295 | - ), |
|
296 | - ), |
|
297 | - ), $object->toArray()); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
302 | - */ |
|
303 | - public function testCommandPropertyOptional() |
|
304 | - { |
|
305 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
306 | - |
|
307 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
308 | - |
|
309 | - $object->handleCommand('property?', 'string foo Some words here'); |
|
310 | - |
|
311 | - $this->assertSame(array( |
|
312 | - 'type' => 'object', |
|
313 | - 'properties' => array( |
|
314 | - 'foo' => array( |
|
315 | - 'type' => 'string', |
|
316 | - 'description' => 'Some words here', |
|
317 | - ), |
|
318 | - ), |
|
319 | - ), $object->toArray()); |
|
320 | - } |
|
321 | - |
|
322 | - public function testObjectProperties() |
|
323 | - { |
|
324 | - $object = new \SwaggerGen\SwaggerGen(); |
|
325 | - $array = $object->getSwagger(array(' |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = new \SwaggerGen\Swagger\Swagger; |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
20 | + */ |
|
21 | + public function testConstructNotAnObject() |
|
22 | + { |
|
23 | + $this->expectException('\SwaggerGen\Exception', "Not an object: 'wrong'"); |
|
24 | + |
|
25 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'wrong'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
30 | + */ |
|
31 | + public function testConstructNoDefault() |
|
32 | + { |
|
33 | + $this->expectException('\SwaggerGen\Exception', "Unparseable object definition: 'object=a'"); |
|
34 | + |
|
35 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object=a'); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
40 | + */ |
|
41 | + public function testConstructEmptyRange() |
|
42 | + { |
|
43 | + $this->expectException('\SwaggerGen\Exception', "Empty object range: 'object[,]'"); |
|
44 | + |
|
45 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[,]'); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
50 | + */ |
|
51 | + public function testConstructRangeStart() |
|
52 | + { |
|
53 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[0,]'); |
|
54 | + |
|
55 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
56 | + |
|
57 | + $this->assertSame(array( |
|
58 | + 'type' => 'object', |
|
59 | + 'minProperties' => 0, |
|
60 | + ), $object->toArray()); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
65 | + */ |
|
66 | + public function testConstructRangeBoth() |
|
67 | + { |
|
68 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object<2,4]'); |
|
69 | + |
|
70 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
71 | + |
|
72 | + $this->assertSame(array( |
|
73 | + 'type' => 'object', |
|
74 | + 'minProperties' => 3, |
|
75 | + 'maxProperties' => 4, |
|
76 | + ), $object->toArray()); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
81 | + */ |
|
82 | + public function testConstructEmptyProperties() |
|
83 | + { |
|
84 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object()'); |
|
85 | + |
|
86 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
87 | + |
|
88 | + $this->assertSame(array( |
|
89 | + 'type' => 'object', |
|
90 | + ), $object->toArray()); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
95 | + */ |
|
96 | + public function testConstructBadProperties() |
|
97 | + { |
|
98 | + $this->expectException('\SwaggerGen\Exception', "Unparseable property definition: '1'"); |
|
99 | + |
|
100 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(1)'); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
105 | + */ |
|
106 | + public function testConstructTypeProperty() |
|
107 | + { |
|
108 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(foo:string)'); |
|
109 | + |
|
110 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
111 | + |
|
112 | + $this->assertSame(array( |
|
113 | + 'type' => 'object', |
|
114 | + 'required' => array( |
|
115 | + 'foo', |
|
116 | + ), |
|
117 | + 'properties' => array( |
|
118 | + 'foo' => array( |
|
119 | + 'type' => 'string', |
|
120 | + ), |
|
121 | + ), |
|
122 | + ), $object->toArray()); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @covers \SwaggerGen\Swagger\Type\ObjectType::__construct |
|
127 | + */ |
|
128 | + public function testConstructTypeProperties() |
|
129 | + { |
|
130 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(foo:string,bar?:int[3,10>=5)'); |
|
131 | + |
|
132 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
133 | + |
|
134 | + $this->assertSame(array( |
|
135 | + 'type' => 'object', |
|
136 | + 'required' => array( |
|
137 | + 'foo', |
|
138 | + ), |
|
139 | + 'properties' => array( |
|
140 | + 'foo' => array( |
|
141 | + 'type' => 'string', |
|
142 | + ), |
|
143 | + 'bar' => array( |
|
144 | + 'type' => 'integer', |
|
145 | + 'format' => 'int32', |
|
146 | + 'default' => 5, |
|
147 | + 'minimum' => 3, |
|
148 | + 'maximum' => 10, |
|
149 | + 'exclusiveMaximum' => true, |
|
150 | + ) |
|
151 | + ), |
|
152 | + ), $object->toArray()); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
157 | + */ |
|
158 | + public function testCommandMinUpperBound() |
|
159 | + { |
|
160 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
161 | + |
|
162 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
163 | + |
|
164 | + $this->expectException('\SwaggerGen\Exception', "Minimum greater than maximum: '6'"); |
|
165 | + |
|
166 | + $object->handleCommand('min', '6'); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
171 | + */ |
|
172 | + public function testCommandMinLowerBound() |
|
173 | + { |
|
174 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
175 | + |
|
176 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
177 | + |
|
178 | + $this->expectException('\SwaggerGen\Exception', "Minimum less than zero: '-1'"); |
|
179 | + |
|
180 | + $object->handleCommand('min', '-1'); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
185 | + */ |
|
186 | + public function testCommandMin() |
|
187 | + { |
|
188 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
189 | + |
|
190 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
191 | + |
|
192 | + $object->handleCommand('min', '4'); |
|
193 | + |
|
194 | + $this->assertSame(array( |
|
195 | + 'type' => 'object', |
|
196 | + 'minProperties' => 4, |
|
197 | + 'maxProperties' => 5, |
|
198 | + ), $object->toArray()); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
203 | + */ |
|
204 | + public function testCommandMaxLowerBound() |
|
205 | + { |
|
206 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
207 | + |
|
208 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
209 | + |
|
210 | + $this->expectException('\SwaggerGen\Exception', "Maximum less than minimum: '2'"); |
|
211 | + |
|
212 | + $object->handleCommand('max', '2'); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
217 | + */ |
|
218 | + public function testCommandMaxUpperBound() |
|
219 | + { |
|
220 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
221 | + |
|
222 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
223 | + |
|
224 | + $this->expectException('\SwaggerGen\Exception', "Maximum less than zero: '-1'"); |
|
225 | + |
|
226 | + $object->handleCommand('max', '-1'); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
231 | + */ |
|
232 | + public function testCommandMax() |
|
233 | + { |
|
234 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object[3,5]'); |
|
235 | + |
|
236 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
237 | + |
|
238 | + $object->handleCommand('max', '4'); |
|
239 | + |
|
240 | + $this->assertSame(array( |
|
241 | + 'type' => 'object', |
|
242 | + 'minProperties' => 3, |
|
243 | + 'maxProperties' => 4, |
|
244 | + ), $object->toArray()); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
249 | + */ |
|
250 | + public function testCommandPropertyMissingDefinition() |
|
251 | + { |
|
252 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
253 | + |
|
254 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
255 | + |
|
256 | + $this->expectException('\SwaggerGen\Exception', "Missing property definition"); |
|
257 | + |
|
258 | + $object->handleCommand('property', ''); |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
263 | + */ |
|
264 | + public function testCommandPropertyMissingName() |
|
265 | + { |
|
266 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
267 | + |
|
268 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
269 | + |
|
270 | + $this->expectException('\SwaggerGen\Exception', "Missing property name: 'string'"); |
|
271 | + |
|
272 | + $object->handleCommand('property', 'string'); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
277 | + */ |
|
278 | + public function testCommandProperty() |
|
279 | + { |
|
280 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
281 | + |
|
282 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
283 | + |
|
284 | + $object->handleCommand('property', 'string foo Some words here'); |
|
285 | + |
|
286 | + $this->assertSame(array( |
|
287 | + 'type' => 'object', |
|
288 | + 'required' => array( |
|
289 | + 'foo', |
|
290 | + ), |
|
291 | + 'properties' => array( |
|
292 | + 'foo' => array( |
|
293 | + 'type' => 'string', |
|
294 | + 'description' => 'Some words here', |
|
295 | + ), |
|
296 | + ), |
|
297 | + ), $object->toArray()); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @covers \SwaggerGen\Swagger\Type\ObjectType->handleCommand |
|
302 | + */ |
|
303 | + public function testCommandPropertyOptional() |
|
304 | + { |
|
305 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
306 | + |
|
307 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ObjectType', $object); |
|
308 | + |
|
309 | + $object->handleCommand('property?', 'string foo Some words here'); |
|
310 | + |
|
311 | + $this->assertSame(array( |
|
312 | + 'type' => 'object', |
|
313 | + 'properties' => array( |
|
314 | + 'foo' => array( |
|
315 | + 'type' => 'string', |
|
316 | + 'description' => 'Some words here', |
|
317 | + ), |
|
318 | + ), |
|
319 | + ), $object->toArray()); |
|
320 | + } |
|
321 | + |
|
322 | + public function testObjectProperties() |
|
323 | + { |
|
324 | + $object = new \SwaggerGen\SwaggerGen(); |
|
325 | + $array = $object->getSwagger(array(' |
|
326 | 326 | api Test |
327 | 327 | endpoint /test |
328 | 328 | method GET something |
329 | 329 | response 200 object(a:array(A),b:array(B)) |
330 | 330 | ')); |
331 | 331 | |
332 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
333 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
334 | - . ',"responses":{"200":{"description":"OK","schema":{"type":"object","required":["a","b"]' |
|
335 | - . ',"properties":{"a":{"type":"array","items":{"$ref":"#\/definitions\/A"}}' |
|
336 | - . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
337 | - . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
338 | - } |
|
339 | - |
|
340 | - public function testObjectPropertiesReadOnly() |
|
341 | - { |
|
342 | - $object = new \SwaggerGen\SwaggerGen(); |
|
343 | - $array = $object->getSwagger(array(' |
|
332 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
333 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
334 | + . ',"responses":{"200":{"description":"OK","schema":{"type":"object","required":["a","b"]' |
|
335 | + . ',"properties":{"a":{"type":"array","items":{"$ref":"#\/definitions\/A"}}' |
|
336 | + . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
337 | + . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
338 | + } |
|
339 | + |
|
340 | + public function testObjectPropertiesReadOnly() |
|
341 | + { |
|
342 | + $object = new \SwaggerGen\SwaggerGen(); |
|
343 | + $array = $object->getSwagger(array(' |
|
344 | 344 | api Test |
345 | 345 | endpoint /test |
346 | 346 | method GET something |
347 | 347 | response 200 object(a!:array(A),b:array(B)) |
348 | 348 | ')); |
349 | 349 | |
350 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
351 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
352 | - . ',"responses":{"200":{"description":"OK","schema":{"type":"object","required":["b"]' |
|
353 | - . ',"properties":{"a":{"type":"array","items":{"$ref":"#\/definitions\/A"}}' |
|
354 | - . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
355 | - . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
356 | - } |
|
357 | - |
|
358 | - public function testDeepObjectProperties() |
|
359 | - { |
|
360 | - $object = new \SwaggerGen\SwaggerGen(); |
|
361 | - $array = $object->getSwagger(array(' |
|
350 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
351 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
352 | + . ',"responses":{"200":{"description":"OK","schema":{"type":"object","required":["b"]' |
|
353 | + . ',"properties":{"a":{"type":"array","items":{"$ref":"#\/definitions\/A"}}' |
|
354 | + . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
355 | + . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
356 | + } |
|
357 | + |
|
358 | + public function testDeepObjectProperties() |
|
359 | + { |
|
360 | + $object = new \SwaggerGen\SwaggerGen(); |
|
361 | + $array = $object->getSwagger(array(' |
|
362 | 362 | api Test |
363 | 363 | endpoint /test |
364 | 364 | method GET something |
365 | 365 | response 200 object(a:object(c:csv(C),d:int),b?:array(B)) |
366 | 366 | ')); |
367 | 367 | |
368 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
369 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
370 | - . ',"responses":{"200":{"description":"OK","schema":{"type":"object"' |
|
371 | - . ',"required":["a"],"properties":{' |
|
372 | - . '"a":{"type":"object","required":["c","d"],"properties":{' |
|
373 | - . '"c":{"type":"array","items":{"$ref":"#\/definitions\/C"}}' |
|
374 | - . ',"d":{"type":"integer","format":"int32"}}}' |
|
375 | - . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
376 | - . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
377 | - } |
|
378 | - |
|
379 | - public function testDeepObjectProperties_JsonNotation() |
|
380 | - { |
|
381 | - $object = new \SwaggerGen\SwaggerGen(); |
|
382 | - $array = $object->getSwagger(array(' |
|
368 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
369 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
370 | + . ',"responses":{"200":{"description":"OK","schema":{"type":"object"' |
|
371 | + . ',"required":["a"],"properties":{' |
|
372 | + . '"a":{"type":"object","required":["c","d"],"properties":{' |
|
373 | + . '"c":{"type":"array","items":{"$ref":"#\/definitions\/C"}}' |
|
374 | + . ',"d":{"type":"integer","format":"int32"}}}' |
|
375 | + . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
376 | + . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
377 | + } |
|
378 | + |
|
379 | + public function testDeepObjectProperties_JsonNotation() |
|
380 | + { |
|
381 | + $object = new \SwaggerGen\SwaggerGen(); |
|
382 | + $array = $object->getSwagger(array(' |
|
383 | 383 | api Test |
384 | 384 | endpoint /test |
385 | 385 | method GET something |
386 | 386 | response 200 {a:{c:csv(C),d:int},b?:[B]} |
387 | 387 | ')); |
388 | 388 | |
389 | - $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
390 | - . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
391 | - . ',"responses":{"200":{"description":"OK","schema":{"type":"object"' |
|
392 | - . ',"required":["a"],"properties":{' |
|
393 | - . '"a":{"type":"object","required":["c","d"],"properties":{' |
|
394 | - . '"c":{"type":"array","items":{"$ref":"#\/definitions\/C"}}' |
|
395 | - . ',"d":{"type":"integer","format":"int32"}}}' |
|
396 | - . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
397 | - . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
398 | - } |
|
399 | - |
|
400 | - public function testAddingOptionalPropertyFailsWhenItIsDiscriminator() |
|
401 | - { |
|
402 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
403 | - $object->handleCommand('discriminator', 'type'); |
|
404 | - $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
405 | - $object->handleCommand('property?', 'string type'); |
|
406 | - } |
|
407 | - |
|
408 | - public function testAddingReadonlyPropertyFailsWhenItIsDiscriminator() |
|
409 | - { |
|
410 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
411 | - $object->handleCommand('discriminator', 'type'); |
|
412 | - $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
413 | - $object->handleCommand('property!', 'string type'); |
|
414 | - } |
|
415 | - |
|
416 | - public function testDiscriminatingOnOptionalPropertyFails() |
|
417 | - { |
|
418 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
419 | - $object->handleCommand('property?', 'string type'); |
|
420 | - $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
421 | - $object->handleCommand('discriminator', 'type'); |
|
422 | - } |
|
423 | - |
|
424 | - public function testDiscriminatingOnReadonlyPropertyFails() |
|
425 | - { |
|
426 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
427 | - $object->handleCommand('property!', 'string type'); |
|
428 | - $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
429 | - $object->handleCommand('discriminator', 'type'); |
|
430 | - } |
|
431 | - |
|
432 | - public function testSettingAnotherDiscriminatorFails() |
|
433 | - { |
|
434 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
435 | - $object->handleCommand('discriminator', 'type'); |
|
436 | - $this->expectException('\SwaggerGen\Exception', "Discriminator may only be set once, trying to change it from 'type' to 'petType'"); |
|
437 | - $object->handleCommand('discriminator', 'petType'); |
|
438 | - } |
|
439 | - |
|
440 | - public function testSettingAdditionalPropertiesTwiceInlineFails() |
|
441 | - { |
|
442 | - $this->expectException('\SwaggerGen\Exception', "Additional properties may only be set once"); |
|
443 | - new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(...,...)'); |
|
444 | - } |
|
445 | - |
|
446 | - public function testSettingAdditionalPropertiesTwiceWithCommandFails() |
|
447 | - { |
|
448 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
449 | - $object->handleCommand('additionalproperties', 'false'); |
|
450 | - $this->expectException('\SwaggerGen\Exception', "Additional properties may only be set once"); |
|
451 | - $object->handleCommand('additionalproperties', 'false'); |
|
452 | - } |
|
453 | - |
|
454 | - public function testSettingAdditionalPropertiesTwiceMixedFails() |
|
455 | - { |
|
456 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(...)'); |
|
457 | - $this->expectException('\SwaggerGen\Exception', "Additional properties may only be set once"); |
|
458 | - $object->handleCommand('additionalproperties', 'string'); |
|
459 | - } |
|
460 | - |
|
461 | - public function testSettingAdditionalPropertiesWithInvalidSyntaxFails() |
|
462 | - { |
|
463 | - $this->expectException('\SwaggerGen\Exception', "Unparseable property definition: '!...!'"); |
|
464 | - new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(!...!)'); |
|
465 | - } |
|
466 | - |
|
467 | - public function testSettingAdditionalPropertiesWithInvalidTypeInlineFails() |
|
468 | - { |
|
469 | - $this->expectException('\SwaggerGen\Exception', "Unparseable additional properties definition: '...?&#'"); |
|
470 | - new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(...?&#)'); |
|
471 | - } |
|
472 | - |
|
473 | - public function testSettingAdditionalPropertiesWithInvalidTypeCommandFails() |
|
474 | - { |
|
475 | - $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
476 | - $this->expectException('\SwaggerGen\Exception', "Unparseable additional properties definition: '?&#'"); |
|
477 | - $object->handleCommand('additionalproperties', '?&#'); |
|
478 | - } |
|
389 | + $this->assertSame('{"swagger":2,"info":{"title":"undefined","version":0}' |
|
390 | + . ',"paths":{"\/test":{"get":{"tags":["Test"],"summary":"something"' |
|
391 | + . ',"responses":{"200":{"description":"OK","schema":{"type":"object"' |
|
392 | + . ',"required":["a"],"properties":{' |
|
393 | + . '"a":{"type":"object","required":["c","d"],"properties":{' |
|
394 | + . '"c":{"type":"array","items":{"$ref":"#\/definitions\/C"}}' |
|
395 | + . ',"d":{"type":"integer","format":"int32"}}}' |
|
396 | + . ',"b":{"type":"array","items":{"$ref":"#\/definitions\/B"}}}}}}}}}' |
|
397 | + . ',"tags":[{"name":"Test"}]}', json_encode($array, JSON_NUMERIC_CHECK)); |
|
398 | + } |
|
399 | + |
|
400 | + public function testAddingOptionalPropertyFailsWhenItIsDiscriminator() |
|
401 | + { |
|
402 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
403 | + $object->handleCommand('discriminator', 'type'); |
|
404 | + $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
405 | + $object->handleCommand('property?', 'string type'); |
|
406 | + } |
|
407 | + |
|
408 | + public function testAddingReadonlyPropertyFailsWhenItIsDiscriminator() |
|
409 | + { |
|
410 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
411 | + $object->handleCommand('discriminator', 'type'); |
|
412 | + $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
413 | + $object->handleCommand('property!', 'string type'); |
|
414 | + } |
|
415 | + |
|
416 | + public function testDiscriminatingOnOptionalPropertyFails() |
|
417 | + { |
|
418 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
419 | + $object->handleCommand('property?', 'string type'); |
|
420 | + $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
421 | + $object->handleCommand('discriminator', 'type'); |
|
422 | + } |
|
423 | + |
|
424 | + public function testDiscriminatingOnReadonlyPropertyFails() |
|
425 | + { |
|
426 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
427 | + $object->handleCommand('property!', 'string type'); |
|
428 | + $this->expectException('\SwaggerGen\Exception', "Discriminator must be a required property, property 'type' is not required"); |
|
429 | + $object->handleCommand('discriminator', 'type'); |
|
430 | + } |
|
431 | + |
|
432 | + public function testSettingAnotherDiscriminatorFails() |
|
433 | + { |
|
434 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
435 | + $object->handleCommand('discriminator', 'type'); |
|
436 | + $this->expectException('\SwaggerGen\Exception', "Discriminator may only be set once, trying to change it from 'type' to 'petType'"); |
|
437 | + $object->handleCommand('discriminator', 'petType'); |
|
438 | + } |
|
439 | + |
|
440 | + public function testSettingAdditionalPropertiesTwiceInlineFails() |
|
441 | + { |
|
442 | + $this->expectException('\SwaggerGen\Exception', "Additional properties may only be set once"); |
|
443 | + new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(...,...)'); |
|
444 | + } |
|
445 | + |
|
446 | + public function testSettingAdditionalPropertiesTwiceWithCommandFails() |
|
447 | + { |
|
448 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
449 | + $object->handleCommand('additionalproperties', 'false'); |
|
450 | + $this->expectException('\SwaggerGen\Exception', "Additional properties may only be set once"); |
|
451 | + $object->handleCommand('additionalproperties', 'false'); |
|
452 | + } |
|
453 | + |
|
454 | + public function testSettingAdditionalPropertiesTwiceMixedFails() |
|
455 | + { |
|
456 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(...)'); |
|
457 | + $this->expectException('\SwaggerGen\Exception', "Additional properties may only be set once"); |
|
458 | + $object->handleCommand('additionalproperties', 'string'); |
|
459 | + } |
|
460 | + |
|
461 | + public function testSettingAdditionalPropertiesWithInvalidSyntaxFails() |
|
462 | + { |
|
463 | + $this->expectException('\SwaggerGen\Exception', "Unparseable property definition: '!...!'"); |
|
464 | + new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(!...!)'); |
|
465 | + } |
|
466 | + |
|
467 | + public function testSettingAdditionalPropertiesWithInvalidTypeInlineFails() |
|
468 | + { |
|
469 | + $this->expectException('\SwaggerGen\Exception', "Unparseable additional properties definition: '...?&#'"); |
|
470 | + new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object(...?&#)'); |
|
471 | + } |
|
472 | + |
|
473 | + public function testSettingAdditionalPropertiesWithInvalidTypeCommandFails() |
|
474 | + { |
|
475 | + $object = new SwaggerGen\Swagger\Type\ObjectType($this->parent, 'object'); |
|
476 | + $this->expectException('\SwaggerGen\Exception', "Unparseable additional properties definition: '?&#'"); |
|
477 | + $object->handleCommand('additionalproperties', '?&#'); |
|
478 | + } |
|
479 | 479 | |
480 | 480 | |
481 | 481 | } |
@@ -3,187 +3,187 @@ |
||
3 | 3 | class DateTypeTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
20 | - */ |
|
21 | - public function testConstructNotADate() |
|
22 | - { |
|
23 | - $this->expectException('\SwaggerGen\Exception', "Not a date: 'wrong'"); |
|
24 | - |
|
25 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'wrong'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
30 | - */ |
|
31 | - public function testConstructRange() |
|
32 | - { |
|
33 | - $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date[1,]'"); |
|
34 | - |
|
35 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date[1,]'); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
40 | - */ |
|
41 | - public function testConstructParentheses() |
|
42 | - { |
|
43 | - $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date()'"); |
|
44 | - |
|
45 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date()'); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
50 | - */ |
|
51 | - public function testConstructDate() |
|
52 | - { |
|
53 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
54 | - |
|
55 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
56 | - |
|
57 | - $this->assertSame(array( |
|
58 | - 'type' => 'string', |
|
59 | - 'format' => 'date', |
|
60 | - ), $object->toArray()); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
65 | - */ |
|
66 | - public function testConstructDateTime() |
|
67 | - { |
|
68 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'datetime'); |
|
69 | - |
|
70 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
71 | - |
|
72 | - $this->assertSame(array( |
|
73 | - 'type' => 'string', |
|
74 | - 'format' => 'date-time', |
|
75 | - ), $object->toArray()); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
80 | - */ |
|
81 | - public function testConstructDateDefaultEmpty() |
|
82 | - { |
|
83 | - $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date='"); |
|
84 | - |
|
85 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date='); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
90 | - */ |
|
91 | - public function testConstructDateDefaultBlank() |
|
92 | - { |
|
93 | - $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date= '"); |
|
94 | - |
|
95 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date= '); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
100 | - */ |
|
101 | - public function testConstructDateDefaultWrong() |
|
102 | - { |
|
103 | - $this->expectException('\SwaggerGen\Exception', "Invalid 'date' default: 'wrong'"); |
|
104 | - |
|
105 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date=wrong'); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
110 | - */ |
|
111 | - public function testConstructDateDefault() |
|
112 | - { |
|
113 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date=1999-12-31'); |
|
114 | - |
|
115 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
116 | - |
|
117 | - $this->assertSame(array( |
|
118 | - 'type' => 'string', |
|
119 | - 'format' => 'date', |
|
120 | - 'default' => '1999-12-31', |
|
121 | - ), $object->toArray()); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
126 | - */ |
|
127 | - public function testConstructDateTimeDefault() |
|
128 | - { |
|
129 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'datetime=1999-12-31T23:59:59+11:00'); |
|
130 | - |
|
131 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
132 | - |
|
133 | - $this->assertSame(array( |
|
134 | - 'type' => 'string', |
|
135 | - 'format' => 'date-time', |
|
136 | - 'default' => '1999-12-31T23:59:59+11:00', |
|
137 | - ), $object->toArray()); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @covers \SwaggerGen\Swagger\Type\DateType->handleCommand |
|
142 | - */ |
|
143 | - public function testCommandDefaultNoValue() |
|
144 | - { |
|
145 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
146 | - |
|
147 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
148 | - |
|
149 | - $this->expectException('\SwaggerGen\Exception', "Empty date default"); |
|
150 | - $object->handleCommand('default', ''); |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @covers \SwaggerGen\Swagger\Type\DateType->handleCommand |
|
155 | - */ |
|
156 | - public function testCommandDefaultWrong() |
|
157 | - { |
|
158 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
159 | - |
|
160 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
161 | - |
|
162 | - $this->expectException('\SwaggerGen\Exception', "Invalid 'date' default: 'wrong'"); |
|
163 | - $object->handleCommand('default', 'wrong'); |
|
164 | - |
|
165 | - $this->assertSame(array( |
|
166 | - 'type' => 'string', |
|
167 | - 'default' => 'date', |
|
168 | - ), $object->toArray()); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @covers \SwaggerGen\Swagger\Type\DateType->handleCommand |
|
173 | - */ |
|
174 | - public function testCommandDefault() |
|
175 | - { |
|
176 | - $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
177 | - |
|
178 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
179 | - |
|
180 | - $object->handleCommand('default', '1999-12-31'); |
|
181 | - |
|
182 | - $this->assertSame(array( |
|
183 | - 'type' => 'string', |
|
184 | - 'format' => 'date', |
|
185 | - 'default' => '1999-12-31', |
|
186 | - ), $object->toArray()); |
|
187 | - } |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
20 | + */ |
|
21 | + public function testConstructNotADate() |
|
22 | + { |
|
23 | + $this->expectException('\SwaggerGen\Exception', "Not a date: 'wrong'"); |
|
24 | + |
|
25 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'wrong'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
30 | + */ |
|
31 | + public function testConstructRange() |
|
32 | + { |
|
33 | + $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date[1,]'"); |
|
34 | + |
|
35 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date[1,]'); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
40 | + */ |
|
41 | + public function testConstructParentheses() |
|
42 | + { |
|
43 | + $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date()'"); |
|
44 | + |
|
45 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date()'); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
50 | + */ |
|
51 | + public function testConstructDate() |
|
52 | + { |
|
53 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
54 | + |
|
55 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
56 | + |
|
57 | + $this->assertSame(array( |
|
58 | + 'type' => 'string', |
|
59 | + 'format' => 'date', |
|
60 | + ), $object->toArray()); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
65 | + */ |
|
66 | + public function testConstructDateTime() |
|
67 | + { |
|
68 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'datetime'); |
|
69 | + |
|
70 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
71 | + |
|
72 | + $this->assertSame(array( |
|
73 | + 'type' => 'string', |
|
74 | + 'format' => 'date-time', |
|
75 | + ), $object->toArray()); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
80 | + */ |
|
81 | + public function testConstructDateDefaultEmpty() |
|
82 | + { |
|
83 | + $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date='"); |
|
84 | + |
|
85 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date='); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
90 | + */ |
|
91 | + public function testConstructDateDefaultBlank() |
|
92 | + { |
|
93 | + $this->expectException('\SwaggerGen\Exception', "Unparseable date definition: 'date= '"); |
|
94 | + |
|
95 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date= '); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
100 | + */ |
|
101 | + public function testConstructDateDefaultWrong() |
|
102 | + { |
|
103 | + $this->expectException('\SwaggerGen\Exception', "Invalid 'date' default: 'wrong'"); |
|
104 | + |
|
105 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date=wrong'); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
110 | + */ |
|
111 | + public function testConstructDateDefault() |
|
112 | + { |
|
113 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date=1999-12-31'); |
|
114 | + |
|
115 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
116 | + |
|
117 | + $this->assertSame(array( |
|
118 | + 'type' => 'string', |
|
119 | + 'format' => 'date', |
|
120 | + 'default' => '1999-12-31', |
|
121 | + ), $object->toArray()); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @covers \SwaggerGen\Swagger\Type\DateType::__construct |
|
126 | + */ |
|
127 | + public function testConstructDateTimeDefault() |
|
128 | + { |
|
129 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'datetime=1999-12-31T23:59:59+11:00'); |
|
130 | + |
|
131 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
132 | + |
|
133 | + $this->assertSame(array( |
|
134 | + 'type' => 'string', |
|
135 | + 'format' => 'date-time', |
|
136 | + 'default' => '1999-12-31T23:59:59+11:00', |
|
137 | + ), $object->toArray()); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @covers \SwaggerGen\Swagger\Type\DateType->handleCommand |
|
142 | + */ |
|
143 | + public function testCommandDefaultNoValue() |
|
144 | + { |
|
145 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
146 | + |
|
147 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
148 | + |
|
149 | + $this->expectException('\SwaggerGen\Exception', "Empty date default"); |
|
150 | + $object->handleCommand('default', ''); |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @covers \SwaggerGen\Swagger\Type\DateType->handleCommand |
|
155 | + */ |
|
156 | + public function testCommandDefaultWrong() |
|
157 | + { |
|
158 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
159 | + |
|
160 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
161 | + |
|
162 | + $this->expectException('\SwaggerGen\Exception', "Invalid 'date' default: 'wrong'"); |
|
163 | + $object->handleCommand('default', 'wrong'); |
|
164 | + |
|
165 | + $this->assertSame(array( |
|
166 | + 'type' => 'string', |
|
167 | + 'default' => 'date', |
|
168 | + ), $object->toArray()); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @covers \SwaggerGen\Swagger\Type\DateType->handleCommand |
|
173 | + */ |
|
174 | + public function testCommandDefault() |
|
175 | + { |
|
176 | + $object = new SwaggerGen\Swagger\Type\DateType($this->parent, 'date'); |
|
177 | + |
|
178 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\DateType', $object); |
|
179 | + |
|
180 | + $object->handleCommand('default', '1999-12-31'); |
|
181 | + |
|
182 | + $this->assertSame(array( |
|
183 | + 'type' => 'string', |
|
184 | + 'format' => 'date', |
|
185 | + 'default' => '1999-12-31', |
|
186 | + ), $object->toArray()); |
|
187 | + } |
|
188 | 188 | |
189 | 189 | } |
@@ -3,124 +3,124 @@ |
||
3 | 3 | class StringUuidTypeTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
20 | - */ |
|
21 | - public function testConstructNotAUuid() |
|
22 | - { |
|
23 | - $this->expectException('\SwaggerGen\Exception', "Not a uuid: 'wrong'"); |
|
24 | - |
|
25 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'wrong'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
30 | - */ |
|
31 | - public function testConstructUuid() |
|
32 | - { |
|
33 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
34 | - |
|
35 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
36 | - |
|
37 | - $this->assertSame(array( |
|
38 | - 'type' => 'string', |
|
39 | - 'format' => 'uuid', |
|
40 | - 'pattern' => '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$', |
|
41 | - ), $object->toArray()); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
46 | - */ |
|
47 | - public function testConstructUuidEmptyDefault() |
|
48 | - { |
|
49 | - $this->expectException('\SwaggerGen\Exception', "Unparseable uuid definition: 'uuid='"); |
|
50 | - |
|
51 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid= '); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
56 | - */ |
|
57 | - public function testConstructUuidBadDefault() |
|
58 | - { |
|
59 | - $this->expectException('\SwaggerGen\Exception', "Unparseable uuid definition: 'uuid=123'"); |
|
60 | - |
|
61 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid=123'); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
66 | - */ |
|
67 | - public function testConstructUuidDefault() |
|
68 | - { |
|
69 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid=123e4567-e89b-12d3-a456-426655440000'); |
|
70 | - |
|
71 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
72 | - |
|
73 | - $this->assertSame(array( |
|
74 | - 'type' => 'string', |
|
75 | - 'format' => 'uuid', |
|
76 | - 'pattern' => '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$', |
|
77 | - 'default' => '123e4567-e89b-12d3-a456-426655440000', |
|
78 | - ), $object->toArray()); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType->handleCommand |
|
83 | - */ |
|
84 | - public function testCommandDefaultNoValue() |
|
85 | - { |
|
86 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
87 | - |
|
88 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
89 | - |
|
90 | - $this->expectException('\SwaggerGen\Exception', "Empty uuid default"); |
|
91 | - $object->handleCommand('default', ''); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType->handleCommand |
|
96 | - */ |
|
97 | - public function testCommandDefaultBadValue() |
|
98 | - { |
|
99 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
100 | - |
|
101 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
102 | - |
|
103 | - $this->expectException('\SwaggerGen\Exception', "Invalid uuid default"); |
|
104 | - $object->handleCommand('default', 'foobar'); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @covers \SwaggerGen\Swagger\Type\StringUuidType->handleCommand |
|
109 | - */ |
|
110 | - public function testCommandDefault() |
|
111 | - { |
|
112 | - $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
113 | - |
|
114 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
115 | - |
|
116 | - $object->handleCommand('default', '123e4567-e89b-12d3-a456-426655440000'); |
|
117 | - |
|
118 | - $this->assertSame(array( |
|
119 | - 'type' => 'string', |
|
120 | - 'format' => 'uuid', |
|
121 | - 'pattern' => '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$', |
|
122 | - 'default' => '123e4567-e89b-12d3-a456-426655440000', |
|
123 | - ), $object->toArray()); |
|
124 | - } |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
20 | + */ |
|
21 | + public function testConstructNotAUuid() |
|
22 | + { |
|
23 | + $this->expectException('\SwaggerGen\Exception', "Not a uuid: 'wrong'"); |
|
24 | + |
|
25 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'wrong'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
30 | + */ |
|
31 | + public function testConstructUuid() |
|
32 | + { |
|
33 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
34 | + |
|
35 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
36 | + |
|
37 | + $this->assertSame(array( |
|
38 | + 'type' => 'string', |
|
39 | + 'format' => 'uuid', |
|
40 | + 'pattern' => '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$', |
|
41 | + ), $object->toArray()); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
46 | + */ |
|
47 | + public function testConstructUuidEmptyDefault() |
|
48 | + { |
|
49 | + $this->expectException('\SwaggerGen\Exception', "Unparseable uuid definition: 'uuid='"); |
|
50 | + |
|
51 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid= '); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
56 | + */ |
|
57 | + public function testConstructUuidBadDefault() |
|
58 | + { |
|
59 | + $this->expectException('\SwaggerGen\Exception', "Unparseable uuid definition: 'uuid=123'"); |
|
60 | + |
|
61 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid=123'); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType::__construct |
|
66 | + */ |
|
67 | + public function testConstructUuidDefault() |
|
68 | + { |
|
69 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid=123e4567-e89b-12d3-a456-426655440000'); |
|
70 | + |
|
71 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
72 | + |
|
73 | + $this->assertSame(array( |
|
74 | + 'type' => 'string', |
|
75 | + 'format' => 'uuid', |
|
76 | + 'pattern' => '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$', |
|
77 | + 'default' => '123e4567-e89b-12d3-a456-426655440000', |
|
78 | + ), $object->toArray()); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType->handleCommand |
|
83 | + */ |
|
84 | + public function testCommandDefaultNoValue() |
|
85 | + { |
|
86 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
87 | + |
|
88 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
89 | + |
|
90 | + $this->expectException('\SwaggerGen\Exception', "Empty uuid default"); |
|
91 | + $object->handleCommand('default', ''); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType->handleCommand |
|
96 | + */ |
|
97 | + public function testCommandDefaultBadValue() |
|
98 | + { |
|
99 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
100 | + |
|
101 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
102 | + |
|
103 | + $this->expectException('\SwaggerGen\Exception', "Invalid uuid default"); |
|
104 | + $object->handleCommand('default', 'foobar'); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @covers \SwaggerGen\Swagger\Type\StringUuidType->handleCommand |
|
109 | + */ |
|
110 | + public function testCommandDefault() |
|
111 | + { |
|
112 | + $object = new SwaggerGen\Swagger\Type\StringUuidType($this->parent, 'uuid'); |
|
113 | + |
|
114 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringUuidType', $object); |
|
115 | + |
|
116 | + $object->handleCommand('default', '123e4567-e89b-12d3-a456-426655440000'); |
|
117 | + |
|
118 | + $this->assertSame(array( |
|
119 | + 'type' => 'string', |
|
120 | + 'format' => 'uuid', |
|
121 | + 'pattern' => '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$', |
|
122 | + 'default' => '123e4567-e89b-12d3-a456-426655440000', |
|
123 | + ), $object->toArray()); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -3,358 +3,358 @@ |
||
3 | 3 | class NumberTypeTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
20 | - */ |
|
21 | - public function testConstructNotANumber() |
|
22 | - { |
|
23 | - $this->expectException('\SwaggerGen\Exception', "Not a number: 'wrong'"); |
|
24 | - |
|
25 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'wrong'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
30 | - */ |
|
31 | - public function testConstructInvalidDefault() |
|
32 | - { |
|
33 | - $this->expectException('\SwaggerGen\Exception', "Unparseable number definition: 'float=null'"); |
|
34 | - |
|
35 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=null'); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
40 | - */ |
|
41 | - public function testConstructNoSpecificationAllowed() |
|
42 | - { |
|
43 | - $this->expectException('\SwaggerGen\Exception', "Unparseable number definition: 'float()=1'"); |
|
44 | - |
|
45 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float()=1'); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
50 | - */ |
|
51 | - public function testConstructEmptyRange() |
|
52 | - { |
|
53 | - $this->expectException('\SwaggerGen\Exception', "Empty number range: 'float[,]=1'"); |
|
54 | - |
|
55 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[,]=1'); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
60 | - */ |
|
61 | - public function testConstructNotEmptyRange() |
|
62 | - { |
|
63 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[0,]'); |
|
64 | - |
|
65 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
66 | - |
|
67 | - $this->assertSame(array( |
|
68 | - 'type' => 'number', |
|
69 | - 'format' => 'float', |
|
70 | - 'minimum' => 0., |
|
71 | - ), $object->toArray()); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
76 | - */ |
|
77 | - public function testConstructNumber() |
|
78 | - { |
|
79 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
80 | - |
|
81 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
82 | - |
|
83 | - $this->assertSame(array( |
|
84 | - 'type' => 'number', |
|
85 | - 'format' => 'float', |
|
86 | - ), $object->toArray()); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
91 | - */ |
|
92 | - public function testConstructLong() |
|
93 | - { |
|
94 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'double'); |
|
95 | - |
|
96 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
97 | - |
|
98 | - $this->assertSame(array( |
|
99 | - 'type' => 'number', |
|
100 | - 'format' => 'double', |
|
101 | - ), $object->toArray()); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
106 | - */ |
|
107 | - public function testConstructZero() |
|
108 | - { |
|
109 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=0'); |
|
110 | - |
|
111 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
112 | - |
|
113 | - $this->assertSame(array( |
|
114 | - 'type' => 'number', |
|
115 | - 'format' => 'float', |
|
116 | - 'default' => 0., |
|
117 | - ), $object->toArray()); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
122 | - */ |
|
123 | - public function testConstructPositive() |
|
124 | - { |
|
125 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=1.23'); |
|
126 | - |
|
127 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
128 | - |
|
129 | - $this->assertSame(array( |
|
130 | - 'type' => 'number', |
|
131 | - 'format' => 'float', |
|
132 | - 'default' => 1.23, |
|
133 | - ), $object->toArray()); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
138 | - */ |
|
139 | - public function testConstructNegative() |
|
140 | - { |
|
141 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=-1.23'); |
|
142 | - |
|
143 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
144 | - |
|
145 | - $this->assertSame(array( |
|
146 | - 'type' => 'number', |
|
147 | - 'format' => 'float', |
|
148 | - 'default' => -1.23, |
|
149 | - ), $object->toArray()); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
154 | - */ |
|
155 | - public function testConstructRangeInclusive() |
|
156 | - { |
|
157 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=3'); |
|
158 | - |
|
159 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
160 | - |
|
161 | - $this->assertSame(array( |
|
162 | - 'type' => 'number', |
|
163 | - 'format' => 'float', |
|
164 | - 'default' => 3., |
|
165 | - 'minimum' => 2., |
|
166 | - 'maximum' => 5., |
|
167 | - ), $object->toArray()); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
172 | - */ |
|
173 | - public function testConstructRangeExclusive() |
|
174 | - { |
|
175 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=3'); |
|
176 | - |
|
177 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
178 | - |
|
179 | - $this->assertSame(array( |
|
180 | - 'type' => 'number', |
|
181 | - 'format' => 'float', |
|
182 | - 'default' => 3., |
|
183 | - 'minimum' => 2., |
|
184 | - 'exclusiveMinimum' => true, |
|
185 | - 'maximum' => 5., |
|
186 | - 'exclusiveMaximum' => true, |
|
187 | - ), $object->toArray()); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
192 | - */ |
|
193 | - public function testConstructDefaultBeyondMaximumExclusive() |
|
194 | - { |
|
195 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=4'); |
|
196 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
197 | - |
|
198 | - $this->expectException('\SwaggerGen\Exception', "Default number beyond maximum: '5'"); |
|
199 | - |
|
200 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=5'); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
205 | - */ |
|
206 | - public function testConstructDefaultBeyondMaximum() |
|
207 | - { |
|
208 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=5'); |
|
209 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
210 | - |
|
211 | - $this->expectException('\SwaggerGen\Exception', "Default number beyond maximum: '6'"); |
|
212 | - |
|
213 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=6'); |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
218 | - */ |
|
219 | - public function testConstructDefaultBeyondMinimumExclusive() |
|
220 | - { |
|
221 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=3'); |
|
222 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
223 | - |
|
224 | - $this->expectException('\SwaggerGen\Exception', "Default number beyond minimum: '2'"); |
|
225 | - |
|
226 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=2'); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
231 | - */ |
|
232 | - public function testConstructDefaultBeyondMinimum() |
|
233 | - { |
|
234 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=2'); |
|
235 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
236 | - |
|
237 | - $this->expectException('\SwaggerGen\Exception', "Default number beyond minimum: '1'"); |
|
238 | - |
|
239 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=1'); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
244 | - */ |
|
245 | - public function testCommandDefaultNoValue() |
|
246 | - { |
|
247 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
248 | - |
|
249 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
250 | - |
|
251 | - $this->expectException('\SwaggerGen\Exception', "Invalid number default: ''"); |
|
252 | - $object->handleCommand('default', ''); |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
257 | - */ |
|
258 | - public function testCommandDefaultInvalidValue() |
|
259 | - { |
|
260 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
261 | - |
|
262 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
263 | - |
|
264 | - $this->expectException('\SwaggerGen\Exception', "Invalid number default: 'foo'"); |
|
265 | - $object->handleCommand('default', 'foo'); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
270 | - */ |
|
271 | - public function testCommandDefaultPositive() |
|
272 | - { |
|
273 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
274 | - |
|
275 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
276 | - |
|
277 | - $object->handleCommand('default', '1.23'); |
|
278 | - |
|
279 | - $this->assertSame(array( |
|
280 | - 'type' => 'number', |
|
281 | - 'format' => 'float', |
|
282 | - 'default' => 1.23, |
|
283 | - ), $object->toArray()); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
288 | - */ |
|
289 | - public function testCommandDefaultNegative() |
|
290 | - { |
|
291 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
292 | - |
|
293 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
294 | - |
|
295 | - $object->handleCommand('default', '-1.23'); |
|
296 | - |
|
297 | - $this->assertSame(array( |
|
298 | - 'type' => 'number', |
|
299 | - 'format' => 'float', |
|
300 | - 'default' => -1.23, |
|
301 | - ), $object->toArray()); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
306 | - */ |
|
307 | - public function testCommandDefaultBeyondRange() |
|
308 | - { |
|
309 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[-1.22,1.22]'); |
|
310 | - |
|
311 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
312 | - |
|
313 | - $this->expectException('\SwaggerGen\Exception', "Default number beyond minimum: '-1.23'"); |
|
314 | - $object->handleCommand('default', '-1.23'); |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
319 | - */ |
|
320 | - public function testCommandEnum() |
|
321 | - { |
|
322 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
323 | - |
|
324 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
325 | - |
|
326 | - $object->handleCommand('enum', '-1 2 1.23'); |
|
327 | - $object->handleCommand('enum', '-1.23 0'); |
|
328 | - |
|
329 | - $this->assertEquals(array( |
|
330 | - 'type' => 'number', |
|
331 | - 'format' => 'float', |
|
332 | - 'enum' => array( |
|
333 | - -1., |
|
334 | - 2., |
|
335 | - 1.23, |
|
336 | - -1.23, |
|
337 | - 0., |
|
338 | - ), |
|
339 | - ), $object->toArray()); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
344 | - */ |
|
345 | - public function testCommandStep() |
|
346 | - { |
|
347 | - $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
348 | - |
|
349 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
350 | - |
|
351 | - $object->handleCommand('step', '3'); |
|
352 | - |
|
353 | - $this->assertEquals(array( |
|
354 | - 'type' => 'number', |
|
355 | - 'format' => 'float', |
|
356 | - 'multipleOf' => 3, |
|
357 | - ), $object->toArray()); |
|
358 | - } |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
20 | + */ |
|
21 | + public function testConstructNotANumber() |
|
22 | + { |
|
23 | + $this->expectException('\SwaggerGen\Exception', "Not a number: 'wrong'"); |
|
24 | + |
|
25 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'wrong'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
30 | + */ |
|
31 | + public function testConstructInvalidDefault() |
|
32 | + { |
|
33 | + $this->expectException('\SwaggerGen\Exception', "Unparseable number definition: 'float=null'"); |
|
34 | + |
|
35 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=null'); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
40 | + */ |
|
41 | + public function testConstructNoSpecificationAllowed() |
|
42 | + { |
|
43 | + $this->expectException('\SwaggerGen\Exception', "Unparseable number definition: 'float()=1'"); |
|
44 | + |
|
45 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float()=1'); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
50 | + */ |
|
51 | + public function testConstructEmptyRange() |
|
52 | + { |
|
53 | + $this->expectException('\SwaggerGen\Exception', "Empty number range: 'float[,]=1'"); |
|
54 | + |
|
55 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[,]=1'); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
60 | + */ |
|
61 | + public function testConstructNotEmptyRange() |
|
62 | + { |
|
63 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[0,]'); |
|
64 | + |
|
65 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
66 | + |
|
67 | + $this->assertSame(array( |
|
68 | + 'type' => 'number', |
|
69 | + 'format' => 'float', |
|
70 | + 'minimum' => 0., |
|
71 | + ), $object->toArray()); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
76 | + */ |
|
77 | + public function testConstructNumber() |
|
78 | + { |
|
79 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
80 | + |
|
81 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
82 | + |
|
83 | + $this->assertSame(array( |
|
84 | + 'type' => 'number', |
|
85 | + 'format' => 'float', |
|
86 | + ), $object->toArray()); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
91 | + */ |
|
92 | + public function testConstructLong() |
|
93 | + { |
|
94 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'double'); |
|
95 | + |
|
96 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
97 | + |
|
98 | + $this->assertSame(array( |
|
99 | + 'type' => 'number', |
|
100 | + 'format' => 'double', |
|
101 | + ), $object->toArray()); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
106 | + */ |
|
107 | + public function testConstructZero() |
|
108 | + { |
|
109 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=0'); |
|
110 | + |
|
111 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
112 | + |
|
113 | + $this->assertSame(array( |
|
114 | + 'type' => 'number', |
|
115 | + 'format' => 'float', |
|
116 | + 'default' => 0., |
|
117 | + ), $object->toArray()); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
122 | + */ |
|
123 | + public function testConstructPositive() |
|
124 | + { |
|
125 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=1.23'); |
|
126 | + |
|
127 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
128 | + |
|
129 | + $this->assertSame(array( |
|
130 | + 'type' => 'number', |
|
131 | + 'format' => 'float', |
|
132 | + 'default' => 1.23, |
|
133 | + ), $object->toArray()); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
138 | + */ |
|
139 | + public function testConstructNegative() |
|
140 | + { |
|
141 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float=-1.23'); |
|
142 | + |
|
143 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
144 | + |
|
145 | + $this->assertSame(array( |
|
146 | + 'type' => 'number', |
|
147 | + 'format' => 'float', |
|
148 | + 'default' => -1.23, |
|
149 | + ), $object->toArray()); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
154 | + */ |
|
155 | + public function testConstructRangeInclusive() |
|
156 | + { |
|
157 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=3'); |
|
158 | + |
|
159 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
160 | + |
|
161 | + $this->assertSame(array( |
|
162 | + 'type' => 'number', |
|
163 | + 'format' => 'float', |
|
164 | + 'default' => 3., |
|
165 | + 'minimum' => 2., |
|
166 | + 'maximum' => 5., |
|
167 | + ), $object->toArray()); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
172 | + */ |
|
173 | + public function testConstructRangeExclusive() |
|
174 | + { |
|
175 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=3'); |
|
176 | + |
|
177 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
178 | + |
|
179 | + $this->assertSame(array( |
|
180 | + 'type' => 'number', |
|
181 | + 'format' => 'float', |
|
182 | + 'default' => 3., |
|
183 | + 'minimum' => 2., |
|
184 | + 'exclusiveMinimum' => true, |
|
185 | + 'maximum' => 5., |
|
186 | + 'exclusiveMaximum' => true, |
|
187 | + ), $object->toArray()); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
192 | + */ |
|
193 | + public function testConstructDefaultBeyondMaximumExclusive() |
|
194 | + { |
|
195 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=4'); |
|
196 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
197 | + |
|
198 | + $this->expectException('\SwaggerGen\Exception', "Default number beyond maximum: '5'"); |
|
199 | + |
|
200 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=5'); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
205 | + */ |
|
206 | + public function testConstructDefaultBeyondMaximum() |
|
207 | + { |
|
208 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=5'); |
|
209 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
210 | + |
|
211 | + $this->expectException('\SwaggerGen\Exception', "Default number beyond maximum: '6'"); |
|
212 | + |
|
213 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=6'); |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
218 | + */ |
|
219 | + public function testConstructDefaultBeyondMinimumExclusive() |
|
220 | + { |
|
221 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=3'); |
|
222 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
223 | + |
|
224 | + $this->expectException('\SwaggerGen\Exception', "Default number beyond minimum: '2'"); |
|
225 | + |
|
226 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float<2,5>=2'); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @covers \SwaggerGen\Swagger\Type\NumberType::__construct |
|
231 | + */ |
|
232 | + public function testConstructDefaultBeyondMinimum() |
|
233 | + { |
|
234 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=2'); |
|
235 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
236 | + |
|
237 | + $this->expectException('\SwaggerGen\Exception', "Default number beyond minimum: '1'"); |
|
238 | + |
|
239 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[2,5]=1'); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
244 | + */ |
|
245 | + public function testCommandDefaultNoValue() |
|
246 | + { |
|
247 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
248 | + |
|
249 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
250 | + |
|
251 | + $this->expectException('\SwaggerGen\Exception', "Invalid number default: ''"); |
|
252 | + $object->handleCommand('default', ''); |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
257 | + */ |
|
258 | + public function testCommandDefaultInvalidValue() |
|
259 | + { |
|
260 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
261 | + |
|
262 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
263 | + |
|
264 | + $this->expectException('\SwaggerGen\Exception', "Invalid number default: 'foo'"); |
|
265 | + $object->handleCommand('default', 'foo'); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
270 | + */ |
|
271 | + public function testCommandDefaultPositive() |
|
272 | + { |
|
273 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
274 | + |
|
275 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
276 | + |
|
277 | + $object->handleCommand('default', '1.23'); |
|
278 | + |
|
279 | + $this->assertSame(array( |
|
280 | + 'type' => 'number', |
|
281 | + 'format' => 'float', |
|
282 | + 'default' => 1.23, |
|
283 | + ), $object->toArray()); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
288 | + */ |
|
289 | + public function testCommandDefaultNegative() |
|
290 | + { |
|
291 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
292 | + |
|
293 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
294 | + |
|
295 | + $object->handleCommand('default', '-1.23'); |
|
296 | + |
|
297 | + $this->assertSame(array( |
|
298 | + 'type' => 'number', |
|
299 | + 'format' => 'float', |
|
300 | + 'default' => -1.23, |
|
301 | + ), $object->toArray()); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
306 | + */ |
|
307 | + public function testCommandDefaultBeyondRange() |
|
308 | + { |
|
309 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float[-1.22,1.22]'); |
|
310 | + |
|
311 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
312 | + |
|
313 | + $this->expectException('\SwaggerGen\Exception', "Default number beyond minimum: '-1.23'"); |
|
314 | + $object->handleCommand('default', '-1.23'); |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
319 | + */ |
|
320 | + public function testCommandEnum() |
|
321 | + { |
|
322 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
323 | + |
|
324 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
325 | + |
|
326 | + $object->handleCommand('enum', '-1 2 1.23'); |
|
327 | + $object->handleCommand('enum', '-1.23 0'); |
|
328 | + |
|
329 | + $this->assertEquals(array( |
|
330 | + 'type' => 'number', |
|
331 | + 'format' => 'float', |
|
332 | + 'enum' => array( |
|
333 | + -1., |
|
334 | + 2., |
|
335 | + 1.23, |
|
336 | + -1.23, |
|
337 | + 0., |
|
338 | + ), |
|
339 | + ), $object->toArray()); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * @covers \SwaggerGen\Swagger\Type\NumberType->handleCommand |
|
344 | + */ |
|
345 | + public function testCommandStep() |
|
346 | + { |
|
347 | + $object = new SwaggerGen\Swagger\Type\NumberType($this->parent, 'float'); |
|
348 | + |
|
349 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\NumberType', $object); |
|
350 | + |
|
351 | + $object->handleCommand('step', '3'); |
|
352 | + |
|
353 | + $this->assertEquals(array( |
|
354 | + 'type' => 'number', |
|
355 | + 'format' => 'float', |
|
356 | + 'multipleOf' => 3, |
|
357 | + ), $object->toArray()); |
|
358 | + } |
|
359 | 359 | |
360 | 360 | } |
@@ -3,130 +3,130 @@ |
||
3 | 3 | class PropertyTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
20 | - */ |
|
21 | - public function testConstructEmpty() |
|
22 | - { |
|
23 | - $this->expectException('\SwaggerGen\Exception', "Not a property: ''"); |
|
24 | - |
|
25 | - new SwaggerGen\Swagger\Type\Property($this->parent, ''); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
30 | - */ |
|
31 | - public function testConstructReference() |
|
32 | - { |
|
33 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'Address'); |
|
34 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
35 | - |
|
36 | - $this->assertSame(array( |
|
37 | - '$ref' => '#/definitions/Address', |
|
38 | - ), $object->toArray()); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
43 | - */ |
|
44 | - public function testConstructReferences() |
|
45 | - { |
|
46 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'array(Address)'); |
|
47 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
48 | - |
|
49 | - $this->assertSame(array( |
|
50 | - 'type' => 'array', |
|
51 | - 'items' => array( |
|
52 | - '$ref' => '#/definitions/Address', |
|
53 | - ), |
|
54 | - ), $object->toArray()); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
59 | - */ |
|
60 | - public function testConstructString() |
|
61 | - { |
|
62 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
63 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
64 | - |
|
65 | - $this->assertSame(array( |
|
66 | - 'type' => 'string', |
|
67 | - ), $object->toArray()); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
72 | - */ |
|
73 | - public function testConstructDescription() |
|
74 | - { |
|
75 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here'); |
|
76 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
77 | - |
|
78 | - $this->assertSame(array( |
|
79 | - 'type' => 'string', |
|
80 | - 'description' => 'Some words here', |
|
81 | - ), $object->toArray()); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
86 | - */ |
|
87 | - public function testConstructReadOnly() |
|
88 | - { |
|
89 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here', true); |
|
90 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
91 | - |
|
92 | - $this->assertSame(array( |
|
93 | - 'type' => 'string', |
|
94 | - 'description' => 'Some words here', |
|
95 | - 'readOnly' => true |
|
96 | - ), $object->toArray()); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
101 | - */ |
|
102 | - public function testConstructComplex() |
|
103 | - { |
|
104 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'int[3,10>=6'); |
|
105 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
106 | - |
|
107 | - $this->assertSame(array( |
|
108 | - 'type' => 'integer', |
|
109 | - 'format' => 'int32', |
|
110 | - 'default' => 6, |
|
111 | - 'minimum' => 3, |
|
112 | - 'maximum' => 10, |
|
113 | - 'exclusiveMaximum' => true, |
|
114 | - ), $object->toArray()); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
119 | - */ |
|
120 | - public function testCommandPassing() |
|
121 | - { |
|
122 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
123 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
124 | - |
|
125 | - $object->handleCommand('default', 'good'); |
|
126 | - $this->assertSame(array( |
|
127 | - 'type' => 'string', |
|
128 | - 'default' => 'good', |
|
129 | - ), $object->toArray()); |
|
130 | - } |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
20 | + */ |
|
21 | + public function testConstructEmpty() |
|
22 | + { |
|
23 | + $this->expectException('\SwaggerGen\Exception', "Not a property: ''"); |
|
24 | + |
|
25 | + new SwaggerGen\Swagger\Type\Property($this->parent, ''); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
30 | + */ |
|
31 | + public function testConstructReference() |
|
32 | + { |
|
33 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'Address'); |
|
34 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
35 | + |
|
36 | + $this->assertSame(array( |
|
37 | + '$ref' => '#/definitions/Address', |
|
38 | + ), $object->toArray()); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
43 | + */ |
|
44 | + public function testConstructReferences() |
|
45 | + { |
|
46 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'array(Address)'); |
|
47 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
48 | + |
|
49 | + $this->assertSame(array( |
|
50 | + 'type' => 'array', |
|
51 | + 'items' => array( |
|
52 | + '$ref' => '#/definitions/Address', |
|
53 | + ), |
|
54 | + ), $object->toArray()); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
59 | + */ |
|
60 | + public function testConstructString() |
|
61 | + { |
|
62 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
63 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
64 | + |
|
65 | + $this->assertSame(array( |
|
66 | + 'type' => 'string', |
|
67 | + ), $object->toArray()); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
72 | + */ |
|
73 | + public function testConstructDescription() |
|
74 | + { |
|
75 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here'); |
|
76 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
77 | + |
|
78 | + $this->assertSame(array( |
|
79 | + 'type' => 'string', |
|
80 | + 'description' => 'Some words here', |
|
81 | + ), $object->toArray()); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
86 | + */ |
|
87 | + public function testConstructReadOnly() |
|
88 | + { |
|
89 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here', true); |
|
90 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
91 | + |
|
92 | + $this->assertSame(array( |
|
93 | + 'type' => 'string', |
|
94 | + 'description' => 'Some words here', |
|
95 | + 'readOnly' => true |
|
96 | + ), $object->toArray()); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
101 | + */ |
|
102 | + public function testConstructComplex() |
|
103 | + { |
|
104 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'int[3,10>=6'); |
|
105 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
106 | + |
|
107 | + $this->assertSame(array( |
|
108 | + 'type' => 'integer', |
|
109 | + 'format' => 'int32', |
|
110 | + 'default' => 6, |
|
111 | + 'minimum' => 3, |
|
112 | + 'maximum' => 10, |
|
113 | + 'exclusiveMaximum' => true, |
|
114 | + ), $object->toArray()); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
119 | + */ |
|
120 | + public function testCommandPassing() |
|
121 | + { |
|
122 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
123 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
124 | + |
|
125 | + $object->handleCommand('default', 'good'); |
|
126 | + $this->assertSame(array( |
|
127 | + 'type' => 'string', |
|
128 | + 'default' => 'good', |
|
129 | + ), $object->toArray()); |
|
130 | + } |
|
131 | 131 | |
132 | 132 | } |
@@ -3,32 +3,32 @@ |
||
3 | 3 | class ReferenceObjectTypeTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
6 | + protected $parent; |
|
7 | 7 | |
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
11 | - } |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
11 | + } |
|
12 | 12 | |
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\ReferenceObjectType::__construct |
|
20 | - */ |
|
21 | - public function testConstructBothConsumes() |
|
22 | - { |
|
23 | - $this->parent->handleCommand('model', 'blah'); |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\ReferenceObjectType::__construct |
|
20 | + */ |
|
21 | + public function testConstructBothConsumes() |
|
22 | + { |
|
23 | + $this->parent->handleCommand('model', 'blah'); |
|
24 | 24 | |
25 | - $object = new SwaggerGen\Swagger\Type\ReferenceObjectType($this->parent, 'blah'); |
|
25 | + $object = new SwaggerGen\Swagger\Type\ReferenceObjectType($this->parent, 'blah'); |
|
26 | 26 | |
27 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ReferenceObjectType', $object); |
|
27 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ReferenceObjectType', $object); |
|
28 | 28 | |
29 | - $this->assertSame(array( |
|
30 | - '$ref' => '#/definitions/blah', |
|
31 | - ), $object->toArray()); |
|
32 | - } |
|
29 | + $this->assertSame(array( |
|
30 | + '$ref' => '#/definitions/blah', |
|
31 | + ), $object->toArray()); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
@@ -3,293 +3,293 @@ |
||
3 | 3 | class StringTypeTest extends SwaggerGen_TestCase |
4 | 4 | { |
5 | 5 | |
6 | - protected $parent; |
|
7 | - |
|
8 | - protected function setUp(): void |
|
9 | - { |
|
10 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | - } |
|
12 | - |
|
13 | - protected function assertPreConditions(): void |
|
14 | - { |
|
15 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | - } |
|
17 | - |
|
18 | - /** |
|
19 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
20 | - */ |
|
21 | - public function testConstructNotAString() |
|
22 | - { |
|
23 | - $this->expectException('\SwaggerGen\Exception', "Not a string: 'wrong'"); |
|
24 | - |
|
25 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'wrong'); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
30 | - */ |
|
31 | - public function testConstructEmptyRange() |
|
32 | - { |
|
33 | - $this->expectException('\SwaggerGen\Exception', "Empty string range: 'string[,]=1'"); |
|
34 | - |
|
35 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,]=1'); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
40 | - */ |
|
41 | - public function testConstructDefaultTooLongInclusive() |
|
42 | - { |
|
43 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
44 | - |
|
45 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,3]=long'); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
50 | - */ |
|
51 | - public function testConstructDefaultTooLongExclusive() |
|
52 | - { |
|
53 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
54 | - |
|
55 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,4>=long'); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
60 | - */ |
|
61 | - public function testConstructDefaultTooShortInclusive() |
|
62 | - { |
|
63 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
64 | - |
|
65 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[6,]=short'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
70 | - */ |
|
71 | - public function testConstructDefaultTooShortExclusive() |
|
72 | - { |
|
73 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
74 | - |
|
75 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<5,]=short'); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
80 | - */ |
|
81 | - public function testConstructString() |
|
82 | - { |
|
83 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
84 | - |
|
85 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
86 | - |
|
87 | - $this->assertSame(array( |
|
88 | - 'type' => 'string', |
|
89 | - ), $object->toArray()); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
94 | - */ |
|
95 | - public function testConstructStringEmptyDefault() |
|
96 | - { |
|
97 | - $this->expectException('\SwaggerGen\Exception', "Unparseable string definition: 'string='"); |
|
98 | - |
|
99 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string= '); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
104 | - */ |
|
105 | - public function testConstructStringDefaultLengthInclusive() |
|
106 | - { |
|
107 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[4,4]=word'); |
|
108 | - |
|
109 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
110 | - |
|
111 | - $this->assertSame(array( |
|
112 | - 'type' => 'string', |
|
113 | - 'default' => 'word', |
|
114 | - 'minLength' => 4, |
|
115 | - 'maxLength' => 4, |
|
116 | - ), $object->toArray()); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
121 | - */ |
|
122 | - public function testConstructStringDefaultLengthExclusive() |
|
123 | - { |
|
124 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<3,5>=word'); |
|
125 | - |
|
126 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
127 | - |
|
128 | - $this->assertSame(array( |
|
129 | - 'type' => 'string', |
|
130 | - 'default' => 'word', |
|
131 | - 'minLength' => 4, |
|
132 | - 'maxLength' => 4, |
|
133 | - ), $object->toArray()); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
138 | - */ |
|
139 | - public function testConstructBinary() |
|
140 | - { |
|
141 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'binary'); |
|
142 | - |
|
143 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
144 | - |
|
145 | - $this->assertSame(array( |
|
146 | - 'type' => 'string', |
|
147 | - 'format' => 'binary', |
|
148 | - ), $object->toArray()); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
153 | - */ |
|
154 | - public function testConstructEnumRange() |
|
155 | - { |
|
156 | - $this->expectException('\SwaggerGen\Exception', "Range not allowed in enumeration definition: 'enum(a,b)[,]'"); |
|
157 | - |
|
158 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)[,]'); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
163 | - */ |
|
164 | - public function testConstructEnumInvalidDefault() |
|
165 | - { |
|
166 | - $this->expectException('\SwaggerGen\Exception', "Invalid enum default: 'c'"); |
|
167 | - |
|
168 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=c'); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
173 | - */ |
|
174 | - public function testConstructEnum() |
|
175 | - { |
|
176 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)'); |
|
177 | - |
|
178 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
179 | - |
|
180 | - $this->assertSame(array( |
|
181 | - 'type' => 'string', |
|
182 | - 'enum' => array('a', 'b'), |
|
183 | - ), $object->toArray()); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
188 | - */ |
|
189 | - public function testConstructEnumWithDefault() |
|
190 | - { |
|
191 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=a'); |
|
192 | - |
|
193 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
194 | - |
|
195 | - $this->assertSame(array( |
|
196 | - 'type' => 'string', |
|
197 | - 'default' => 'a', |
|
198 | - 'enum' => array('a', 'b'), |
|
199 | - ), $object->toArray()); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
204 | - */ |
|
205 | - public function testConstructPattern() |
|
206 | - { |
|
207 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string([a-z])'); |
|
208 | - |
|
209 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
210 | - |
|
211 | - $this->assertSame(array( |
|
212 | - 'type' => 'string', |
|
213 | - 'pattern' => '[a-z]', |
|
214 | - ), $object->toArray()); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
219 | - */ |
|
220 | - public function testCommandDefaultNoValue() |
|
221 | - { |
|
222 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
223 | - |
|
224 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
225 | - |
|
226 | - $this->expectException('\SwaggerGen\Exception', "Empty string default"); |
|
227 | - $object->handleCommand('default', ''); |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
232 | - */ |
|
233 | - public function testCommandDefault() |
|
234 | - { |
|
235 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
236 | - |
|
237 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
238 | - |
|
239 | - $object->handleCommand('default', 'word'); |
|
240 | - |
|
241 | - $this->assertSame(array( |
|
242 | - 'type' => 'string', |
|
243 | - 'default' => 'word', |
|
244 | - ), $object->toArray()); |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
249 | - */ |
|
250 | - public function testCommandPattern() |
|
251 | - { |
|
252 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
253 | - |
|
254 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
255 | - |
|
256 | - $object->handleCommand('pattern', '[a-z]'); |
|
257 | - |
|
258 | - $this->assertSame(array( |
|
259 | - 'type' => 'string', |
|
260 | - 'pattern' => '[a-z]', |
|
261 | - ), $object->toArray()); |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
266 | - */ |
|
267 | - public function testCommandEnumWhenRange() |
|
268 | - { |
|
269 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[0,]'); |
|
270 | - |
|
271 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
272 | - |
|
273 | - $this->expectException('\SwaggerGen\Exception', "Enumeration not allowed in ranged string: 'red green blue'"); |
|
274 | - |
|
275 | - $object->handleCommand('enum', 'red green blue'); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
280 | - */ |
|
281 | - public function testCommandEnum() |
|
282 | - { |
|
283 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
284 | - |
|
285 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
286 | - |
|
287 | - $object->handleCommand('enum', 'red green blue'); |
|
288 | - |
|
289 | - $this->assertSame(array( |
|
290 | - 'type' => 'string', |
|
291 | - 'enum' => array('red', 'green', 'blue'), |
|
292 | - ), $object->toArray()); |
|
293 | - } |
|
6 | + protected $parent; |
|
7 | + |
|
8 | + protected function setUp(): void |
|
9 | + { |
|
10 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
11 | + } |
|
12 | + |
|
13 | + protected function assertPreConditions(): void |
|
14 | + { |
|
15 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
16 | + } |
|
17 | + |
|
18 | + /** |
|
19 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
20 | + */ |
|
21 | + public function testConstructNotAString() |
|
22 | + { |
|
23 | + $this->expectException('\SwaggerGen\Exception', "Not a string: 'wrong'"); |
|
24 | + |
|
25 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'wrong'); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
30 | + */ |
|
31 | + public function testConstructEmptyRange() |
|
32 | + { |
|
33 | + $this->expectException('\SwaggerGen\Exception', "Empty string range: 'string[,]=1'"); |
|
34 | + |
|
35 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,]=1'); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
40 | + */ |
|
41 | + public function testConstructDefaultTooLongInclusive() |
|
42 | + { |
|
43 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
44 | + |
|
45 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,3]=long'); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
50 | + */ |
|
51 | + public function testConstructDefaultTooLongExclusive() |
|
52 | + { |
|
53 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
54 | + |
|
55 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,4>=long'); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
60 | + */ |
|
61 | + public function testConstructDefaultTooShortInclusive() |
|
62 | + { |
|
63 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
64 | + |
|
65 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[6,]=short'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
70 | + */ |
|
71 | + public function testConstructDefaultTooShortExclusive() |
|
72 | + { |
|
73 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
74 | + |
|
75 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<5,]=short'); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
80 | + */ |
|
81 | + public function testConstructString() |
|
82 | + { |
|
83 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
84 | + |
|
85 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
86 | + |
|
87 | + $this->assertSame(array( |
|
88 | + 'type' => 'string', |
|
89 | + ), $object->toArray()); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
94 | + */ |
|
95 | + public function testConstructStringEmptyDefault() |
|
96 | + { |
|
97 | + $this->expectException('\SwaggerGen\Exception', "Unparseable string definition: 'string='"); |
|
98 | + |
|
99 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string= '); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
104 | + */ |
|
105 | + public function testConstructStringDefaultLengthInclusive() |
|
106 | + { |
|
107 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[4,4]=word'); |
|
108 | + |
|
109 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
110 | + |
|
111 | + $this->assertSame(array( |
|
112 | + 'type' => 'string', |
|
113 | + 'default' => 'word', |
|
114 | + 'minLength' => 4, |
|
115 | + 'maxLength' => 4, |
|
116 | + ), $object->toArray()); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
121 | + */ |
|
122 | + public function testConstructStringDefaultLengthExclusive() |
|
123 | + { |
|
124 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<3,5>=word'); |
|
125 | + |
|
126 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
127 | + |
|
128 | + $this->assertSame(array( |
|
129 | + 'type' => 'string', |
|
130 | + 'default' => 'word', |
|
131 | + 'minLength' => 4, |
|
132 | + 'maxLength' => 4, |
|
133 | + ), $object->toArray()); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
138 | + */ |
|
139 | + public function testConstructBinary() |
|
140 | + { |
|
141 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'binary'); |
|
142 | + |
|
143 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
144 | + |
|
145 | + $this->assertSame(array( |
|
146 | + 'type' => 'string', |
|
147 | + 'format' => 'binary', |
|
148 | + ), $object->toArray()); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
153 | + */ |
|
154 | + public function testConstructEnumRange() |
|
155 | + { |
|
156 | + $this->expectException('\SwaggerGen\Exception', "Range not allowed in enumeration definition: 'enum(a,b)[,]'"); |
|
157 | + |
|
158 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)[,]'); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
163 | + */ |
|
164 | + public function testConstructEnumInvalidDefault() |
|
165 | + { |
|
166 | + $this->expectException('\SwaggerGen\Exception', "Invalid enum default: 'c'"); |
|
167 | + |
|
168 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=c'); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
173 | + */ |
|
174 | + public function testConstructEnum() |
|
175 | + { |
|
176 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)'); |
|
177 | + |
|
178 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
179 | + |
|
180 | + $this->assertSame(array( |
|
181 | + 'type' => 'string', |
|
182 | + 'enum' => array('a', 'b'), |
|
183 | + ), $object->toArray()); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
188 | + */ |
|
189 | + public function testConstructEnumWithDefault() |
|
190 | + { |
|
191 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=a'); |
|
192 | + |
|
193 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
194 | + |
|
195 | + $this->assertSame(array( |
|
196 | + 'type' => 'string', |
|
197 | + 'default' => 'a', |
|
198 | + 'enum' => array('a', 'b'), |
|
199 | + ), $object->toArray()); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
204 | + */ |
|
205 | + public function testConstructPattern() |
|
206 | + { |
|
207 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string([a-z])'); |
|
208 | + |
|
209 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
210 | + |
|
211 | + $this->assertSame(array( |
|
212 | + 'type' => 'string', |
|
213 | + 'pattern' => '[a-z]', |
|
214 | + ), $object->toArray()); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
219 | + */ |
|
220 | + public function testCommandDefaultNoValue() |
|
221 | + { |
|
222 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
223 | + |
|
224 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
225 | + |
|
226 | + $this->expectException('\SwaggerGen\Exception', "Empty string default"); |
|
227 | + $object->handleCommand('default', ''); |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
232 | + */ |
|
233 | + public function testCommandDefault() |
|
234 | + { |
|
235 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
236 | + |
|
237 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
238 | + |
|
239 | + $object->handleCommand('default', 'word'); |
|
240 | + |
|
241 | + $this->assertSame(array( |
|
242 | + 'type' => 'string', |
|
243 | + 'default' => 'word', |
|
244 | + ), $object->toArray()); |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
249 | + */ |
|
250 | + public function testCommandPattern() |
|
251 | + { |
|
252 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
253 | + |
|
254 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
255 | + |
|
256 | + $object->handleCommand('pattern', '[a-z]'); |
|
257 | + |
|
258 | + $this->assertSame(array( |
|
259 | + 'type' => 'string', |
|
260 | + 'pattern' => '[a-z]', |
|
261 | + ), $object->toArray()); |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
266 | + */ |
|
267 | + public function testCommandEnumWhenRange() |
|
268 | + { |
|
269 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[0,]'); |
|
270 | + |
|
271 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
272 | + |
|
273 | + $this->expectException('\SwaggerGen\Exception', "Enumeration not allowed in ranged string: 'red green blue'"); |
|
274 | + |
|
275 | + $object->handleCommand('enum', 'red green blue'); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
280 | + */ |
|
281 | + public function testCommandEnum() |
|
282 | + { |
|
283 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
284 | + |
|
285 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
286 | + |
|
287 | + $object->handleCommand('enum', 'red green blue'); |
|
288 | + |
|
289 | + $this->assertSame(array( |
|
290 | + 'type' => 'string', |
|
291 | + 'enum' => array('red', 'green', 'blue'), |
|
292 | + ), $object->toArray()); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | } |