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