Skip to content

Commit

Permalink
Use PHPUnit 8
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 10, 2019
1 parent f154007 commit 968cfbf
Show file tree
Hide file tree
Showing 20 changed files with 139 additions and 187 deletions.
1 change: 0 additions & 1 deletion .gitattributes
@@ -1,4 +1,3 @@
.coveralls.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
Expand Down
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.phpunit.result.cache
build
composer.lock
tests/sandbox
Expand Down
15 changes: 8 additions & 7 deletions .travis.yml
Expand Up @@ -2,19 +2,20 @@ sudo: false

cache:
directories:
- $COMPOSER_CACHE_DIR
- $HOME/.composer/cache
- $TRAVIS_BUILD_DIR/build
- $COMPOSER_CACHE_DIR
- $HOME/.composer/cache
- $TRAVIS_BUILD_DIR/build

language: php

php:
- 7.2
- nightly
- "7.2"
- "7.3"
- nightly

matrix:
allow_failures:
- php: nightly
- php: nightly

script:
- if [[ $TRAVIS_PHP_VERSION == "7.2" ]]; then make test-coveralls; else make test; fi
- if [[ $TRAVIS_PHP_VERSION == "7.2" ]]; then make test-coveralls; else make test; fi
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,7 +1,7 @@
The icanboogie/http package is free software.
It is released under the terms of the following BSD License.

Copyright (c) 2011-2018 by Olivier Laviale
Copyright (c) 2011-2019 by Olivier Laviale
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Expand Up @@ -2,7 +2,7 @@

PACKAGE_NAME = icanboogie/http
PACKAGE_VERSION = 4.0
PHPUNIT_VERSION = phpunit-7.phar
PHPUNIT_VERSION = phpunit-8.phar
PHPUNIT_FILENAME = build/$(PHPUNIT_VERSION)
PHPUNIT = php $(PHPUNIT_FILENAME)

Expand All @@ -26,19 +26,22 @@ $(PHPUNIT_FILENAME):
mkdir -p build
wget https://phar.phpunit.de/$(PHPUNIT_VERSION) -O $(PHPUNIT_FILENAME)

test: all
test: all test-cleanup
@$(PHPUNIT)

test-coverage: all
test-coverage: all test-cleanup
@mkdir -p build/coverage
@$(PHPUNIT) --coverage-html build/coverage

test-coveralls: all
test-coveralls: all test-cleanup
@mkdir -p build/logs
COMPOSER_ROOT_VERSION=$(PACKAGE_VERSION) composer require satooshi/php-coveralls
@$(PHPUNIT) --coverage-clover build/logs/clover.xml
php vendor/bin/php-coveralls -v

test-cleanup:
rm -rf tests/sandbox/*

doc: vendor
@mkdir -p build/docs
@apigen generate \
Expand Down
13 changes: 4 additions & 9 deletions phpunit.xml
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.3/phpunit.xsd"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
Expand All @@ -18,7 +13,7 @@
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<whitelist>
<directory suffix=".php">./lib</directory>
</whitelist>
</filter>
Expand Down
6 changes: 2 additions & 4 deletions tests/DispatcherProviderTest.php
Expand Up @@ -13,16 +13,14 @@

class DispatcherProviderTest extends \PHPUnit\Framework\TestCase
{
public function tearDown()
protected function tearDown(): void
{
DispatcherProvider::undefine();
}

/**
* @expectedException \ICanBoogie\HTTP\DispatcherProviderNotDefined
*/
public function test_should_throw_exception_when_no_provider_is_defined()
{
$this->expectException(DispatcherProviderNotDefined::class);
DispatcherProvider::provide();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/DispatcherTest.php
Expand Up @@ -21,7 +21,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
*/
private $events;

public function setUp()
protected function setUp(): void
{
$this->events = $events = new EventCollection;

Expand Down Expand Up @@ -91,12 +91,10 @@ public function testDispatcherRescueEvent()
$this->assertEquals('Rescued: Damned!', $response->body);
}

/**
* @expectedException \ICanBoogie\HTTP\NotFound
*/
public function testNotFound()
{
$dispatcher = new RequestDispatcher;
$this->expectException(NotFound::class);
$dispatcher(Request::from($_SERVER));
}

Expand Down
25 changes: 12 additions & 13 deletions tests/FileResponseTest.php
Expand Up @@ -12,24 +12,23 @@
namespace ICanBoogie\HTTP;

use ICanBoogie\DateTime;
use LogicException;

class FileResponseTest extends \PHPUnit\Framework\TestCase
final class FileResponseTest extends \PHPUnit\Framework\TestCase
{
/**
* @expectedException \LogicException
* @expectedExceptionMessageRegExp /Expected file, got directory\:/
*/
public function test_should_throw_exception_on_directory()
{
$this->expectException(LogicException::class);
$this->expectExceptionMessageRegExp("/Expected file, got directory\:/");

new FileResponse(__DIR__, Request::from());
}

/**
* @expectedException \LogicException
* @expectedExceptionMessageRegExp /File does not exist\:/
*/
public function test_should_throw_exception_on_invalid_file()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessageRegExp("/File does not exist\:/");

new FileResponse(uniqid(), Request::from());
}

Expand Down Expand Up @@ -311,7 +310,7 @@ public function test_get_is_modified($expected, $request_headers, $modified_time
$response = $this
->getMockBuilder(FileResponse::class)
->setConstructorArgs([ create_file(), $request ])
->setMethods([ 'get_modified_time', 'get_etag' ])
->onlyMethods([ 'get_modified_time', 'get_etag' ])
->getMockForAbstractClass();
$response
->expects($this->any())
Expand Down Expand Up @@ -390,12 +389,12 @@ public function test_accept_ranges($method, $type)
$response = $this
->getMockBuilder(FileResponse::class)
->setConstructorArgs([ __FILE__, $request ])
->setMethods([ 'send_body' ])
->onlyMethods([ 'send_body' ])
->getMock();

/* @var $response FileResponse */

$this->assertContains("Accept-Ranges: $type", (string) $response);
$this->assertStringContainsString("Accept-Ranges: $type", (string) $response);
}

public function provide_test_accept_ranges()
Expand Down Expand Up @@ -435,7 +434,7 @@ public function test_range_response($bytes, $pathname, $expected)
$response = $this
->getMockBuilder(FileResponse::class)
->setConstructorArgs([ $pathname, $request, [ FileResponse::OPTION_ETAG => $etag ] ])
->setMethods([ 'send_headers' ])
->onlyMethods([ 'send_headers' ])
->getMock();

/* @var $response FileResponse */
Expand Down
13 changes: 8 additions & 5 deletions tests/FileTest.php
Expand Up @@ -12,6 +12,7 @@
namespace ICanBoogie\HTTP;

use ICanBoogie\FormattedString;
use ICanBoogie\PropertyNotWritable;

class FileTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -200,11 +201,13 @@ public function provide_test_to_array()

/**
* @dataProvider provide_readonly_properties
* @expectedException \ICanBoogie\PropertyNotWritable
*/
public function test_write_readonly_properties($property)
public function test_write_readonly_properties(string $property)
{
$file = File::from([ File::OPTION_PATHNAME => __FILE__ ]);

$this->expectException(PropertyNotWritable::class);

$file->$property = null;
}

Expand Down Expand Up @@ -293,15 +296,15 @@ public function test_should_get_defined_size()
$this->assertEquals($expected, $file->size);
}

/**
* @expectedException \Exception
*/
public function test_move_overwrite()
{
$file1 = create_file();
$file2 = create_file();

$file = File::from($file1);

$this->expectException(\Exception::class);

$file->move($file2);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Headers/CacheControlTest.php
Expand Up @@ -11,6 +11,8 @@

namespace ICanBoogie\HTTP\Headers;

use InvalidArgumentException;

class CacheControlTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down Expand Up @@ -108,12 +110,10 @@ public function test_from_same()
$this->assertSame($instance, CacheControl::from($instance));
}

/**
* @expectedException \InvalidArgumentException
*/
public function test_set_invalid_cacheable()
{
$cache_control = new CacheControl;
$this->expectException(InvalidArgumentException::class);
$cache_control->cacheable = 'madonna';
}

Expand Down
22 changes: 8 additions & 14 deletions tests/Headers/HeaderTest.php
Expand Up @@ -13,6 +13,8 @@

use ICanBoogie\FormattedString;
use ICanBoogie\HTTP\Headers\HeaderTest\A;
use ICanBoogie\OffsetNotDefined;
use ICanBoogie\PropertyNotDefined;

class HeaderTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -95,39 +97,31 @@ public function test_ignore_unrecognized_parameter()
$this->assertEquals('123; p=test.txt', (string) $a);
}

/**
* @expectedException \ICanBoogie\PropertyNotDefined
*/
public function test_setting_unsupported_attribute_using_a_property_should_throw_an_exception()
{
$a = new A;
$this->expectException(PropertyNotDefined::class);
$a->b = true;
}

/**
* @expectedException \ICanBoogie\OffsetNotDefined
*/
public function test_setting_unsupported_attribute_using_an_offset_should_throw_an_exception()
{
$a = new A;
$this->expectException(OffsetNotDefined::class);
$a['b'] = true;
}

/**
* @expectedException \ICanBoogie\PropertyNotDefined
*/
public function test_getting_unsupported_attribute_using_a_property_should_throw_an_exception()
{
$a = new A;
$this->expectException(PropertyNotDefined::class);
$b = $a->b;
}

/**
* @expectedException \ICanBoogie\OffsetNotDefined
*/
public function test_getting_unsupported_attribute_using_an_offset_should_throw_an_exception()
{
$a = new A;
$this->expectException(OffsetNotDefined::class);
$b = $a['b'];
}

Expand All @@ -147,12 +141,12 @@ public function test_from_to_string()
}

/**
* @expectedException \InvalidArgumentException
* @dataProvider provide_invalid_from_source
*/
public function test_from_with_invalid_input_should_throw_exception($source)
{
$a = A::from(new \StdClass);
$this->expectException(\InvalidArgumentException::class);
$a = A::from($source);
}

public function provide_invalid_from_source()
Expand Down
2 changes: 1 addition & 1 deletion tests/ProvideDispatcherTest.php
Expand Up @@ -21,7 +21,7 @@ class ProvideDispatcherTest extends \PHPUnit\Framework\TestCase
*/
private $events;

public function setUp()
protected function setUp(): void
{
$this->events = new EventCollection;

Expand Down
12 changes: 5 additions & 7 deletions tests/RedirectResponseTest.php
Expand Up @@ -16,22 +16,20 @@ public function test_construct()
$this->assertEquals($uri, $response->location);

$body = (string) $response;
$this->assertContains($uri, $body);
$this->assertStringContainsString($uri, $body);
}

/**
* @expectedException \ICanBoogie\HTTP\StatusCodeNotValid
*/
public function test_construct_with_invalid_code()
{
$this->expectException(StatusCodeNotValid::class);

new RedirectResponse("/go/to/there", 987);
}

/**
* @expectedException \ICanBoogie\HTTP\StatusCodeNotValid
*/
public function test_construct_with_not_redirect_code()
{
$this->expectException(StatusCodeNotValid::class);

new RedirectResponse("/go/to/there", Status::NOT_FOUND);
}
}

0 comments on commit 968cfbf

Please sign in to comment.