Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
},
"scripts":{
"phpunit": "phpunit -c phpunit.xml.dist"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
}
}
51 changes: 20 additions & 31 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="true">
<testsuites>
<testsuite name="onoi-http-request-unit">
<directory>tests/phpunit/Unit</directory>
</testsuite>
<testsuite name="onoi-http-request-integration">
<directory>tests/phpunit/Integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<php>
<const name="WEB_SERVER_HOST" value="localhost" />
<const name="WEB_SERVER_PORT" value="13499" />
<const name="WEB_SERVER_DOCROOT" value="/http-public" />
</php>
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="onoi-http-request-unit">
<directory>tests/phpunit/Unit</directory>
</testsuite>
<testsuite name="onoi-http-request-integration">
<directory>tests/phpunit/Integration</directory>
</testsuite>
</testsuites>
<php>
<const name="WEB_SERVER_HOST" value="localhost"/>
<const name="WEB_SERVER_PORT" value="13499"/>
<const name="WEB_SERVER_DOCROOT" value="/http-public"/>
</php>
</phpunit>
2 changes: 1 addition & 1 deletion src/CurlRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CurlRequest implements HttpRequest {
*/
public function __construct( $handle ) {

if ( get_resource_type( $handle ) !== 'curl' ) {
if ( ( is_resource( $handle ) && get_resource_type( $handle ) !== 'curl' ) || $handle instanceof CurlHandle ) {
throw new InvalidArgumentException( "Expected a cURL resource type" );
}

Expand Down
2 changes: 1 addition & 1 deletion src/MultiCurlRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MultiCurlRequest implements HttpRequest {
*/
public function __construct( $handle ) {

if ( get_resource_type( $handle ) !== 'curl_multi' ) {
if ( ( is_resource( $handle ) && get_resource_type( $handle ) !== 'curl_multi' ) || $handle instanceof CurlMultiHandle ) {
throw new InvalidArgumentException( "Expected a cURL multi resource type" );
}

Expand Down
5 changes: 2 additions & 3 deletions tests/phpunit/Integration/RequestToExternalUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author mwjames
*/
class RequestToExternalUrlTest extends \PHPUnit_Framework_TestCase {
class RequestToExternalUrlTest extends \PHPUnit\Framework\TestCase {

public function testCachedRequestToExternalUrl() {

Expand All @@ -35,8 +35,7 @@ public function testCachedRequestToExternalUrl() {
$instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, 42 );
$instance->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX, 'foo' );

$this->assertInternalType(
'string',
$this->assertIsString(
$instance->execute()
);

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/Integration/RequestToPhpHttpdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author mwjames
*/
class RequestToPhpHttpdTest extends \PHPUnit_Framework_TestCase {
class RequestToPhpHttpdTest extends \PHPUnit\Framework\TestCase {

private static $pid;

Expand All @@ -25,7 +25,7 @@ class RequestToPhpHttpdTest extends \PHPUnit_Framework_TestCase {
* Options defined in phpunit.xml.dist
* @see https://github.com/vgno/tech.vg.no-1812/blob/master/features/bootstrap/FeatureContext.php
*/
public static function setUpBeforeClass() {
public static function setUpBeforeClass(): void {

$command = sprintf( 'php -S %s:%d -t %s >/dev/null 2>&1 & echo $!',
WEB_SERVER_HOST,
Expand All @@ -39,7 +39,7 @@ public static function setUpBeforeClass() {
self::$pid = (int) $output[0];
}

public static function tearDownAfterClass() {
public static function tearDownAfterClass(): void {
// exec( 'kill ' . (int) self::$pid );
}

Expand Down
24 changes: 11 additions & 13 deletions tests/phpunit/Unit/CachedCurlRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @author mwjames
*/
class CachedCurlRequestTest extends \PHPUnit_Framework_TestCase {
class CachedCurlRequestTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {

Expand Down Expand Up @@ -72,13 +72,12 @@ public function testDifferentOptionsToGenerateDifferentKeys() {
->setMethods( array( 'contains' ) )
->getMockForAbstractClass();

$cache->expects( $this->at( 0 ) )
$cache->expects( $this->exactly( 2 ) )
->method( 'contains' )
->with( $this->equalTo( 'onoi:http:7ccbcfd552a597d67077d6cc037580ac' ) );

$cache->expects( $this->at( 1 ) )
->method( 'contains' )
->with( $this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' ) );
->withConsecutive(
[$this->equalTo( 'onoi:http:7ccbcfd552a597d67077d6cc037580ac' )],
[$this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' )]
);

$instance = new CachedCurlRequest( curl_init(), $cache );

Expand All @@ -96,13 +95,12 @@ public function testToHaveTargetUrlAsPartOfTheCacheKey() {
->setMethods( array( 'contains', 'save' ) )
->getMockForAbstractClass();

$cache->expects( $this->at( 0 ) )
->method( 'contains' )
->with( $this->equalTo( 'onoi:http:236b194825be3d614ce5fc1b7763a278' ) );

$cache->expects( $this->at( 2 ) )
$cache->expects( $this->exactly( 2 ) )
->method( 'contains' )
->with( $this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' ) );
->withConsecutive(
[$this->equalTo( 'onoi:http:236b194825be3d614ce5fc1b7763a278' )],
[$this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' )]
);

$instance = new CachedCurlRequest( curl_init( 'http://example.org' ), $cache );

Expand Down
13 changes: 5 additions & 8 deletions tests/phpunit/Unit/CurlRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @author mwjames
*/
class CurlRequestTest extends \PHPUnit_Framework_TestCase {
class CurlRequestTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {

Expand All @@ -31,7 +31,7 @@ public function testCanConstruct() {
}

public function testWrongResourceTypeThrowsException() {
$this->setExpectedException( 'InvalidArgumentException' );
$this->expectException( 'InvalidArgumentException' );
new CurlRequest( curl_multi_init() );
}

Expand All @@ -45,8 +45,7 @@ public function testPing() {

$instance->setOption( CURLOPT_URL, 'http://example.org' );

$this->assertInternalType(
'boolean',
$this->assertIsBool(
$instance->ping()
);
}
Expand All @@ -55,8 +54,7 @@ public function testGetLastError() {

$instance = new CurlRequest( curl_init() );

$this->assertInternalType(
'string',
$this->assertIsString(
$instance->getLastError()
);
}
Expand All @@ -65,8 +63,7 @@ public function testGetLastErrorCode() {

$instance = new CurlRequest( curl_init() );

$this->assertInternalType(
'integer',
$this->assertIsInt(
$instance->getLastErrorCode()
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/Unit/Exception/BadHttpResponseExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*
* @author mwjames
*/
class BadHttpResponseExceptionTest extends \PHPUnit_Framework_TestCase {
class BadHttpResponseExceptionTest extends \PHPUnit\Framework\TestCase {

private $httpRequest;

protected function setUp() {
protected function setUp(): void {
parent::setUp();

$this->httpRequest = $this->getMockBuilder( '\Onoi\HttpRequest\HttpRequest' )
Expand Down Expand Up @@ -73,7 +73,7 @@ public function testForCurlRequest() {

$e = new BadHttpResponseException( $curlRequest );

$this->assertContains(
$this->assertStringContainsString(
'error 3',
$e->getMessage()
);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/Unit/Exception/HttpConnectionExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author mwjames
*/
class HttpConnectionExceptionTest extends \PHPUnit_Framework_TestCase {
class HttpConnectionExceptionTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {

Expand All @@ -28,7 +28,7 @@ public function testErrorMessage() {

$e = new HttpConnectionException( 'foo', 42 );

$this->assertContains(
$this->assertStringContainsString(
'foo',
$e->getMessage()
);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Unit/HttpRequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @author mwjames
*/
class HttpRequestFactoryTest extends \PHPUnit_Framework_TestCase {
class HttpRequestFactoryTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/Unit/MockedHttpStreamSocketRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*
* @author mwjames
*/
class MockedHttpStreamSocketRequestTest extends \PHPUnit_Framework_TestCase {
class MockedHttpStreamSocketRequestTest extends \PHPUnit\Framework\TestCase {

public function setUp() {
public function setUp(): void {
parent::setUp();

stream_wrapper_unregister( 'http' );
Expand Down Expand Up @@ -44,7 +44,7 @@ public function getMockStream( $data, $code = 'HTTP/1.1 200 OK' ) {
return fopen( 'http://example.com', 'r', false, $context );
}

public function tearDown() {
public function tearDown(): void {
stream_wrapper_restore('http');
}

Expand Down
10 changes: 4 additions & 6 deletions tests/phpunit/Unit/MultiCurlRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author mwjames
*/
class MultiCurlRequestTest extends \PHPUnit_Framework_TestCase {
class MultiCurlRequestTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {

Expand All @@ -32,7 +32,7 @@ public function testCanConstruct() {
}

public function testWrongResourceTypeThrowsException() {
$this->setExpectedException( 'InvalidArgumentException' );
$this->expectException( 'InvalidArgumentException' );
new MultiCurlRequest( curl_init() );
}

Expand Down Expand Up @@ -98,13 +98,11 @@ public function testExecuteForResponse() {
new CurlRequest( curl_init() )
);

$this->assertInternalType(
'array',
$this->assertIsArray(
$instance->execute()
);

$this->assertInternalType(
'string',
$this->assertIsString(
$instance->getLastError()
);

Expand Down
23 changes: 8 additions & 15 deletions tests/phpunit/Unit/NullRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @author mwjames
*/
class NullRequestTest extends \PHPUnit_Framework_TestCase {
class NullRequestTest extends \PHPUnit\Framework\TestCase {

public function testCanConstruct() {

Expand All @@ -34,38 +34,31 @@ public function testNull() {

$instance = new NullRequest();

$this->assertInternalType(
'boolean',
$this->assertIsBool(
$instance->ping()
);

$this->assertInternalType(
'null',
$this->assertNull(
$instance->setOption( 'foo', 42 )
);

$this->assertInternalType(
'null',
$this->assertNull(
$instance->getOption( 'foo' )
);

$this->assertInternalType(
'null',
$this->assertNull(
$instance->getLastTransferInfo()
);

$this->assertInternalType(
'string',
$this->assertIsString(
$instance->getLastError()
);

$this->assertInternalType(
'integer',
$this->assertIsInt(
$instance->getLastErrorCode()
);

$this->assertInternalType(
'null',
$this->assertNull(
$instance->execute()
);
}
Expand Down
Loading