Skip to content

Commit

Permalink
Merge pull request filp#672 from GrahamCampbell/patch-1
Browse files Browse the repository at this point in the history
Support PHP 8.0
  • Loading branch information
denis-sokolov committed Oct 17, 2020
2 parents 69b082b + 92b1b30 commit 51b84b9
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 54 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Tests

on:
push:
pull_request:

jobs:
tests:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-20.04

strategy:
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none
env:
update: true

- name: Setup Problem Matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Fix PHPUnit Version PHP < 7.4
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "phpunit/phpunit:^6.5.14 || ^7.5.20 || ^8.5.8" --dev --no-update --no-interaction
if: "matrix.php < 7.4"

- name: Fix PHPUnit Version PHP >= 7.4
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "phpunit/phpunit:^9.3.3" --dev --no-update --no-interaction
if: "matrix.php >= 7.4"

- name: Install PHP Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --no-interaction --no-progress

- name: Execute PHPUnit
run: vendor/bin/phpunit
21 changes: 6 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,24 @@ matrix:
dist: trusty
- php: 5.6
dist: xenial
env: PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml"
after_success: wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
- php: 5.6
dist: xenial
env: SETUP=lowest
- php: 7.0
dist: xenial
- php: 7.1
dist: bionic
- php: 7.2
dist: bionic
- php: 7.3
dist: bionic
- php: 7.4
dist: bionic
- php: hhvm-3.30
dist: trusty
before_install:
- travis_retry composer require "phpunit/phpunit:^5.7.27" --dev --no-update --no-interaction
- travis_retry composer require "mockery/mockery:^0.9.11" --dev --no-update --no-interaction

cache:
directories:
- "$HOME/.composer/cache"

before_script:
install:
- if [[ "$SETUP" = "basic" ]]; then composer install --no-interaction --prefer-dist; fi
- if [[ "$SETUP" = "lowest" ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi
- if [[ $TRAVIS_PHP_VERSION = "5.6" && "$SETUP" = "basic" ]]; then PHPUNIT_FLAGS="--coverage-clover build/logs/clover.xml"; fi

script:
- vendor/bin/phpunit --verbose $PHPUNIT_FLAGS

after_success:
- if [ $TRAVIS_PHP_VERSION = "5.6" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml; fi
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
}
],
"require": {
"php": "^5.5.9 || ^7.0",
"php": "^5.5.9 || ^7.0 || ^8.0",
"psr/log": "^1.0.1"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.3",
"mockery/mockery": "^0.9 || ^1.0",
"symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
},
Expand All @@ -36,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.6-dev"
"dev-master": "2.7-dev"
}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="tests/bootstrap.php" colors="true">
<phpunit backupGlobals="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true">
<testsuites>
<testsuite name="Whoops Tests Suite">
<directory>tests/Whoops/</directory>
Expand Down
4 changes: 2 additions & 2 deletions tests/Whoops/Exception/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function testPlain()
{
$msg = 'Sample exception message foo';
$output = Formatter::formatExceptionPlain(new Inspector(new \Exception($msg)));
$this->assertContains($msg, $output);
$this->assertContains('Stacktrace', $output);
$this->assertStringContains($msg, $output);
$this->assertStringContains('Stacktrace', $output);
}
}
11 changes: 8 additions & 3 deletions tests/Whoops/Exception/FrameCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,25 @@ public function testArrayAccessGet()

/**
* @covers Whoops\Exception\FrameCollection::offsetSet
* @expectedException Exception
*/
public function testArrayAccessSet()
{
$collection = $this->getFrameCollectionInstance();

$this->expectExceptionOfType('Exception');

$collection[0] = 'foo';
}

/**
* @covers Whoops\Exception\FrameCollection::offsetUnset
* @expectedException Exception
*/
public function testArrayAccessUnset()
{
$collection = $this->getFrameCollectionInstance();

$this->expectExceptionOfType('Exception');

unset($collection[0]);
}

Expand Down Expand Up @@ -132,12 +136,13 @@ public function testMapFrames()

/**
* @covers Whoops\Exception\FrameCollection::map
* @expectedException UnexpectedValueException
*/
public function testMapFramesEnforceType()
{
$frames = $this->getFrameCollectionInstance();

$this->expectExceptionOfType('UnexpectedValueException');

// Filter out all frames with a line number under 6
$frames->map(function ($frame) {
return "bajango";
Expand Down
9 changes: 5 additions & 4 deletions tests/Whoops/Handler/CallbackHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

class CallbackHandlerTest extends TestCase
{
public function testSimplifiedBacktrace() {
$handler = new CallbackHandler(function($exception, $inspector, $run) {
public function testSimplifiedBacktrace()
{
$handler = new CallbackHandler(function ($exception, $inspector, $run) {
return debug_backtrace();
});
$backtrace = $handler->handle();

foreach($backtrace as $frame) {
$this->assertNotContains('call_user_func', $frame['function']);
foreach ($backtrace as $frame) {
$this->assertStringNotContains('call_user_func', $frame['function']);
}
}
}
30 changes: 15 additions & 15 deletions tests/Whoops/Handler/PlainTextHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ private function getPlainTextFromHandler(
/**
* @covers Whoops\Handler\PlainTextHandler::__construct
* @covers Whoops\Handler\PlainTextHandler::setLogger
* @expectedException \InvalidArgumentException
*/
public function testConstructor()
{
$logger = new StdClass(); // guaranteed to be invalid!
$this->getHandler($logger);
$this->expectExceptionOfType('InvalidArgumentException');

$this->getHandler(new StdClass());
}

/**
* @covers Whoops\Handler\PlainTextHandler::setLogger
* @expectedException InvalidArgumentException
*/
public function testSetLogger()
{
$logger = new StdClass(); // guaranteed to be invalid!
$this->getHandler()->setLogger($logger);
$this->expectExceptionOfType('InvalidArgumentException');

$this->getHandler()->setLogger(new StdClass());
}

/**
Expand Down Expand Up @@ -239,7 +239,7 @@ public function testReturnsWithoutPreviousExceptions()
);

// Check that the response does not contain Inner exception message:
$this->assertNotContains(
$this->assertStringNotContains(
sprintf(
"%s: %s in file %s",
RuntimeException::class,
Expand Down Expand Up @@ -295,10 +295,10 @@ public function testReturnsWithFramesOutput()
);

// Check that the response has the correct value:
$this->assertContains('Stack trace:', $text);
$this->assertStringContains('Stack trace:', $text);

// Check that the trace is returned:
$this->assertContains(
$this->assertStringContains(
sprintf(
'%3d. %s->%s() %s:%d',
2,
Expand Down Expand Up @@ -334,10 +334,10 @@ public function testReturnsWithFramesAndArgsOutput()
$this->assertGreaterThan(60, count($lines));

// Check that the response has the correct value:
$this->assertContains('Stack trace:', $text);
$this->assertStringContains('Stack trace:', $text);

// Check that the trace is returned:
$this->assertContains(
$this->assertStringContains(
sprintf(
'%3d. %s->%s() %s:%d',
2,
Expand All @@ -349,7 +349,7 @@ public function testReturnsWithFramesAndArgsOutput()
$text
);
// Check that the trace arguments are returned:
$this->assertContains(sprintf(
$this->assertStringContains(sprintf(
'%s string(%d) "%s"',
PlainTextHandler::VAR_DUMP_PREFIX,
strlen('test message'),
Expand All @@ -376,10 +376,10 @@ public function testReturnsWithFramesAndLimitedArgsOutput()
);

// Check that the response has the correct value:
$this->assertContains('Stack trace:', $text);
$this->assertStringContains('Stack trace:', $text);

// Check that the trace is returned:
$this->assertContains(
$this->assertStringContains(
sprintf(
'%3d. %s->%s() %s:%d',
2,
Expand All @@ -392,7 +392,7 @@ public function testReturnsWithFramesAndLimitedArgsOutput()
);

// Check that the trace arguments are returned:
$this->assertContains(sprintf(
$this->assertStringContains(sprintf(
'%s string(%d) "%s"',
PlainTextHandler::VAR_DUMP_PREFIX,
strlen('test message'),
Expand Down
6 changes: 3 additions & 3 deletions tests/Whoops/Handler/PrettyPageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ public function testGetSetResourcePaths()

/**
* @covers Whoops\Handler\PrettyPageHandler::addResourcePath
* @expectedException InvalidArgumentException
*/
public function testSetInvalidResourcesPath()
{
$path = __DIR__ . '/ZIMBABWE'; // guaranteed to be invalid!
$this->getHandler()->addResourcePath($path);
$this->expectExceptionOfType('InvalidArgumentException');

$this->getHandler()->addResourcePath(__DIR__ . '/ZIMBABWE');
}

/**
Expand Down
14 changes: 10 additions & 4 deletions tests/Whoops/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ public function testPushHandler()
}

/**
* @expectedException InvalidArgumentException
* @covers Whoops\Run::pushHandler
*/
public function testPushInvalidHandler()
{
$run = $this->getRunInstance();
$run->pushHandler($banana = 'actually turnip');

$this->expectExceptionOfType('InvalidArgumentException');

$run->pushHandler('actually turnip');
}

/**
Expand Down Expand Up @@ -180,7 +182,6 @@ public function testRegisterHandler()

/**
* @covers Whoops\Run::unregister
* @expectedException Exception
*/
public function testUnregisterHandler()
{
Expand All @@ -191,6 +192,9 @@ public function testUnregisterHandler()
$run->pushHandler($handler);

$run->unregister();

$this->expectExceptionOfType('Exception');

throw $this->getException("I'm not supposed to be caught!");
}

Expand Down Expand Up @@ -402,6 +406,7 @@ public function testSilenceErrorsInPaths()

/**
* @covers Whoops\Run::handleError
* @requires PHP < 8
*/
public function testGetSilencedError()
{
Expand Down Expand Up @@ -491,10 +496,11 @@ public function testSendHttpCodeNullCode()

/**
* @covers Whoops\Run::sendHttpCode
* @expectedException InvalidArgumentException
*/
public function testSendHttpCodeWrongCode()
{
$this->expectExceptionOfType('InvalidArgumentException');

$this->getRunInstance()->sendHttpCode(1337);
}
}
Loading

0 comments on commit 51b84b9

Please sign in to comment.