Passed
Push — main ( 9e88f8...9f1665 )
by Teodoro
02:28
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
use Tleckie\Async\TaskFactoryInterface;
9
use Tleckie\Async\TaskInterface;
10
11
/**
12
 * Class AsyncTest
13
 *
14
 * @backupGlobals disabled
15
 * @package       Tleckie\Async\Tests
16
 * @author        Teodoro Leckie Westberg <[email protected]>
17
 */
18
class AsyncTest extends TestCase
19
{
20
    /** @var Async */
21
    private Async $async;
22
23
    public function setUp(): void
24
    {
25
        $this->async = new Async(null, null, 0);
26
    }
27
28
    /**
29
     * @test
30
     */
31
    public function add(): void
32
    {
33
        $this->async->add(static function () {
34
            usleep(8000);
35
36
            return 555;
37
        });
38
        $this->async->add(static function () {
39
            return 2;
40
        });
41
42
        $values = $this->async->wait();
43
        static::assertContainsEquals(555, $values);
44
        static::assertContainsEquals(2, $values);
45
    }
46
47
    /**
48
     * @test
49
     * @runTestsInSeparateProcesses
50
     */
51
    public function then(): void
52
    {
53
        $this->async->add(static function () {
54
            return 555;
55
        })->then(static function (int $value) {
56
            static::assertEquals(555, $value);
57
        });
58
59
        $this->async->wait();
60
    }
61
}
62