@@ -90,24 +90,52 @@ public function testGetUploadedFiles()
90
90
$ this ->assertEquals ($ file , $ files [0 ]);
91
91
}
92
92
93
- public function testGetParsedBody ()
93
+ /**
94
+ * @dataProvider validParsedBodyParams
95
+ */
96
+ public function testGetParsedBody ($ value )
94
97
{
95
98
if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
96
99
$ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
97
100
}
98
101
99
- $ data = [
100
- 4711 ,
101
- null ,
102
- new \stdClass (),
103
- ['foo ' => 'bar ' , 'baz ' ],
102
+ $ new = $ this ->serverRequest ->withParsedBody ($ value );
103
+ $ this ->assertNull ($ this ->serverRequest ->getParsedBody (), 'withParsedBody MUST be immutable ' );
104
+ $ this ->assertEquals ($ value , $ new ->getParsedBody ());
105
+ }
106
+
107
+ public function validParsedBodyParams ()
108
+ {
109
+ return [
110
+ [null ],
111
+ [new \stdClass ()],
112
+ [['foo ' => 'bar ' , 'baz ' ]],
104
113
];
114
+ }
105
115
106
- foreach ($ data as $ item ) {
107
- $ new = $ this ->serverRequest ->withParsedBody ($ item );
108
- $ this ->assertNull ($ this ->serverRequest ->getParsedBody (), 'withParsedBody MUST be immutable ' );
109
- $ this ->assertEquals ($ item , $ new ->getParsedBody ());
116
+ /**
117
+ * @dataProvider invalidParsedBodyParams
118
+ * @expectedException \InvalidArgumentException
119
+ */
120
+ public function testGetParsedBodyInvalid ($ value )
121
+ {
122
+ if (isset ($ this ->skippedTests [__FUNCTION__ ])) {
123
+ $ this ->markTestSkipped ($ this ->skippedTests [__FUNCTION__ ]);
110
124
}
125
+
126
+ $ new = $ this ->serverRequest ->withParsedBody ($ value );
127
+ $ this ->assertNull ($ this ->serverRequest ->getParsedBody (), 'withParsedBody MUST be immutable ' );
128
+ $ this ->assertEquals ($ value , $ new ->getParsedBody ());
129
+ }
130
+
131
+ public function invalidParsedBodyParams ()
132
+ {
133
+ return [
134
+ [4711 ],
135
+ [47.11 ],
136
+ ['foobar ' ],
137
+ [true ],
138
+ ];
111
139
}
112
140
113
141
public function testGetAttributes ()
@@ -117,7 +145,9 @@ public function testGetAttributes()
117
145
}
118
146
119
147
$ new = $ this ->serverRequest ->withAttribute ('foo ' , 'bar ' );
120
- $ this ->assertNull ($ this ->serverRequest ->getAttributes (), 'withAttribute MUST be immutable ' );
148
+ $ oldAttributes = $ this ->serverRequest ->getAttributes ();
149
+ $ this ->assertInternalType ('array ' , $ oldAttributes , 'getAttributes MUST return an array ' );
150
+ $ this ->assertEmpty ($ oldAttributes , 'withAttribute MUST be immutable ' );
121
151
$ this ->assertEquals (['foo ' => 'bar ' ], $ new ->getAttributes ());
122
152
123
153
$ new = $ new ->withAttribute ('baz ' , 'biz ' );
0 commit comments