Completed
Push — master ( 8a3baa...fa7e80 )
by Vuong
01:55
created

TaskTest::testTimeout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-async
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\test\unit\async;
9
10
use Yii;
11
12
use vxm\async\event\ErrorEvent;
13
14
/**
15
 * Class TaskTest
16
 *
17
 * @author Vuong Minh <[email protected]>
18
 * @since 1.0.0
19
 */
20
class TaskTest extends TestCase
21
{
22
23
    public function testExecute()
24
    {
25
        $result = null;
26
27
        Yii::$app->async->run(new TaskRunnerTest, [
28
            'success' => function ($output) use (&$result) {
29
30
                $result = $output;
31
            }
32
        ])->wait();
33
34
        $this->assertEquals('yii\console\Application', $result);
35
    }
36
37
    public function testError()
38
    {
39
        $result = null;
40
41
        Yii::$app->async->on('error', function (ErrorEvent $event) use (&$result) {
42
            $result = get_class($event->throwable);
43
        });
44
45
        Yii::$app->async->run(new TaskRunnerErrorTest())->wait();
46
47
        $this->assertEquals('yii\console\Exception', $result);
48
    }
49
50
    public function testTimeout()
51
    {
52
        $result = false;
53
54
        Yii::$app->async->on('timeout', function () use (&$result) {
55
            $result = true;
56
        });
57
58
        Yii::$app->async->run(new TaskRunnerTimeoutTest)->wait();
59
60
        $this->assertTrue($result);
61
    }
62
63
}
64