-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCase.php
More file actions
76 lines (67 loc) · 2.23 KB
/
TestCase.php
File metadata and controls
76 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace bdk\Test\HttpMessage;
use bdk\PhpUnitPolyfill\AssertionTrait;
use bdk\PhpUnitPolyfill\ExpectExceptionTrait;
use InvalidArgumentException;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Error\Notice as ErrorNotice;
use PHPUnit\Framework\TestCase as TestCaseBase;
use ReflectionClass;
use RuntimeException;
use TypeError;
/**
*
*/
class TestCase extends TestCaseBase
{
use AssertionTrait;
use ExpectExceptionTrait;
use DataProviderTrait;
use FactoryTrait;
// defining this in DataProviderTrait -> fatal error on php 8.0 (but not 8.1+)
protected static $hasParamTypes = null;
protected static $errorHandler;
public static function setUpBeforeClass(): void
{
self::$errorHandler = \set_error_handler(static function ($type, $msg) {
if ($type & E_USER_DEPRECATED) {
return true;
}
throw new RuntimeException($msg);
});
}
public static function tearDownAfter(): void
{
\set_error_handler(self::$errorHandler);
}
protected static function hasParamTypes()
{
if (PHP_VERSION_ID >= 70000 && isset(self::$hasParamTypes) === false) {
$refClass = new ReflectionClass('Psr\Http\Message\MessageInterface');
$refMethod = $refClass->getMethod('withProtocolVersion');
$refParams = $refMethod->getParameters();
$refParam = $refParams[0];
self::$hasParamTypes = $refParam->hasType();
}
return self::$hasParamTypes;
}
protected static function assertExceptionOrTypeError($callable)
{
try {
$callable();
} catch (ErrorNotice $e) {
self::assertSame('A non well formed numeric value encountered', $e->getMessage());
return;
} catch (RuntimeException $e) {
self::assertSame('A non well formed numeric value encountered', $e->getMessage());
return;
} catch (InvalidArgumentException $e) {
self::assertTrue(true);
return;
} catch (TypeError $e) {
self::assertSame(\get_class($e), 'TypeError');
return;
}
throw new AssertionFailedError('Exception not thrown');
}
}