blob: 05f54ba175529374a08440944493c82c65228d32 (
plain)
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
|
<?php
namespace gipfl\Protocol\JsonRpc;
use PHPUnit\Framework\TestCase as BaseTestCase;
use React\EventLoop\LoopInterface;
class TestCase extends BaseTestCase
{
protected $examples = [];
protected function parseExample($key)
{
return Packet::decode($this->examples[$key]);
}
protected function failAfterSeconds($seconds, LoopInterface $loop)
{
$loop->addTimer($seconds, function () use ($seconds) {
throw new \RuntimeException("Timed out after $seconds seconds");
});
}
protected function collectErrorsForNotices(&$errors)
{
\set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$errors) {
if (\error_reporting() === 0) { // @-operator in use
return false;
}
$errors[] = new \ErrorException($errstr, 0, $errno, $errfile, $errline);
return false; // Always continue with normal error processing
}, E_ALL | E_STRICT);
\error_reporting(E_ALL | E_STRICT);
}
protected function throwEventualErrors(array $errors)
{
foreach ($errors as $error) {
throw $error;
}
}
}
|