Skip to content

Commit

Permalink
In progress fixes for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Robinson <drew.robinson@gmail.com>
  • Loading branch information
ocean committed Oct 14, 2020
1 parent d1d3b03 commit 72d7105
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 62 deletions.
36 changes: 18 additions & 18 deletions test/Client/CommonHttpTests.php
Expand Up @@ -335,7 +335,7 @@ public function testResetParameters()
$this->client->setMethod('POST');
$res = $this->client->send();

$this->assertNotContains(
$this->assertStringNotContainsString(
serialize($params),
$res->getBody(),
"returned body contains GET or POST parameters (it shouldn't!)"
Expand Down Expand Up @@ -369,8 +369,8 @@ public function testParameterUnset()
$this->client->setMethod('POST');
$res = $this->client->send();

$this->assertNotContains('cheese', $res->getBody(), 'The "cheese" GET parameter was expected to be unset');
$this->assertNotContains('alice', $res->getBody(), 'The "to" POST parameter was expected to be unset');
$this->assertStringNotContainsString('cheese', $res->getBody(), 'The "cheese" GET parameter was expected to be unset');
$this->assertStringNotContainsString('alice', $res->getBody(), 'The "to" POST parameter was expected to be unset');
}

/**
Expand Down Expand Up @@ -402,7 +402,7 @@ public function testHeadersSingle()
$body = strtolower($res->getBody());

foreach ($headers as $key => $val) {
$this->assertContains(strtolower($key . ': ' . $val), $body);
$this->assertStringContainsString(strtolower($key . ': ' . $val), $body);
}
}

Expand Down Expand Up @@ -432,9 +432,9 @@ public function testHeadersArray()

foreach ($headers as $key => $val) {
if (is_string($key)) {
$this->assertContains(strtolower($key . ': ' . $val), $body);
$this->assertStringContainsString(strtolower($key . ': ' . $val), $body);
} else {
$this->assertContains(strtolower($val), $body);
$this->assertStringContainsString(strtolower($val), $body);
}
}
}
Expand Down Expand Up @@ -473,7 +473,7 @@ public function testMultipleHeader()
$val = implode('; ', $val);
}

$this->assertContains(strtolower($key . ': ' . $val), $body);
$this->assertStringContainsString(strtolower($key . ': ' . $val), $body);
}
}

Expand All @@ -499,8 +499,8 @@ public function testRedirectDefault()
$this->assertEquals(3, $this->client->getRedirectionsCount(), 'Redirection counter is not as expected');

// Make sure the body does *not* contain the set parameters
$this->assertNotContains('swallow', $res->getBody());
$this->assertNotContains('Camelot', $res->getBody());
$this->assertStringNotContainsString('swallow', $res->getBody());
$this->assertStringNotContainsString('Camelot', $res->getBody());
}

/**
Expand All @@ -522,12 +522,12 @@ public function testRedirectPersistsCookies()
$this->assertEquals(3, $this->client->getRedirectionsCount(), 'Redirection counter is not as expected');

// Make sure the body does *not* contain the set parameters
$this->assertNotContains('swallow', $res->getBody());
$this->assertNotContains('Camelot', $res->getBody());
$this->assertStringNotContainsString('swallow', $res->getBody());
$this->assertStringNotContainsString('Camelot', $res->getBody());

// Check that we have received and persisted expected cookies
$cookies = $this->client->getCookies();
$this->assertInternalType('array', $cookies, 'Client is not sending cookies on redirect');
$this->assertIsArray($cookies, 'Client is not sending cookies on redirect');
$this->assertArrayHasKey('laminastestSessionCookie', $cookies, 'Client is not sending cookies on redirect');
$this->assertArrayHasKey('laminastestLongLivedCookie', $cookies, 'Client is not sending cookies on redirect');
$this->assertEquals('positive', $cookies['laminastestSessionCookie']->getValue());
Expand Down Expand Up @@ -558,8 +558,8 @@ public function testRedirectStrict()
$this->assertEquals(3, $this->client->getRedirectionsCount(), 'Redirection counter is not as expected');

// Make sure the body *does* contain the set parameters
$this->assertContains('swallow', $res->getBody());
$this->assertContains('Camelot', $res->getBody());
$this->assertStringContainsString('swallow', $res->getBody());
$this->assertStringContainsString('Camelot', $res->getBody());
}

/**
Expand Down Expand Up @@ -950,7 +950,7 @@ public function testStreamResponse()
$response = $this->client->send();

$this->assertInstanceOf(Stream::class, $response, 'Request did not return stream response!');
$this->assertInternalType('resource', $response->getStream(), 'Request does not contain stream!');
$this->assertIsResource($response->getStream(), 'Request does not contain stream!');

$streamName = $response->getStreamName();

Expand All @@ -977,7 +977,7 @@ public function testStreamResponseBody()
$response = $this->client->send();

$this->assertInstanceOf(Stream::class, $response, 'Request did not return stream response!');
$this->assertInternalType('resource', $response->getStream(), 'Request does not contain stream!');
$this->assertIsResource($response->getStream(), 'Request does not contain stream!');

$body = $response->getBody();

Expand All @@ -998,7 +998,7 @@ public function testStreamResponseNamed()
$response = $this->client->send();

$this->assertInstanceOf(Stream::class, $response, 'Request did not return stream response!');
$this->assertInternalType('resource', $response->getStream(), 'Request does not contain stream!');
$this->assertIsResource($response->getStream(), 'Request does not contain stream!');

$this->assertEquals($outfile, $response->getStreamName());

Expand Down Expand Up @@ -1089,7 +1089,7 @@ public function testUsesProvidedArgSeparator()
$request->setQuery(new Parameters(['foo' => 'bar', 'baz' => 'bat']));
$this->client->send($request);
$rawRequest = $this->client->getLastRawRequest();
$this->assertContains('?foo=bar;baz=bat', $rawRequest);
$this->assertStringContainsString('?foo=bar;baz=bat', $rawRequest);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test/Client/CurlTest.php
Expand Up @@ -176,8 +176,8 @@ public function testRedirectWithGetOnly()
$this->assertEquals(3, $this->client->getRedirectionsCount(), 'Redirection counter is not as expected');

// Make sure the body does *not* contain the set parameters
$this->assertNotContains('swallow', $res->getBody());
$this->assertNotContains('Camelot', $res->getBody());
$this->assertStringNotContainsString('swallow', $res->getBody());
$this->assertStringNotContainsString('Camelot', $res->getBody());
}

/**
Expand Down Expand Up @@ -357,7 +357,7 @@ public function testGetCurlHandle()
$adapter->setOptions(['timeout' => 2, 'maxredirects' => 1]);
$adapter->connect('getlaminas.org');

$this->assertInternalType('resource', $adapter->getHandle());
$this->assertIsResource($adapter->getHandle());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/Client/SocketTest.php
Expand Up @@ -357,7 +357,7 @@ public function testCaseInsensitiveHeaders()
'someTestBody'
);

$this->assertContains('x-test-header', $requestString);
$this->assertStringContainsString('x-test-header', $requestString);
}

/**
Expand Down
26 changes: 13 additions & 13 deletions test/Client/StaticClientTest.php
Expand Up @@ -64,7 +64,7 @@ public function testHttpGetWithParamsInUri()
{
$response = HTTPClient::get($this->baseuri . 'testGetData.php?foo');
$this->assertTrue($response->isSuccess());
$this->assertContains('foo', $response->getBody());
$this->assertStringContainsString('foo', $response->getBody());
}

/**
Expand All @@ -74,8 +74,8 @@ public function testHttpMultiGetWithParam()
{
$response = HTTPClient::get($this->baseuri . 'testGetData.php', ['foo' => 'bar']);
$this->assertTrue($response->isSuccess());
$this->assertContains('foo', $response->getBody());
$this->assertContains('bar', $response->getBody());
$this->assertStringContainsString('foo', $response->getBody());
$this->assertStringContainsString('bar', $response->getBody());
}

/**
Expand All @@ -93,9 +93,9 @@ public function testHttpGetWithBody()
);

$this->assertTrue($response->isSuccess());
$this->assertContains('foo', $response->getBody());
$this->assertContains('bar', $response->getBody());
$this->assertContains($getBody, $response->getBody());
$this->assertStringContainsString('foo', $response->getBody());
$this->assertStringContainsString('bar', $response->getBody());
$this->assertStringContainsString($getBody, $response->getBody());
}

/**
Expand All @@ -105,8 +105,8 @@ public function testHttpSimplePost()
{
$response = HTTPClient::post($this->baseuri . 'testPostData.php', ['foo' => 'bar']);
$this->assertTrue($response->isSuccess());
$this->assertContains('foo', $response->getBody());
$this->assertContains('bar', $response->getBody());
$this->assertStringContainsString('foo', $response->getBody());
$this->assertStringContainsString('bar', $response->getBody());
}

/**
Expand All @@ -120,8 +120,8 @@ public function testHttpPostContentType()
['Content-Type' => Client::ENC_URLENCODED]
);
$this->assertTrue($response->isSuccess());
$this->assertContains('foo', $response->getBody());
$this->assertContains('bar', $response->getBody());
$this->assertStringContainsString('foo', $response->getBody());
$this->assertStringContainsString('bar', $response->getBody());
}

/**
Expand All @@ -139,7 +139,7 @@ public function testHttpPostWithBody()
);

$this->assertTrue($response->isSuccess());
$this->assertContains($postBody, $response->getBody());
$this->assertStringContainsString($postBody, $response->getBody());
}

/**
Expand All @@ -164,7 +164,7 @@ public function testHttpGetUsesAdapterConfig()

$rawRequest = $client->getLastRawRequest();

$this->assertContains('User-Agent: simplegettest', $rawRequest);
$this->assertStringContainsString('User-Agent: simplegettest', $rawRequest);
}

/**
Expand All @@ -189,6 +189,6 @@ public function testHttpPostUsesAdapterConfig()

$rawRequest = $client->getLastRawRequest();

$this->assertContains('User-Agent: simpleposttest', $rawRequest);
$this->assertStringContainsString('User-Agent: simpleposttest', $rawRequest);
}
}
11 changes: 5 additions & 6 deletions test/Client/StaticTest.php
Expand Up @@ -76,8 +76,7 @@ public function testSetGetUriString()
$this->assertEquals($uri->__toString(), $uristr, 'Returned Uri object does not hold the expected URI');

$uri = $this->_client->getUri()->toString();
$this->assertInternalType(
'string',
$this->assertIsString(
$uri,
'Returned value expected to be a string, ' . gettype($uri) . ' returned'
);
Expand Down Expand Up @@ -111,7 +110,7 @@ public function testDoubleGetParameter()
$this->_client->setMethod('GET');
$this->_client->send();

$this->assertContains(
$this->assertStringContainsString(
$qstr,
$this->_client->getLastRawRequest(),
'Request is expected to contain the entire query string'
Expand Down Expand Up @@ -174,7 +173,7 @@ public function testSetNewCookies()
$cookies = $this->_client->getCookies();

// Check we got the right cookiejar
$this->assertInternalType('array', $cookies);
$this->assertIsArray($cookies);
$this->assertContainsOnlyInstancesOf(SetCookie::class, $cookies);
$this->assertCount(2, $cookies);
}
Expand Down Expand Up @@ -574,7 +573,7 @@ public function testEncodedCookiesInRequestHeaders()
$this->_client->addCookie('foo', 'bar=baz');
$this->_client->send();
$cookieValue = 'Cookie: foo=' . urlencode('bar=baz');
$this->assertContains(
$this->assertStringContainsString(
$cookieValue,
$this->_client->getLastRawRequest(),
'Request is expected to contain the entire cookie "keyname=encoded_value"'
Expand All @@ -598,7 +597,7 @@ public function testRawCookiesInRequestHeaders()
$this->_client->addCookie('foo', 'bar=baz');
$this->_client->send();
$cookieValue = 'Cookie: foo=bar=baz';
$this->assertContains(
$this->assertStringContainsString(
$cookieValue,
$this->_client->getLastRawRequest(),
'Request is expected to contain the entire cookie "keyname=raw_value"'
Expand Down
27 changes: 13 additions & 14 deletions test/ClientTest.php
Expand Up @@ -208,10 +208,10 @@ public function testClientUsesAcceptEncodingHeaderFromRequestObject()

$rawRequest = $client->getLastRawRequest();

$this->assertNotContains('Accept-Encoding: gzip, deflate', $rawRequest, '', true);
$this->assertNotContains('Accept-Encoding: identity', $rawRequest, '', true);
$this->assertStringNotContainsString('Accept-Encoding: gzip, deflate', $rawRequest, '', true);
$this->assertStringNotContainsString('Accept-Encoding: identity', $rawRequest, '', true);

$this->assertContains('Accept-Encoding: foo', $rawRequest);
$this->assertStringContainsString('Accept-Encoding: foo', $rawRequest);
}

public function testEncodeAuthHeaderWorksAsExpected()
Expand Down Expand Up @@ -298,7 +298,7 @@ public function testIfClientDoesNotLooseAuthenticationOnRedirect()
$client->setMethod('GET')->send();

// the last request should contain the Authorization header
$this->assertContains($encoded, $client->getLastRawRequest());
$this->assertStringContainsString($encoded, $client->getLastRawRequest());
}

public function testIfClientDoesNotForwardAuthenticationToForeignHost()
Expand Down Expand Up @@ -329,7 +329,7 @@ public function testIfClientDoesNotForwardAuthenticationToForeignHost()

// the last request should NOT contain the Authorization header,
// because example.com is different from example.org
$this->assertNotContains($encoded, $client->getLastRawRequest());
$this->assertStringNotContainsString($encoded, $client->getLastRawRequest());

// set up two responses that simulate a redirection from example.org to sub.example.org
$testAdapter->setResponse(
Expand All @@ -349,7 +349,7 @@ public function testIfClientDoesNotForwardAuthenticationToForeignHost()

// the last request should contain the Authorization header,
// because sub.example.org is a subdomain unter example.org
$this->assertContains($encoded, $client->getLastRawRequest());
$this->assertStringContainsString($encoded, $client->getLastRawRequest());

// set up two responses that simulate a rediration from sub.example.org to example.org
$testAdapter->setResponse(
Expand All @@ -369,7 +369,7 @@ public function testIfClientDoesNotForwardAuthenticationToForeignHost()

// the last request should NOT contain the Authorization header,
// because example.org is not a subdomain unter sub.example.org
$this->assertNotContains($encoded, $client->getLastRawRequest());
$this->assertStringNotContainsString($encoded, $client->getLastRawRequest());
}

public function testAdapterAlwaysReachableIfSpecified()
Expand Down Expand Up @@ -426,9 +426,9 @@ public function testPrepareHeadersCurlDigestAuthentication()

$headers = $prepareHeadersReflection->invoke($client, $body, new Http('http://localhost:5984'));

$this->assertInternalType('array', $headers);
$this->assertIsArray($headers);
$this->assertArrayHasKey('Authorization', $headers);
$this->assertContains('Digest', $headers['Authorization']);
$this->assertStringContainsString('Digest', $headers['Authorization']);
}

/**
Expand All @@ -440,14 +440,13 @@ public function testCanSpecifyCustomAuthMethodsInExtendingClasses()

$client->setAuth('username', 'password', ExtendedClient::AUTH_CUSTOM);

$this->assertAttributeEquals(
$this->assertEquals(
[
'user' => 'username',
'password' => 'password',
'type' => ExtendedClient::AUTH_CUSTOM,
],
'auth',
$client
$client->auth
);
}

Expand Down Expand Up @@ -527,7 +526,7 @@ public function testFormUrlEncodeSeparator()
$client->setAdapter(Test::class);
$client->send($request);
$rawRequest = $client->getLastRawRequest();
$this->assertContains('foo=bar&baz=foo', $rawRequest);
$this->assertStringContainsString('foo=bar&baz=foo', $rawRequest);
}

public function uriDataProvider()
Expand Down Expand Up @@ -646,7 +645,7 @@ public function testDefaultUserAgentDoesNotUseEscapeCharacter()
$r = new ReflectionProperty($client, 'config');
$r->setAccessible(true);
$config = $r->getValue($client);
$this->assertInternalType('array', $config);
$this->assertIsArray($config);
$this->assertArrayHasKey('useragent', $config);
$this->assertSame('Laminas_Http_Client', $config['useragent']);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Header/GenericHeaderTest.php
Expand Up @@ -51,7 +51,7 @@ public function testInvalidFieldName($name)
}

/**
* @group 7295
* @group ZF#7295
*/
public function testDoesNotReplaceUnderscoresWithDashes()
{
Expand Down

0 comments on commit 72d7105

Please sign in to comment.