Completed
Push — master ( c85e73...41284f )
by Dmitry
02:55
created

RunnerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMultiple() 0 22 1
B test() 0 33 1
A testArgumentCasting() 0 8 1
1
<?php
2
3
namespace Test;
4
5
use Basis\Job\Job\Info;
6
use Basis\Runner;
7
use Job\Hello;
8
use Basis\Test;
9
10
class RunnerTest extends Test
11
{
12
    public function testMultiple()
13
    {
14
        $result = $this->app->dispatch('test.hello');
15
        $this->assertSame($result->message, 'hello world!');
16
17
        $result = $this->app->dispatch('test.hello', []);
18
        $this->assertSame($result->message, 'hello world!');
19
20
        $result = $this->app->dispatch('test.hello', [['name' => 'nekufa']]);
21
        $this->assertCount(1, $result);
22
        $this->assertSame($result[0]->message, 'hello nekufa!');
23
24
        $result = $this->app->dispatch('test.hello', [['name' => 'nekufa'], []]);
25
        $this->assertCount(2, $result);
26
        $this->assertSame($result[0]->message, 'hello nekufa!');
27
        $this->assertSame($result[1]->message, 'hello world!');
28
29
        $result = $this->app->dispatch('test.hello', [['name' => 'nekufa'], ['name' => 'vasya']]);
30
        $this->assertCount(2, $result);
31
        $this->assertSame($result[0]->message, 'hello nekufa!');
32
        $this->assertSame($result[1]->message, 'hello vasya!');
33
    }
34
35
    public function test()
36
    {
37
        $result = $this->app->dispatch('test.hello');
38
        $this->assertSame($result->message, 'hello world!');
39
40
        $result = $this->app->dispatch('test.hello', ['name' => 'nekufa']);
41
        $this->assertSame($result->message, 'hello nekufa!');
42
43
        $result = $this->app->dispatch('test.helloSomebody', ['name' => 'nekufa']);
44
        $this->assertSame($result->message, 'hello nekufa!');
45
46
        $result = $this->app->dispatch('test.HelloSomebody', ['name' => 'nekufa']);
47
        $this->assertSame($result->message, 'hello nekufa!');
48
49
        $result = $this->app->dispatch('test.hellosomebody', ['name' => 'nekufa']);
50
        $this->assertSame($result->message, 'hello nekufa!');
51
52
        $result = $this->app->dispatch('hello');
53
        $this->assertSame($result->message, 'hello world!');
54
55
        $result = $this->app->dispatch('hello', ['name' => 'nekufa']);
56
        $this->assertSame($result->message, 'hello nekufa!');
57
58
        $jobs = $this->app->get(Runner::class)->getMapping();
59
        $this->assertNotNull($jobs);
60
        $this->assertContains('test.hello', array_keys($jobs));
61
        $this->assertSame($jobs['test.hello'], Hello::class);
62
63
        $jobs = $this->app->dispatch('module.meta')->jobs;
64
        $this->assertNotNull($jobs);
65
        $this->assertCount(2, $jobs);
66
        $this->assertContains('hello', $jobs);
67
    }
68
69
    public function testArgumentCasting()
70
    {
71
        $result = $this->app->dispatch('test.hello', ['nekufa']);
72
        $this->assertSame($result->message, 'hello nekufa!');
73
74
        $result = $this->app->dispatch('test.hello', ['dmitry', 'krokhin']);
75
        $this->assertSame($result->message, 'hello dmitry krokhin!');
76
    }
77
}
78