Completed
Push — master ( 088bf6...a47832 )
by Martijn
02:41
created

ParameterTest::testConstructor_Optional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class ParameterTest extends SwaggerGen_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
	protected $parent;
7
8
	protected function setUp()
9
	{
10
		$this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject');
11
	}
12
13
	protected function assertPreConditions()
14
	{
15
		$this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent);
16
	}
17
18
	/**
19
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
20
	 */
21
	public function testConstructor_InEmpty()
22
	{
23
		$this->expectException('\SwaggerGen\Exception', "Invalid in for parameter: ''");
24
25
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, '', '');
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
26
	}
27
28
	/**
29
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
30
	 */
31
	public function testConstructor_InNotValid()
32
	{
33
		$this->expectException('\SwaggerGen\Exception', "Invalid in for parameter: 'foo'");
34
35
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'foo', '');
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36
	}
37
38
	/**
39
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
40
	 */
41
	public function testConstructor_DefinitionEmpty()
42
	{
43
		$this->expectException('\SwaggerGen\Exception', "No type definition for parameter");
44
45
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', '');
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46
	}
47
48
	/**
49
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
50
	 */
51
	public function testConstructor_NameEmpty()
52
	{
53
		$this->expectException('\SwaggerGen\Exception', "No name for parameter");
54
55
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int');
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
56
	}
57
58
	/**
59
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
60
	 */
61
	public function testConstructor_DefinitionUnknownType()
62
	{
63
		$this->expectException('\SwaggerGen\Exception', "Type format not recognized: 'foo'");
64
65
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'foo bar');
0 ignored issues
show
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
	}
67
68
	/**
69
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
70
	 */
71
	public function testConstructor()
72
	{
73
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo');
74
75
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
76
77
		$this->assertSame(array(
78
			'name' => 'foo',
79
			'in' => 'path',
80
			'required' => true,
81
			'type' => 'integer',
82
			'format' => 'int32',
83
				), $object->toArray());
84
	}
85
86
	/**
87
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
88
	 */
89
	public function testConstructor_PathAlwaysRequired()
90
	{
91
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo', false);
92
93
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
94
95
		$this->assertSame(array(
96
			'name' => 'foo',
97
			'in' => 'path',
98
			'required' => true,
99
			'type' => 'integer',
100
			'format' => 'int32',
101
				), $object->toArray());
102
	}
103
104
	/**
105
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
106
	 */
107
	public function testConstructor_Optional()
108
	{
109
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'query', 'int foo', false);
110
111
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
112
113
		$this->assertSame(array(
114
			'name' => 'foo',
115
			'in' => 'query',
116
			'type' => 'integer',
117
			'format' => 'int32',
118
				), $object->toArray());
119
	}
120
121
	/**
122
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
123
	 */
124
	public function testConstructor_Description()
125
	{
126
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo Some words');
127
128
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
129
130
		$this->assertSame(array(
131
			'name' => 'foo',
132
			'in' => 'path',
133
			'description' => 'Some words',
134
			'required' => true,
135
			'type' => 'integer',
136
			'format' => 'int32',
137
				), $object->toArray());
138
	}
139
140
	/**
141
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
142
	 */
143
	public function testConstructor_Form()
144
	{
145
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'form', 'int foo', false);
146
147
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
148
149
		$this->assertSame(array(
150
			'name' => 'foo',
151
			'in' => 'formData',
152
			'type' => 'integer',
153
			'format' => 'int32',
154
				), $object->toArray());
155
	}
156
157
	/**
158
	 * @covers \SwaggerGen\Swagger\Parameter::__construct
159
	 */
160
	public function testConstructor_Header()
161
	{
162
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'header', 'int foo', false);
163
164
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
165
166
		$this->assertSame(array(
167
			'name' => 'foo',
168
			'in' => 'header',
169
			'type' => 'integer',
170
			'format' => 'int32',
171
				), $object->toArray());
172
	}
173
174
	/**
175
	 * @covers \SwaggerGen\Swagger\Type\Parameter->handleCommand
176
	 */
177
	public function testHandleCommand_Passing()
178
	{
179
		$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo', false);
180
181
		$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object);
182
183
		$object->handleCommand('default', '123');
184
185
		$this->assertSame(array(
186
			'name' => 'foo',
187
			'in' => 'path',
188
			'required' => true,
189
			'type' => 'integer',
190
			'format' => 'int32',
191
			'default' => 123,
192
				), $object->toArray());
193
	}
194
195
}
196