Completed
Push — master ( c70864...b6d4e5 )
by Dmitry
03:30 queued 27s
created

test/php/Test/MockTest.php (3 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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...
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