Completed
Push — master ( f0fc0a...56fb48 )
by Dmitry
03:00
created

MockTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hello() 0 4 1
A testContext() 0 4 1
A testInstanceParams() 0 5 1
A testMocking() 0 14 4
1
<?php
2
3
namespace Test;
4
5
use Basis\Test;
6
7
class MockTest extends Test
8
{
9
    public $mocks = [
10
        ['say.hello', ['nick' => 'nekufa'], 'hello'],
11
        ['service.call', ['name' => 'nekufa'], ['value' => 'nekufa!']],
12
        ['service.call', ['name' => 'bazyaba'], ['value' => 'bazyaba!']],
13
        ['service.call', [], ['value' => 'anonymous!']],
14
    ];
15
16
    public function hello($params)
17
    {
18
        return ['text' => 'Hello, '.$params->nick];
19
    }
20
21
    public function testContext()
22
    {
23
        $this->assertSame('Hello, nekufa', $this->dispatch('say.hello', ['nick' => 'nekufa'])->text);
24
    }
25
26
    public function testInstanceParams()
27
    {
28
        $this->params = ['name' => 'tester'];
29
        $this->assertSame('hello tester!', $this->dispatch('test.hello', [])->message);
30
    }
31
32
    public function testMocking()
33
    {
34
        foreach ($this->mocks as [$job, $params, $value]) {
35
            if (is_string($value) || is_callable($value)) {
0 ignored issues
show
Bug introduced by
The variable $value does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
                continue;
37
            }
38
            $result = $this->dispatch($job, $params);
0 ignored issues
show
Bug introduced by
The variable $job does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $params does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
39
            $this->assertSame(get_object_vars($result), $value);
40
        }
41
42
43
        $this->expectExceptionMessage("Remote calls (remote.call) are disabled for tests");
44
        $this->dispatch('remote.call');
45
    }
46
}
47