SynchronousManagerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 47
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A handlesCallbackTasks() 0 26 2
1
<?php
2
3
namespace AsyncPHP\Doorman\Tests\Manager;
4
5
use AsyncPHP\Doorman\Manager\SynchronousManager;
6
use AsyncPHP\Doorman\Task\CallbackTask;
7
use AsyncPHP\Doorman\Tests\Test;
8
9
/**
10
 * @covers AsyncPHP\Doorman\Manager\SynchronousManager
11
 */
12
class SynchronousManagerTest extends Test
13
{
14
    /**
15
     * @var SynchronousManager
16
     */
17
    protected $manager;
18
19
    /**
20
     * @inheritdoc
21
     */
22
    public function setUp()
23
    {
24
        parent::setUp();
25
26
        $this->manager = new SynchronousManager();
27
    }
28
29
    /**
30
     * @test
31
     */
32
    public function handlesCallbackTasks()
33
    {
34
        $task1 = new CallbackTask(function () {
35
            touch(__DIR__."/task1.tmp");
36
        });
37
38
        $task2 = new CallbackTask(function () {
39
            touch(__DIR__."/task2.tmp");
40
        });
41
42
        $this->manager->addTask($task1);
43
        $this->manager->addTask($task2);
44
45
        $this->unlink(__DIR__."/task1.tmp");
46
        $this->unlink(__DIR__."/task2.tmp");
47
48
        while ($this->manager->tick()) {
49
            usleep(250);
50
        }
51
52
        $this->assertFileExists(__DIR__."/task1.tmp");
53
        $this->assertFileExists(__DIR__."/task2.tmp");
54
55
        $this->unlink(__DIR__."/task1.tmp");
56
        $this->unlink(__DIR__."/task2.tmp");
57
    }
58
}
59