MockTest::testContext()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 testParamsToObject()
33
    {
34
        $this->params = ['session' => ['person' => 1]];
35
        $this->assertSame($this->dispatch('test.person')->person, 1);
36
    }
37
38
    public function testMocking()
39
    {
40
        foreach ($this->mocks as [$job, $params, $value]) {
41
            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...
42
                continue;
43
            }
44
            $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...
45
            $this->assertSame(get_object_vars($result), $value);
46
        }
47
48
49
        $this->expectExceptionMessage("Remote calls (remote.call) are disabled for tests");
50
        $this->dispatch('remote.call');
51
    }
52
}
53