Completed
Push — master ( 904e9e...12cc86 )
by Dmitry
05:35
created

RunnerTest::test()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
3
namespace Test;
4
5
use Basis\Job\Job\Info;
6
use Basis\Runner;
7
use Basis\Test;
8
use Exception;
9
use Job\Hello;
10
11
class RunnerTest extends Test
12
{
13
    public function testMultiple()
14
    {
15
        $result = $this->app->dispatch('test.hello');
16
        $this->assertSame($result->message, 'hello world!');
17
18
        $result = $this->app->dispatch('test.hello', []);
19
        $this->assertSame($result->message, 'hello world!');
20
21
        $result = $this->app->dispatch('test.hello', [['name' => 'nekufa']]);
22
        $this->assertCount(1, $result);
23
        $this->assertSame($result[0]->message, 'hello nekufa!');
24
25
        $result = $this->app->dispatch('test.hello', [['name' => 'nekufa'], []]);
26
        $this->assertCount(2, $result);
27
        $this->assertSame($result[0]->message, 'hello nekufa!');
28
        $this->assertSame($result[1]->message, 'hello world!');
29
30
        $result = $this->app->dispatch('test.hello', [['name' => 'nekufa'], ['name' => 'vasya']]);
31
        $this->assertCount(2, $result);
32
        $this->assertSame($result[0]->message, 'hello nekufa!');
33
        $this->assertSame($result[1]->message, 'hello vasya!');
34
    }
35
36
    public function test()
37
    {
38
        $result = $this->app->dispatch('test.hello');
39
        $this->assertSame($result->message, 'hello world!');
40
41
        $result = $this->app->dispatch('test.hello', ['name' => 'nekufa']);
42
        $this->assertSame($result->message, 'hello nekufa!');
43
44
        $result = $this->app->dispatch('test.helloSomebody', ['name' => 'nekufa']);
45
        $this->assertSame($result->message, 'hello nekufa!');
46
47
        $result = $this->app->dispatch('test.HelloSomebody', ['name' => 'nekufa']);
48
        $this->assertSame($result->message, 'hello nekufa!');
49
50
        $result = $this->app->dispatch('test.hellosomebody', ['name' => 'nekufa']);
51
        $this->assertSame($result->message, 'hello nekufa!');
52
53
        $result = $this->app->dispatch('hello');
54
        $this->assertSame($result->message, 'hello world!');
55
56
        $result = $this->app->dispatch('hello', ['name' => 'nekufa']);
57
        $this->assertSame($result->message, 'hello nekufa!');
58
59
        $jobs = $this->app->get(Runner::class)->getMapping();
60
        $this->assertNotNull($jobs);
61
        $this->assertContains('test.hello', array_keys($jobs));
62
        $this->assertSame($jobs['test.hello'], Hello::class);
63
64
        $jobs = $this->app->dispatch('module.meta')->jobs;
65
        $this->assertNotNull($jobs);
66
        $this->assertCount(2, $jobs);
67
        $this->assertContains('hello', $jobs);
68
    }
69
70
    public function testArgumentCasting()
71
    {
72
        $result = $this->app->dispatch('test.hello', ['nekufa']);
73
        $this->assertSame($result->message, 'hello nekufa!');
74
75
        $result = $this->app->dispatch('test.hello', ['dmitry', 'krokhin']);
76
        $this->assertSame($result->message, 'hello dmitry krokhin!');
77
    }
78
79
    public function testConfirmation()
80
    {
81
        $hash = null;
82
83
        try {
84
            $this->dispatch('test.hello', ['bazyaba']);
85
            $this->assertNull('confirmation should be thrown');
86
87
        } catch (Exception $e) {
88
            $message = json_decode($e->getMessage());
89
            if (!is_object($message)) {
90
                throw $e;
91
            }
92
            $this->assertSame($message->type, 'confirm');
93
            $this->assertSame($message->message, 'bazyaba?');
94
            $hash = $message->hash;
95
        }
96
97
        $this->assertNotNull($hash);
98
        $result = $this->dispatch('test.hello', ['name' => 'bazyaba', '_confirmations' => [$hash]]);
99
100
        $this->assertSame($result->message, 'hello bazyaba!');
101
    }
102
}
103