Test Failed
Push — main ( bf77ba...401323 )
by Teodoro
03:31 queued 41s
created

AsyncTest::failed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Tleckie\Async\Tests;
4
5
use Exception;
6
use PHPUnit\Framework\TestCase;
7
use Tleckie\Async\Async;
8
9
/**
10
 * Class AsyncTest
11
 *
12
 * @package Tleckie\Async\Tests
13
 * @author  Teodoro Leckie Westberg <[email protected]>
14
 */
15
class AsyncTest extends TestCase
16
{
17
    /** @var Async */
18
    private Async $async;
19
20
    public function setUp(): void
21
    {
22
        $this->async = new Async(null, null, 0);
23
    }
24
25
    /**
26
     * @test
27
     */
28
    public function add(): void
29
    {
30
        $this->async->add(static function () {
31
            usleep(8000);
32
33
            return 555;
34
        });
35
        $this->async->add(static function () {
36
            return 2;
37
        });
38
39
        static::assertEquals([2, 555], $this->async->wait());
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function then(): void
46
    {
47
        $this->async->add(static function () {
48
            return 555;
49
        })->then(static function (int $value) {
50
            static::assertEquals(555, $value);
51
        });
52
53
        $this->async->wait();
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function failed(): void
60
    {
61
        $this->async->add(static function () {
62
            throw new Exception('Test message');
63
        })->catch(function (Exception $exception) {
64
            static::assertEquals('Test message', $exception->getMessage());
65
        });
66
67
        $this->async->wait();
68
    }
69
}
70