Browse Source

Fixes #7

2.1.0
Dustin Wilson 1 year ago
parent
commit
c24cc5d204
  1. 76
      composer.lock
  2. 6
      lib/Catcher.php
  3. 24
      run
  4. 2
      tests/cases/TestCatcher.php
  5. 5
      tests/cases/TestThrowableController.php
  6. 19
      tests/docroot/testDispatch.php

76
composer.lock

@ -60,30 +60,30 @@
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "1.5.0",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "0a0fa9780f5d4e507415a065172d26a98d02047b"
"reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b",
"reference": "0a0fa9780f5d4e507415a065172d26a98d02047b",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0",
"reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
"php": "^8.1"
},
"require-dev": {
"doctrine/coding-standard": "^9 || ^11",
"doctrine/coding-standard": "^11",
"ext-pdo": "*",
"ext-phar": "*",
"phpbench/phpbench": "^0.16 || ^1",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"vimeo/psalm": "^4.30 || ^5.4"
"phpbench/phpbench": "^1.2",
"phpstan/phpstan": "^1.9.4",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.5.27",
"vimeo/psalm": "^5.4"
},
"type": "library",
"autoload": {
@ -110,7 +110,7 @@
],
"support": {
"issues": "https://github.com/doctrine/instantiator/issues",
"source": "https://github.com/doctrine/instantiator/tree/1.5.0"
"source": "https://github.com/doctrine/instantiator/tree/2.0.0"
},
"funding": [
{
@ -126,7 +126,7 @@
"type": "tidelift"
}
],
"time": "2022-12-30T00:15:36+00:00"
"time": "2022-12-30T00:23:10+00:00"
},
{
"name": "eloquent/phony",
@ -452,16 +452,16 @@
},
{
"name": "mensbeam/intl",
"version": "0.9.1",
"version": "0.9.2",
"source": {
"type": "git",
"url": "https://github.com/mensbeam/intl.git",
"reference": "07d26e3f45c3a3167eb6389572419d3bda7ff5e1"
"reference": "88dbf8398ab69e71164ac073f9ec011be2baa4ae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mensbeam/intl/zipball/07d26e3f45c3a3167eb6389572419d3bda7ff5e1",
"reference": "07d26e3f45c3a3167eb6389572419d3bda7ff5e1",
"url": "https://api.github.com/repos/mensbeam/intl/zipball/88dbf8398ab69e71164ac073f9ec011be2baa4ae",
"reference": "88dbf8398ab69e71164ac073f9ec011be2baa4ae",
"shasum": ""
},
"require": {
@ -501,9 +501,9 @@
],
"support": {
"issues": "https://github.com/mensbeam/intl/issues",
"source": "https://github.com/mensbeam/intl/tree/0.9.1"
"source": "https://github.com/mensbeam/intl/tree/0.9.2"
},
"time": "2021-10-24T14:37:46+00:00"
"time": "2023-01-25T22:12:58+00:00"
},
{
"name": "mensbeam/mimesniff",
@ -617,16 +617,16 @@
},
{
"name": "nikic/php-parser",
"version": "v4.15.2",
"version": "v4.15.3",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc"
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039",
"reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039",
"shasum": ""
},
"require": {
@ -667,9 +667,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.2"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3"
},
"time": "2022-11-12T15:38:23+00:00"
"time": "2023-01-16T22:05:37+00:00"
},
{
"name": "phar-io/manifest",
@ -1102,20 +1102,20 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.27",
"version": "9.5.28",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "a2bc7ffdca99f92d959b3f2270529334030bba38"
"reference": "954ca3113a03bf780d22f07bf055d883ee04b65e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a2bc7ffdca99f92d959b3f2270529334030bba38",
"reference": "a2bc7ffdca99f92d959b3f2270529334030bba38",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/954ca3113a03bf780d22f07bf055d883ee04b65e",
"reference": "954ca3113a03bf780d22f07bf055d883ee04b65e",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.3.1",
"doctrine/instantiator": "^1.3.1 || ^2",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
@ -1184,7 +1184,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.27"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.28"
},
"funding": [
{
@ -1200,7 +1200,7 @@
"type": "tidelift"
}
],
"time": "2022-12-09T07:31:23+00:00"
"time": "2023-01-14T12:32:24+00:00"
},
{
"name": "psr/http-message",
@ -2221,16 +2221,16 @@
},
{
"name": "symfony/css-selector",
"version": "v5.4.17",
"version": "v5.4.19",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "052ef49b660f9ad2a3adb311c555c9bc11ba61f4"
"reference": "f4a7d150f5b9e8f974f6f127d8167e420d11fc62"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/052ef49b660f9ad2a3adb311c555c9bc11ba61f4",
"reference": "052ef49b660f9ad2a3adb311c555c9bc11ba61f4",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/f4a7d150f5b9e8f974f6f127d8167e420d11fc62",
"reference": "f4a7d150f5b9e8f974f6f127d8167e420d11fc62",
"shasum": ""
},
"require": {
@ -2267,7 +2267,7 @@
"description": "Converts CSS selectors to XPath expressions",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/css-selector/tree/v5.4.17"
"source": "https://github.com/symfony/css-selector/tree/v5.4.19"
},
"funding": [
{
@ -2283,7 +2283,7 @@
"type": "tidelift"
}
],
"time": "2022-12-23T11:40:44+00:00"
"time": "2023-01-01T08:32:19+00:00"
},
{
"name": "symfony/polyfill-php80",

6
lib/Catcher.php

@ -179,7 +179,7 @@ class Catcher {
* @internal
*/
public function handleError(int $code, string $message, ?string $file = null, ?int $line = null): bool {
if ($code !== 0 && error_reporting()) {
if ($code && $code & error_reporting()) {
$error = new Error($message, $code, $file, $line);
if ($this->throwErrors) {
// The point of this library is to allow treating of errors as if they were
@ -272,6 +272,10 @@ class Catcher {
$this->isShuttingDown = true;
if ($error = $this->getLastError()) {
if ($this->isErrorFatal($error['type'])) {
$errorReporting = error_reporting();
if ($this->errorReporting !== null && $this->errorReporting === $errorReporting && !($this->errorReporting & \E_ERROR)) {
error_reporting($errorReporting | \E_ERROR);
}
$this->handleError($error['type'], $error['message'], $error['file'], $error['line']);
}
} else {

24
run

@ -8,7 +8,7 @@ $testDir = "$cwd/tests";
function help($error = true): void {
$help = <<<USAGE
Usage:
run test [typical|quick|coverage|full] [additional_phpunit_options]
run test [additional_phpunit_options]
run --help
USAGE;
@ -38,26 +38,8 @@ switch ($argv[1]) {
'--coverage-html='.escapeshellarg("$testDir/coverage")
];
$argv[2] = $argv[2] ?? '';
switch ($argv[2]) {
case '':
case 'typical':
$opts[] = '--exclude-group=optional';
break;
case 'quick':
$opts[] = '--exclude-group=optional,slow';
break;
case 'coverage':
$opts[] = '--exclude-group=optional,coverageOptional';
break;
case 'full':
break;
default:
help();
}
if (isset($argv[3])) {
$opts = [ ...$opts, array_slice($argv, 3) ];
if (isset($argv[2])) {
$opts = [ ...$opts, array_slice($argv, 2) ];
}
$opts = implode(' ', $opts);

2
tests/cases/TestCatcher.php

@ -482,6 +482,7 @@ class TestCatcher extends \PHPUnit\Framework\TestCase {
$p = new \ReflectionProperty($c, 'isShuttingDown');
$p->setAccessible(true);
$this->assertFalse($p->getValue($c));
$c->unregister();
$h = Phony::partialMock(Catcher::class, [ new PlainTextHandler([ 'silent' => true ]) ]);
$h->getLastError->returns([
@ -494,6 +495,5 @@ class TestCatcher extends \PHPUnit\Framework\TestCase {
$c->handleShutdown();
$h->handleError->called();
$h->handleThrowable->called();
$c->unregister();
}
}

5
tests/cases/TestThrowableController.php

@ -14,10 +14,7 @@ use MensBeam\Foundation\Catcher\{
ThrowableController
};
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class TestThrowableController extends \PHPUnit\Framework\TestCase {
/**
* @covers \MensBeam\Foundation\Catcher\ThrowableController::getErrorType

19
tests/docroot/testDispatch.php

@ -1,19 +0,0 @@
<?php
/**
* @license MIT
* Copyright 2022 Dustin Wilson, et al.
* See LICENSE and AUTHORS files for details
*/
declare(strict_types=1);
namespace MensBeam\Foundation\Catcher\Test;
use MensBeam\Foundation\Catcher;
use MensBeam\Foundation\Catcher\{
Error,
PlainTextHandler
};
require_once('../../vendor/autoload.php');
Catcher::$preventExit = true;
$c = new Catcher(new PlainTextHandler([ 'httpCode' => 200 ]));
trigger_error('Ook!', \E_USER_WARNING);
Loading…
Cancel
Save