Skip to content

Commit 5163e1c

Browse files
committed
Fix php-curl-class#67: Change assertTrue to assertEquals where appropriate
1 parent 2d883ce commit 5163e1c

File tree

1 file changed

+53
-61
lines changed

1 file changed

+53
-61
lines changed

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public function testCaseInsensitiveArraySet()
4848
function assertions($array, $count = 1)
4949
{
5050
PHPUnit_Framework_Assert::assertCount($count, $array);
51-
PHPUnit_Framework_Assert::assertTrue($array['foo'] === 'bar');
52-
PHPUnit_Framework_Assert::assertTrue($array['Foo'] === 'bar');
53-
PHPUnit_Framework_Assert::assertTrue($array['FOo'] === 'bar');
54-
PHPUnit_Framework_Assert::assertTrue($array['FOO'] === 'bar');
51+
PHPUnit_Framework_Assert::assertEquals($array['foo'], 'bar');
52+
PHPUnit_Framework_Assert::assertEquals($array['Foo'], 'bar');
53+
PHPUnit_Framework_Assert::assertEquals($array['FOo'], 'bar');
54+
PHPUnit_Framework_Assert::assertEquals($array['FOO'], 'bar');
5555
}
5656

5757
$array = new CaseInsensitiveArray();
@@ -86,17 +86,17 @@ public function testUserAgent()
8686
public function testGet()
8787
{
8888
$test = new Test();
89-
$this->assertTrue($test->server('server', 'GET', array(
89+
$this->assertEquals($test->server('server', 'GET', array(
9090
'key' => 'REQUEST_METHOD',
91-
)) === 'GET');
91+
)), 'GET');
9292
}
9393

9494
public function testPostRequestMethod()
9595
{
9696
$test = new Test();
97-
$this->assertTrue($test->server('server', 'POST', array(
97+
$this->assertEquals($test->server('server', 'POST', array(
9898
'key' => 'REQUEST_METHOD',
99-
)) === 'POST');
99+
)), 'POST');
100100
}
101101

102102
public function testPostContinueResponse()
@@ -136,15 +136,15 @@ public function testPostContinueResponse()
136136
public function testPostData()
137137
{
138138
$test = new Test();
139-
$this->assertTrue($test->server('post', 'POST', array(
139+
$this->assertEquals($test->server('post', 'POST', array(
140140
'key' => 'value',
141-
)) === 'key=value');
141+
)), 'key=value');
142142
}
143143

144144
public function testPostAssociativeArrayData()
145145
{
146146
$test = new Test();
147-
$this->assertTrue(
147+
$this->assertEquals(
148148
$test->server('post_multidimensional', 'POST', array(
149149
'username' => 'myusername',
150150
'password' => 'mypassword',
@@ -154,7 +154,7 @@ public function testPostAssociativeArrayData()
154154
'param3' => 123,
155155
'param4' => 3.14,
156156
),
157-
)) ===
157+
)),
158158
'username=myusername' .
159159
'&password=mypassword' .
160160
'&more_data%5B' .
@@ -168,25 +168,25 @@ public function testPostAssociativeArrayData()
168168
public function testPostMultidimensionalData()
169169
{
170170
$test = new Test();
171-
$this->assertTrue($test->server('post_multidimensional', 'POST', array(
171+
$this->assertEquals($test->server('post_multidimensional', 'POST', array(
172172
'key' => 'file',
173173
'file' => array(
174174
'wibble',
175175
'wubble',
176176
'wobble',
177177
),
178-
)) === 'key=file&file%5B%5D=wibble&file%5B%5D=wubble&file%5B%5D=wobble');
178+
)), 'key=file&file%5B%5D=wibble&file%5B%5D=wubble&file%5B%5D=wobble');
179179
}
180180

181181
public function testPostFilePathUpload()
182182
{
183183
$file_path = Helper\get_png();
184184

185185
$test = new Test();
186-
$this->assertTrue($test->server('post_file_path_upload', 'POST', array(
186+
$this->assertEquals($test->server('post_file_path_upload', 'POST', array(
187187
'key' => 'image',
188188
'image' => '@' . $file_path,
189-
)) === 'image/png');
189+
)), 'image/png');
190190

191191
unlink($file_path);
192192
$this->assertFalse(file_exists($file_path));
@@ -198,10 +198,10 @@ public function testPostCurlFileUpload()
198198
$file_path = Helper\get_png();
199199

200200
$test = new Test();
201-
$this->assertTrue($test->server('post_file_path_upload', 'POST', array(
201+
$this->assertEquals($test->server('post_file_path_upload', 'POST', array(
202202
'key' => 'image',
203203
'image' => new CURLFile($file_path),
204-
)) === 'image/png');
204+
)), 'image/png');
205205

206206
unlink($file_path);
207207
$this->assertFalse(file_exists($file_path));
@@ -211,15 +211,15 @@ public function testPostCurlFileUpload()
211211
public function testPutRequestMethod()
212212
{
213213
$test = new Test();
214-
$this->assertTrue($test->server('request_method', 'PUT') === 'PUT');
214+
$this->assertEquals($test->server('request_method', 'PUT'), 'PUT');
215215
}
216216

217217
public function testPutData()
218218
{
219219
$test = new Test();
220-
$this->assertTrue($test->server('put', 'PUT', array(
220+
$this->assertEquals($test->server('put', 'PUT', array(
221221
'key' => 'value',
222-
)) === 'key=value');
222+
)), 'key=value');
223223
}
224224

225225
public function testPutFileHandle()
@@ -236,27 +236,27 @@ public function testPutFileHandle()
236236

237237
fclose($tmp_file);
238238

239-
$this->assertTrue($test->curl->response === 'image/png');
239+
$this->assertEquals($test->curl->response, 'image/png');
240240
}
241241

242242
public function testPatchRequestMethod()
243243
{
244244
$test = new Test();
245-
$this->assertTrue($test->server('request_method', 'PATCH') === 'PATCH');
245+
$this->assertEquals($test->server('request_method', 'PATCH'), 'PATCH');
246246
}
247247

248248
public function testDelete()
249249
{
250250
$test = new Test();
251-
$this->assertTrue($test->server('server', 'DELETE', array(
251+
$this->assertEquals($test->server('server', 'DELETE', array(
252252
'key' => 'REQUEST_METHOD',
253-
)) === 'DELETE');
253+
)), 'DELETE');
254254

255255
$test = new Test();
256-
$this->assertTrue($test->server('delete', 'DELETE', array(
256+
$this->assertEquals($test->server('delete', 'DELETE', array(
257257
'test' => 'delete',
258258
'key' => 'test',
259-
)) === 'delete');
259+
)), 'delete');
260260
}
261261

262262
public function testHeadRequestMethod()
@@ -281,7 +281,7 @@ public function testOptionsRequestMethod()
281281
public function testBasicHttpAuth401Unauthorized()
282282
{
283283
$test = new Test();
284-
$this->assertTrue($test->server('http_basic_auth', 'GET') === 'canceled');
284+
$this->assertEquals($test->server('http_basic_auth', 'GET'), 'canceled');
285285
}
286286

287287
public function testBasicHttpAuthSuccess()
@@ -292,17 +292,17 @@ public function testBasicHttpAuthSuccess()
292292
$test->curl->setBasicAuthentication($username, $password);
293293
$test->server('http_basic_auth', 'GET');
294294
$json = $test->curl->response;
295-
$this->assertTrue($json->username === $username);
296-
$this->assertTrue($json->password === $password);
295+
$this->assertEquals($json->username, $username);
296+
$this->assertEquals($json->password, $password);
297297
}
298298

299299
public function testReferrer()
300300
{
301301
$test = new Test();
302302
$test->curl->setReferrer('myreferrer');
303-
$this->assertTrue($test->server('server', 'GET', array(
303+
$this->assertEquals($test->server('server', 'GET', array(
304304
'key' => 'HTTP_REFERER',
305-
)) === 'myreferrer');
305+
)), 'myreferrer');
306306
}
307307

308308
public function testResponseBody()
@@ -318,17 +318,17 @@ public function testResponseBody()
318318
) as $request_method => $expected_response) {
319319
$curl = new Curl();
320320
$curl->setHeader('X-DEBUG-TEST', 'response_body');
321-
$this->assertTrue($curl->$request_method(Test::TEST_URL) === $expected_response);
321+
$this->assertEquals($curl->$request_method(Test::TEST_URL), $expected_response);
322322
}
323323
}
324324

325325
public function testCookies()
326326
{
327327
$test = new Test();
328328
$test->curl->setCookie('mycookie', 'yum');
329-
$this->assertTrue($test->server('cookie', 'GET', array(
329+
$this->assertEquals($test->server('cookie', 'GET', array(
330330
'key' => 'mycookie',
331-
)) === 'yum');
331+
)), 'yum');
332332
}
333333

334334
public function testCookieEncoding()
@@ -359,9 +359,9 @@ public function testCookieFile()
359359

360360
$test = new Test();
361361
$test->curl->setCookieFile($cookie_file);
362-
$this->assertTrue($test->server('cookie', 'GET', array(
362+
$this->assertEquals($test->server('cookie', 'GET', array(
363363
'key' => 'mycookie',
364-
)) === 'yum');
364+
)), 'yum');
365365

366366
unlink($cookie_file);
367367
$this->assertFalse(file_exists($cookie_file));
@@ -402,7 +402,7 @@ public function testError()
402402
$test->curl->get(Test::ERROR_URL);
403403
$this->assertTrue($test->curl->error);
404404
$this->assertTrue($test->curl->curl_error);
405-
$this->assertTrue($test->curl->curl_error_code === CURLE_OPERATION_TIMEOUTED);
405+
$this->assertEquals($test->curl->curl_error_code, CURLE_OPERATION_TIMEOUTED);
406406
}
407407

408408
public function testErrorMessage()
@@ -424,15 +424,15 @@ public function testHeaders()
424424
$test->curl->setHeader('Content-Type', 'application/json');
425425
$test->curl->setHeader('X-Requested-With', 'XMLHttpRequest');
426426
$test->curl->setHeader('Accept', 'application/json');
427-
$this->assertTrue($test->server('server', 'GET', array(
427+
$this->assertEquals($test->server('server', 'GET', array(
428428
'key' => 'CONTENT_TYPE',
429-
)) === 'application/json');
430-
$this->assertTrue($test->server('server', 'GET', array(
429+
)), 'application/json');
430+
$this->assertEquals($test->server('server', 'GET', array(
431431
'key' => 'HTTP_X_REQUESTED_WITH',
432-
)) === 'XMLHttpRequest');
433-
$this->assertTrue($test->server('server', 'GET', array(
432+
)), 'XMLHttpRequest');
433+
$this->assertEquals($test->server('server', 'GET', array(
434434
'key' => 'HTTP_ACCEPT',
435-
)) === 'application/json');
435+
)), 'application/json');
436436
}
437437

438438
public function testHeaderCaseSensitivity()
@@ -494,9 +494,7 @@ public function testNestedData()
494494
),
495495
),
496496
);
497-
$this->assertTrue(
498-
$test->server('post', 'POST', $data) === http_build_query($data)
499-
);
497+
$this->assertEquals($test->server('post', 'POST', $data), http_build_query($data));
500498
}
501499

502500
public function testPostStringUrlEncodedContentType()
@@ -679,7 +677,7 @@ public function testArrayToStringConversion()
679677
'baz' => array(
680678
),
681679
));
682-
$this->assertTrue($test->curl->response === 'foo=bar&baz=');
680+
$this->assertEquals($test->curl->response, 'foo=bar&baz=');
683681

684682
$test = new Test();
685683
$test->server('post', 'POST', array(
@@ -689,10 +687,7 @@ public function testArrayToStringConversion()
689687
),
690688
),
691689
));
692-
$this->assertTrue(
693-
urldecode($test->curl->response) ===
694-
'foo=bar&baz[qux]='
695-
);
690+
$this->assertEquals(urldecode($test->curl->response), 'foo=bar&baz[qux]=');
696691

697692
$test = new Test();
698693
$test->server('post', 'POST', array(
@@ -703,10 +698,7 @@ public function testArrayToStringConversion()
703698
'wibble' => 'wobble',
704699
),
705700
));
706-
$this->assertTrue(
707-
urldecode($test->curl->response) ===
708-
'foo=bar&baz[qux]=&baz[wibble]=wobble'
709-
);
701+
$this->assertEquals(urldecode($test->curl->response), 'foo=bar&baz[qux]=&baz[wibble]=wobble');
710702
}
711703

712704
public function testParallelRequests()
@@ -725,9 +717,9 @@ public function testParallelRequests()
725717
));
726718

727719
$len = strlen('/a/?foo=bar');
728-
$this->assertTrue(substr($curl->curls['0']->response, - $len) === '/a/?foo=bar');
729-
$this->assertTrue(substr($curl->curls['1']->response, - $len) === '/b/?foo=bar');
730-
$this->assertTrue(substr($curl->curls['2']->response, - $len) === '/c/?foo=bar');
720+
$this->assertEquals(substr($curl->curls['0']->response, - $len), '/a/?foo=bar');
721+
$this->assertEquals(substr($curl->curls['1']->response, - $len), '/b/?foo=bar');
722+
$this->assertEquals(substr($curl->curls['2']->response, - $len), '/c/?foo=bar');
731723
}
732724

733725
public function testParallelRequestErrors()
@@ -738,7 +730,7 @@ public function testParallelRequestErrors()
738730
$curl->complete(function ($instance) use (&$success_called, &$error_called, &$complete_called) {
739731
PHPUnit_Framework_Assert::assertTrue($instance->error);
740732
PHPUnit_Framework_Assert::assertTrue($instance->curl_error);
741-
PHPUnit_Framework_Assert::assertTrue($instance->curl_error_code === CURLE_OPERATION_TIMEOUTED);
733+
PHPUnit_Framework_Assert::assertEquals($instance->curl_error_code, CURLE_OPERATION_TIMEOUTED);
742734
});
743735
$curl->get(array(
744736
Test::ERROR_URL . 'a/',
@@ -754,7 +746,7 @@ public function testParallelSetOptions()
754746
$curl->setHeader('X-DEBUG-TEST', 'server');
755747
$curl->setOpt(CURLOPT_USERAGENT, 'useragent');
756748
$curl->complete(function ($instance) {
757-
PHPUnit_Framework_Assert::assertTrue($instance->response === 'useragent');
749+
PHPUnit_Framework_Assert::assertEquals($instance->response, 'useragent');
758750
});
759751
$curl->get(array(
760752
Test::TEST_URL,

0 commit comments

Comments
 (0)