Test Failed
Push — main ( f9734f...77af0a )
by Teodoro
02:48
created

AsyncTest::failed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
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
        $values = $this->async->wait();
40
        static::assertContainsEquals(555, $values);
41
        static::assertContainsEquals(2, $values);
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function then(): void
48
    {
49
        $this->async->add(static function () {
50
            return 555;
51
        })->then(static function (int $value) {
52
            static::assertEquals(555, $value);
53
        });
54
55
        $this->async->wait();
56
    }
57
}
58