Skip to content

Commit 78daa3f

Browse files
committed
Functionally test enforcing Throwable as rejection
1 parent e5b5af1 commit 78daa3f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/FunctionalRejectTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace React\Promise;
4+
5+
use stdClass;
6+
7+
class FunctionalRejectTest extends TestCase
8+
{
9+
public function nonThrowables()
10+
{
11+
yield '1' => [1];
12+
yield 'true' => [true];
13+
yield 'stdClass' => [new stdClass()];
14+
}
15+
16+
/**
17+
* @test
18+
* @dataProvider nonThrowables
19+
*/
20+
public function shouldThrowWhenCalledWithANonException($input)
21+
{
22+
$errorCollector = new ErrorCollector();
23+
$errorCollector->start();
24+
25+
all([
26+
resolve(true),
27+
race([
28+
(new Promise(function ($_, $reject) use ($input) {
29+
$reject($input);
30+
})),
31+
(new Promise(function () {
32+
})),
33+
])
34+
])->done($this->expectCallableNever());
35+
36+
$errors = $errorCollector->stop();
37+
38+
$this->assertEquals(E_USER_ERROR, $errors[0]['errno']);
39+
$this->assertContains(
40+
'TypeError: Argument 1 passed to React\Promise\reject() must implement interface Throwable',
41+
$errors[0]['errstr']
42+
);
43+
}
44+
}

0 commit comments

Comments
 (0)