Skip to content

Commit a45aa4c

Browse files
authored
Merge pull request php-vcr#237 from carusogabriel/refactoring-tests
Refactoring tests
2 parents 90df7a9 + cb880d9 commit a45aa4c

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

tests/VCR/ConfigurationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public function testSetStorageInvalidName()
136136
public function testGetStorage()
137137
{
138138
$class = $this->config->getStorage();
139-
$this->assertTrue(in_array('Iterator', class_implements($class)));
140-
$this->assertTrue(in_array('Traversable', class_implements($class)));
141-
$this->assertTrue(in_array('VCR\Storage\AbstractStorage', class_parents($class)));
139+
$this->assertContains('Iterator', class_implements($class));
140+
$this->assertContains('Traversable', class_implements($class));
141+
$this->assertContains('VCR\Storage\AbstractStorage', class_parents($class));
142142
}
143143

144144
public function testWhitelist()

tests/VCR/LibraryHooks/CurlHookTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ public function testShouldReturnCurlInfoAll()
211211
$info = curl_getinfo($curlHandle);
212212
curl_close($curlHandle);
213213

214-
$this->assertTrue(is_array($info), 'curl_getinfo() should return an array.');
215-
$this->assertEquals(21, count($info), 'curl_getinfo() should return 21 values.');
214+
$this->assertInternalType('array', $info, 'curl_getinfo() should return an array.');
215+
$this->assertCount(21, $info, 'curl_getinfo() should return 21 values.');
216216
$this->curlHook->disable();
217217
}
218218

@@ -226,7 +226,7 @@ public function testShouldReturnCurlInfoAllKeys()
226226
$info = curl_getinfo($curlHandle);
227227
curl_close($curlHandle);
228228

229-
$this->assertTrue(is_array($info), 'curl_getinfo() should return an array.');
229+
$this->assertInternalType('array', $info, 'curl_getinfo() should return an array.');
230230
$this->assertArrayHasKey('url', $info);
231231
$this->assertArrayHasKey('content_type', $info);
232232
$this->assertArrayHasKey('http_code', $info);

tests/VCR/LibraryHooks/SoapHookTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testShouldInterceptCallWhenEnabled()
3838

3939
$this->soapHook->disable();
4040
$this->assertInstanceOf('\stdClass', $actual, 'Response was not returned.');
41-
$this->assertEquals(true, $actual->GetCityWeatherByZIPResult->Success, 'Response was not returned.');
41+
$this->assertTrue($actual->GetCityWeatherByZIPResult->Success, 'Response was not returned.');
4242
}
4343

4444
public function testShouldHandleSOAPVersion11()
@@ -86,7 +86,7 @@ public function testShouldReturnLastRequestWithTraceOn()
8686
$actual = $client->__getLastRequest();
8787

8888
$this->soapHook->disable();
89-
$this->assertTrue(!is_null($actual), '__getLastRequest() returned NULL.');
89+
$this->assertNotNull($actual, '__getLastRequest() returned NULL.');
9090
}
9191

9292
/**

tests/VCR/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testGetBody()
5151
public function testGetBodyNoneDefined()
5252
{
5353
$response = Response::fromArray(array());
54-
$this->assertEquals(null, $response->getBody(true));
54+
$this->assertNull($response->getBody(true));
5555
}
5656

5757
public function testRestoreBodyFromArray()

tests/VCR/Storage/YamlTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testStoreTwoRecording()
115115
foreach ($this->yamlObject as $recording) {
116116
$actual[] = $recording;
117117
}
118-
$this->assertEquals(2, count($actual), 'More that two recordings stores.');
118+
$this->assertCount(2, $actual, 'More that two recordings stores.');
119119
$this->assertEquals($expected, $actual[0], 'Storing and reading first recording failed.');
120120
$this->assertEquals($expected, $actual[1], 'Storing and reading second recording failed.');
121121
}

tests/VCR/Util/CurlHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testSetCurlOptionOnRequestPostFieldsEmptyString()
8080

8181
// This is consistent with how requests are read out of storage using
8282
// \VCR\Request::fromArray(array $request).
83-
$this->assertSame(null, $request->getBody());
83+
$this->assertNull($request->getBody());
8484
}
8585

8686
public function testSetCurlOptionOnRequestSetSingleHeader()

tests/VCR/Util/HttpUtilTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,37 @@ public function testParseResponseBasic()
88
{
99
$raw = "HTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
1010
list($status, $headers, $body) = HttpUtil::parseResponse($raw);
11-
11+
1212
$expectedHeaders = array(
1313
'Content-Type: text/html',
1414
'Date: Fri, 19 Jun 2015 16:05:18 GMT',
1515
'Vary: Accept-Encoding',
1616
'Content-Length: 0'
1717
);
18-
18+
1919
$this->assertEquals('HTTP/1.1 201 Created', $status);
2020
$this->assertEquals(null, $body);
2121
$this->assertEquals($expectedHeaders, $headers);
2222
}
23-
23+
2424
public function testParseResponseMultipleHeaders()
2525
{
2626
$raw = "HTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept, Accept-Language, Expect\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
2727
list($status, $headers, $body) = HttpUtil::parseResponse($raw);
28-
28+
2929
$expectedHeaders = array(
3030
'Content-Type: text/html',
3131
'Date: Fri, 19 Jun 2015 16:05:18 GMT',
3232
'Vary: Accept, Accept-Language, Expect',
3333
'Vary: Accept-Encoding',
3434
'Content-Length: 0'
3535
);
36-
36+
3737
$this->assertEquals('HTTP/1.1 201 Created', $status);
3838
$this->assertEquals(null, $body);
3939
$this->assertEquals($expectedHeaders, $headers);
4040
}
41-
41+
4242
public function testParseContinuePlusResponse()
4343
{
4444
$raw = "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
@@ -50,12 +50,12 @@ public function testParseContinuePlusResponse()
5050
'Vary: Accept-Encoding',
5151
'Content-Length: 0'
5252
);
53-
53+
5454
$this->assertEquals('HTTP/1.1 201 Created', $status);
5555
$this->assertEquals(null, $body);
5656
$this->assertEquals($expectedHeaders, $headers);
5757
}
58-
58+
5959
public function testParseiMultipleContinuePlusResponse()
6060
{
6161
$raw = "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
@@ -67,7 +67,7 @@ public function testParseiMultipleContinuePlusResponse()
6767
'Vary: Accept-Encoding',
6868
'Content-Length: 0'
6969
);
70-
70+
7171
$this->assertEquals('HTTP/1.1 201 Created', $status);
7272
$this->assertEquals(null, $body);
7373
$this->assertEquals($expectedHeaders, $headers);
@@ -78,15 +78,15 @@ public function testParseContinuePlusResponseMultipleHeaders()
7878
{
7979
$raw = "HTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 201 Created\r\nContent-Type: text/html\r\nDate: Fri, 19 Jun 2015 16:05:18 GMT\r\nVary: Accept, Accept-Language, Expect\r\nVary: Accept-Encoding\r\nContent-Length: 0\r\n\r\n";
8080
list($status, $headers, $body) = HttpUtil::parseResponse($raw);
81-
81+
8282
$expectedHeaders = array(
8383
'Content-Type: text/html',
8484
'Date: Fri, 19 Jun 2015 16:05:18 GMT',
8585
'Vary: Accept, Accept-Language, Expect',
8686
'Vary: Accept-Encoding',
8787
'Content-Length: 0'
8888
);
89-
89+
9090
$this->assertEquals('HTTP/1.1 201 Created', $status);
9191
$this->assertEquals(null, $body);
9292
$this->assertEquals($expectedHeaders, $headers);
@@ -109,7 +109,7 @@ public function testParseHeadersBasic()
109109
$outputArray = HttpUtil::parseHeaders($inputArray);
110110
$this->assertEquals($excpetedHeaders, $outputArray);
111111
}
112-
112+
113113
public function testParseHeadersMultiple()
114114
{
115115
$inputArray = array(

tests/integration/guzzle/test/VCR/Example/ExampleHttpClientTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function testRequestPOSTDirect()
5050
{
5151
$this->assertValidPOSTResponse($this->requestPOST());
5252
}
53-
53+
5454
public function testRequestPOSTIntercepted()
5555
{
5656
$this->assertValidPOSTResponse($this->requestPOSTIntercepted());
@@ -112,20 +112,20 @@ protected function requestPOSTIntercepted()
112112

113113
protected function assertValidGETResponse($info)
114114
{
115-
$this->assertTrue(is_array($info), 'Response is not an array.');
115+
$this->assertInternalType('array', $info, 'Response is not an array.');
116116
$this->assertArrayHasKey('url', $info, "Key 'url' not found.");
117117
$this->assertEquals(self::TEST_GET_URL, $info['url'], "Value for key 'url' wrong.");
118118
$this->assertArrayHasKey('headers', $info, "Key 'headers' not found.");
119-
$this->assertTrue(is_array($info['headers']), 'Headers is not an array.');
119+
$this->assertInternalType('array', $info['headers'], 'Headers is not an array.');
120120
}
121-
121+
122122
protected function assertValidPOSTResponse($info)
123123
{
124-
$this->assertTrue(is_array($info), 'Response is not an array.');
124+
$this->assertInternalType('array', $info, 'Response is not an array.');
125125
$this->assertArrayHasKey('url', $info, "Key 'url' not found.");
126126
$this->assertEquals(self::TEST_POST_URL, $info['url'], "Value for key 'url' wrong.");
127127
$this->assertArrayHasKey('headers', $info, "Key 'headers' not found.");
128-
$this->assertTrue(is_array($info['headers']), 'Headers is not an array.');
128+
$this->assertInternalType('array', $info['headers'], 'Headers is not an array.');
129129
$this->assertEquals(self::TEST_POST_BODY, $info['data'], 'Correct request body was not sent.');
130130
}
131131
}

0 commit comments

Comments
 (0)