From 642f97808341b6c869b926a220e940274c7d865c Mon Sep 17 00:00:00 2001 From: Tomasz Sawicki Date: Tue, 24 Jul 2018 14:41:57 +0200 Subject: [PATCH 1/2] Fix getting the type of unexpected reject reason --- src/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index c177be4..95f70f7 100644 --- a/src/functions.php +++ b/src/functions.php @@ -87,7 +87,7 @@ function ($error) use (&$exception, &$rejected, &$wait, $loop) { if ($rejected) { if (!$exception instanceof \Exception) { $exception = new \UnexpectedValueException( - 'Promise rejected with unexpected value of type ' . (is_object(($exception) ? get_class($exception) : gettype($exception))), + 'Promise rejected with unexpected value of type ' . (is_object($exception) ? get_class($exception) : gettype($exception)), 0, $exception instanceof \Throwable ? $exception : null ); From 485a2e3420351c01071cca1f2307c132f44238b5 Mon Sep 17 00:00:00 2001 From: Tomasz Sawicki Date: Tue, 24 Jul 2018 14:41:57 +0200 Subject: [PATCH 2/2] Fix getting the type of unexpected reject reason --- src/functions.php | 2 +- tests/FunctionAwaitTest.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index c177be4..95f70f7 100644 --- a/src/functions.php +++ b/src/functions.php @@ -87,7 +87,7 @@ function ($error) use (&$exception, &$rejected, &$wait, $loop) { if ($rejected) { if (!$exception instanceof \Exception) { $exception = new \UnexpectedValueException( - 'Promise rejected with unexpected value of type ' . (is_object(($exception) ? get_class($exception) : gettype($exception))), + 'Promise rejected with unexpected value of type ' . (is_object($exception) ? get_class($exception) : gettype($exception)), 0, $exception instanceof \Throwable ? $exception : null ); diff --git a/tests/FunctionAwaitTest.php b/tests/FunctionAwaitTest.php index 73e5eee..a22753c 100644 --- a/tests/FunctionAwaitTest.php +++ b/tests/FunctionAwaitTest.php @@ -19,6 +19,7 @@ public function testAwaitOneRejected() /** * @expectedException UnexpectedValueException + * @expectedExceptionMessage Promise rejected with unexpected value of type bool */ public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException() { @@ -29,6 +30,7 @@ public function testAwaitOneRejectedWithFalseWillWrapInUnexpectedValueException( /** * @expectedException UnexpectedValueException + * @expectedExceptionMessage Promise rejected with unexpected value of type NULL */ public function testAwaitOneRejectedWithNullWillWrapInUnexpectedValueException() { @@ -48,6 +50,7 @@ public function testAwaitOneRejectedWithPhp7ErrorWillWrapInUnexpectedValueExcept Block\await($promise, $this->loop); $this->fail(); } catch (UnexpectedValueException $e) { + $this->assertEquals('Promise rejected with unexpected value of type Error', $e->getMessage()); $this->assertInstanceOf('Throwable', $e->getPrevious()); $this->assertEquals('Test', $e->getPrevious()->getMessage()); }