Skip to content

Commit ce11aaa

Browse files
committed
Functionally test enforcing Throwable as rejection
1 parent d7b9f5f commit ce11aaa

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/FunctionalRejectTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
(new Promise(function ($_, $reject) use ($input) {
26+
$reject($input);
27+
}))->done($this->expectCallableNever());
28+
29+
$errors = $errorCollector->stop();
30+
31+
$this->assertEquals(E_USER_ERROR, $errors[0]['errno']);
32+
$this->assertContains(
33+
'TypeError: Argument 1 passed to React\Promise\reject() must implement interface Throwable',
34+
$errors[0]['errstr']
35+
);
36+
}
37+
}

0 commit comments

Comments
 (0)