Skip to content

Commit

Permalink
Merge pull request #414 from rmccue/feature/qa-tests-use-strict-asser…
Browse files Browse the repository at this point in the history
…tions

QA: use the most specific PHPUnit assertion possible
  • Loading branch information
schlessera committed Nov 5, 2020
2 parents fa35cf1 + 95e96ae commit cff2fcf
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 225 deletions.
18 changes: 9 additions & 9 deletions tests/Auth/Basic.php
Expand Up @@ -22,11 +22,11 @@ public function testUsingArray($transport) {
'transport' => $transport,
);
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
$this->assertEquals(200, $request->status_code);
$this->assertSame(200, $request->status_code);

$result = json_decode($request->body);
$this->assertEquals(true, $result->authenticated);
$this->assertEquals('user', $result->user);
$this->assertTrue($result->authenticated);
$this->assertSame('user', $result->user);
}

/**
Expand All @@ -43,11 +43,11 @@ public function testUsingInstantiation($transport) {
'transport' => $transport,
);
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
$this->assertEquals(200, $request->status_code);
$this->assertSame(200, $request->status_code);

$result = json_decode($request->body);
$this->assertEquals(true, $result->authenticated);
$this->assertEquals('user', $result->user);
$this->assertTrue($result->authenticated);
$this->assertSame('user', $result->user);
}

/**
Expand All @@ -65,15 +65,15 @@ public function testPOSTUsingInstantiation($transport) {
);
$data = 'test';
$request = Requests::post(httpbin('/post'), array(), $data, $options);
$this->assertEquals(200, $request->status_code);
$this->assertSame(200, $request->status_code);

$result = json_decode($request->body);

$auth = $result->headers->Authorization;
$auth = explode(' ', $auth);

$this->assertEquals(base64_encode('user:passwd'), $auth[1]);
$this->assertEquals('test', $result->data);
$this->assertSame(base64_encode('user:passwd'), $auth[1]);
$this->assertSame('test', $result->data);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/ChunkedEncoding.php
Expand Up @@ -43,7 +43,7 @@ public function testChunked($body, $expected) {
);
$response = Requests::get('http://example.com/', array(), $options);

$this->assertEquals($expected, $response->body);
$this->assertSame($expected, $response->body);
}

public static function notChunkedProvider() {
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testNotActuallyChunked($body) {
);
$response = Requests::get('http://example.com/', array(), $options);

$this->assertEquals($transport->body, $response->body);
$this->assertSame($transport->body, $response->body);
}


Expand All @@ -88,6 +88,6 @@ public function testMixedChunkiness() {
'transport' => $transport,
);
$response = Requests::get('http://example.com/', array(), $options);
$this->assertEquals($transport->body, $response->body);
$this->assertSame($transport->body, $response->body);
}
}
60 changes: 30 additions & 30 deletions tests/Cookies.php
Expand Up @@ -4,12 +4,12 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
public function testBasicCookie() {
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue');

$this->assertEquals('requests-testcookie', $cookie->name);
$this->assertEquals('testvalue', $cookie->value);
$this->assertEquals('testvalue', (string) $cookie);
$this->assertSame('requests-testcookie', $cookie->name);
$this->assertSame('testvalue', $cookie->value);
$this->assertSame('testvalue', (string) $cookie);

$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_header());
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_set_cookie());
$this->assertSame('requests-testcookie=testvalue', $cookie->format_for_header());
$this->assertSame('requests-testcookie=testvalue', $cookie->format_for_set_cookie());
}

public function testCookieWithAttributes() {
Expand All @@ -19,14 +19,14 @@ public function testCookieWithAttributes() {
);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);

$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_header());
$this->assertEquals('requests-testcookie=testvalue; httponly; path=/', $cookie->format_for_set_cookie());
$this->assertSame('requests-testcookie=testvalue', $cookie->format_for_header());
$this->assertSame('requests-testcookie=testvalue; httponly; path=/', $cookie->format_for_set_cookie());
}

public function testEmptyCookieName() {
$cookie = Requests_Cookie::parse('test');
$this->assertEquals('', $cookie->name);
$this->assertEquals('test', $cookie->value);
$this->assertSame('', $cookie->name);
$this->assertSame('test', $cookie->value);
}

public function testEmptyAttributes() {
Expand All @@ -50,7 +50,7 @@ public function testCookieJarUnsetter() {
$jar = new Requests_Cookie_Jar();
$jar['requests-testcookie'] = 'testvalue';

$this->assertEquals('testvalue', $jar['requests-testcookie']);
$this->assertSame('testvalue', $jar['requests-testcookie']);

unset($jar['requests-testcookie']);
$this->assertEmpty($jar['requests-testcookie']);
Expand All @@ -74,7 +74,7 @@ public function testCookieJarIterator() {
$jar = new Requests_Cookie_Jar($cookies);

foreach ($jar as $key => $value) {
$this->assertEquals($cookies[$key], $value);
$this->assertSame($cookies[$key], $value);
}
}

Expand All @@ -88,7 +88,7 @@ public function testReceivingCookies() {

$cookie = $response->cookies['requests-testcookie'];
$this->assertNotEmpty($cookie);
$this->assertEquals('testvalue', $cookie->value);
$this->assertSame('testvalue', $cookie->value);
}

public function testPersistenceOnRedirect() {
Expand All @@ -101,7 +101,7 @@ public function testPersistenceOnRedirect() {

$cookie = $response->cookies['requests-testcookie'];
$this->assertNotEmpty($cookie);
$this->assertEquals('testvalue', $cookie->value);
$this->assertSame('testvalue', $cookie->value);
}

protected function setCookieRequest($cookies) {
Expand All @@ -124,7 +124,7 @@ public function testSendingCookie() {
$data = $this->setCookieRequest($cookies);

$this->assertArrayHasKey('requests-testcookie1', $data);
$this->assertEquals('testvalue1', $data['requests-testcookie1']);
$this->assertSame('testvalue1', $data['requests-testcookie1']);
}

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ public function testSendingCookieWithJar() {
$data = $this->setCookieRequest($cookies);

$this->assertArrayHasKey('requests-testcookie1', $data);
$this->assertEquals('testvalue1', $data['requests-testcookie1']);
$this->assertSame('testvalue1', $data['requests-testcookie1']);
}

public function testSendingMultipleCookies() {
Expand All @@ -164,10 +164,10 @@ public function testSendingMultipleCookies() {
$data = $this->setCookieRequest($cookies);

$this->assertArrayHasKey('requests-testcookie1', $data);
$this->assertEquals('testvalue1', $data['requests-testcookie1']);
$this->assertSame('testvalue1', $data['requests-testcookie1']);

$this->assertArrayHasKey('requests-testcookie2', $data);
$this->assertEquals('testvalue2', $data['requests-testcookie2']);
$this->assertSame('testvalue2', $data['requests-testcookie2']);
}

public function testSendingMultipleCookiesWithJar() {
Expand All @@ -180,10 +180,10 @@ public function testSendingMultipleCookiesWithJar() {
$data = $this->setCookieRequest($cookies);

$this->assertArrayHasKey('requests-testcookie1', $data);
$this->assertEquals('testvalue1', $data['requests-testcookie1']);
$this->assertSame('testvalue1', $data['requests-testcookie1']);

$this->assertArrayHasKey('requests-testcookie2', $data);
$this->assertEquals('testvalue2', $data['requests-testcookie2']);
$this->assertSame('testvalue2', $data['requests-testcookie2']);
}

public function testSendingPrebakedCookie() {
Expand All @@ -195,7 +195,7 @@ public function testSendingPrebakedCookie() {
$data = $this->setCookieRequest($cookies);

$this->assertArrayHasKey('requests-testcookie', $data);
$this->assertEquals('testvalue', $data['requests-testcookie']);
$this->assertSame('testvalue', $data['requests-testcookie']);
}

public function domainMatchProvider() {
Expand Down Expand Up @@ -230,7 +230,7 @@ public function testDomainExactMatch($original, $check, $matches, $domain_matche
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['domain'] = $original;
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals($matches, $cookie->domain_matches($check));
$this->assertSame($matches, $cookie->domain_matches($check));
}

/**
Expand All @@ -243,7 +243,7 @@ public function testDomainMatch($original, $check, $matches, $domain_matches) {
'host-only' => false,
);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
$this->assertEquals($domain_matches, $cookie->domain_matches($check));
$this->assertSame($domain_matches, $cookie->domain_matches($check));
}

public function pathMatchProvider() {
Expand Down Expand Up @@ -273,7 +273,7 @@ public function testPathMatch($original, $check, $matches) {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['path'] = $original;
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals($matches, $cookie->path_matches($check));
$this->assertSame($matches, $cookie->path_matches($check));
}

public function urlMatchProvider() {
Expand Down Expand Up @@ -314,7 +314,7 @@ public function testUrlExactMatch($domain, $path, $check, $matches, $domain_matc
$attributes['path'] = $path;
$check = new Requests_IRI($check);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals($matches, $cookie->uri_matches($check));
$this->assertSame($matches, $cookie->uri_matches($check));
}

/**
Expand All @@ -331,7 +331,7 @@ public function testUrlMatch($domain, $path, $check, $matches, $domain_matches)
);
$check = new Requests_IRI($check);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
$this->assertEquals($domain_matches, $cookie->uri_matches($check));
$this->assertSame($domain_matches, $cookie->uri_matches($check));
}

public function testUrlMatchSecure() {
Expand Down Expand Up @@ -459,22 +459,22 @@ public static function parseResultProvider() {

protected function check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags = array()) {
if (isset($expected['name'])) {
$this->assertEquals($expected['name'], $cookie->name);
$this->assertSame($expected['name'], $cookie->name);
}
if (isset($expected['value'])) {
$this->assertEquals($expected['value'], $cookie->value);
$this->assertSame($expected['value'], $cookie->value);
}
if (isset($expected['expired'])) {
$this->assertEquals($expected['expired'], $cookie->is_expired());
$this->assertSame($expected['expired'], $cookie->is_expired());
}
if (isset($expected_attributes)) {
foreach ($expected_attributes as $attr_key => $attr_val) {
$this->assertEquals($attr_val, $cookie->attributes[$attr_key], "$attr_key should match supplied");
$this->assertSame($attr_val, $cookie->attributes[$attr_key], "$attr_key should match supplied");
}
}
if (isset($expected_flags)) {
foreach ($expected_flags as $flag_key => $flag_val) {
$this->assertEquals($flag_val, $cookie->flags[$flag_key], "$flag_key should match supplied");
$this->assertSame($flag_val, $cookie->flags[$flag_key], "$flag_key should match supplied");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Encoding.php
Expand Up @@ -74,15 +74,15 @@ public static function encodedData() {
*/
public function testDecompress($original, $encoded) {
$decoded = Requests::decompress($encoded);
$this->assertEquals($original, $decoded);
$this->assertSame($original, $decoded);
}

/**
* @dataProvider encodedData
*/
public function testCompatibleInflate($original, $encoded) {
$decoded = Requests::compatible_gzinflate($encoded);
$this->assertEquals($original, $decoded);
$this->assertSame($original, $decoded);
}

protected function bin2hex($field) {
Expand Down
10 changes: 5 additions & 5 deletions tests/IDNAEncoder.php
Expand Up @@ -19,7 +19,7 @@ public static function specExamples() {
*/
public function testEncoding($data, $expected) {
$result = Requests_IDNAEncoder::encode($data);
$this->assertEquals($expected, $result);
$this->assertSame($expected, $result);
}

/**
Expand Down Expand Up @@ -50,22 +50,22 @@ public function testAlreadyPrefixed() {

public function testASCIICharacter() {
$result = Requests_IDNAEncoder::encode('a');
$this->assertEquals('a', $result);
$this->assertSame('a', $result);
}

public function testTwoByteCharacter() {
$result = Requests_IDNAEncoder::encode("\xc2\xb6"); // Pilcrow character
$this->assertEquals('xn--tba', $result);
$this->assertSame('xn--tba', $result);
}

public function testThreeByteCharacter() {
$result = Requests_IDNAEncoder::encode("\xe2\x82\xac"); // Euro symbol
$this->assertEquals('xn--lzg', $result);
$this->assertSame('xn--lzg', $result);
}

public function testFourByteCharacter() {
$result = Requests_IDNAEncoder::encode("\xf0\xa4\xad\xa2"); // Chinese symbol?
$this->assertEquals('xn--ww6j', $result);
$this->assertSame('xn--ww6j', $result);
}

/**
Expand Down

0 comments on commit cff2fcf

Please sign in to comment.