summaryrefslogtreecommitdiffstats
path: root/vendor/gipfl/protocol-jsonrpc/src/TestCase.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gipfl/protocol-jsonrpc/src/TestCase.php')
-rw-r--r--vendor/gipfl/protocol-jsonrpc/src/TestCase.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/gipfl/protocol-jsonrpc/src/TestCase.php b/vendor/gipfl/protocol-jsonrpc/src/TestCase.php
new file mode 100644
index 0000000..05f54ba
--- /dev/null
+++ b/vendor/gipfl/protocol-jsonrpc/src/TestCase.php
@@ -0,0 +1,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;
+ }
+ }
+}