Completed
Push — master ( 1f1a8e...ab56b8 )
by Dmitry
03:54
created

Test::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 15.5468

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 30
ccs 5
cts 20
cp 0.25
rs 8.439
cc 5
eloc 18
nc 6
nop 0
crap 15.5468
1
<?php
2
3
namespace Basis;
4
5
use Basis\Converter;
6
use PHPUnit\Framework\TestCase;
7
use ReflectionProperty;
8
use Tarantool\Mapper\Pool;
9
10
abstract class Test extends TestCase
11
{
12
    use Toolkit;
13
14
    public $params = [];
15
    public $disableRemote = true;
16
17
    public $mocks = [];
18
    public $data = [];
19
20 3
    public function __construct()
21
    {
22
        parent::__construct();
23
24
        $this->app = new Test\Application($this);
25
26
        foreach ($this->mocks as [$method, $params, $result]) {
27
            $this->mock($method, $params)->willReturn($result);
0 ignored issues
show
Bug introduced by
The variable $method 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...
Bug introduced by
The variable $result 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...
28
        }
29
30
        $serviceData = [];
31
        foreach ($this->data as $space => $data) {
32
            [$service, $space] = explode('.', $space);
0 ignored issues
show
Bug introduced by
The variable $service does not exist. Did you mean $serviceData?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
33
            if (!array_key_exists($service, $serviceData)) {
0 ignored issues
show
Bug introduced by
The variable $service does not exist. Did you mean $serviceData?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
34
                $serviceData[$service] = [];
0 ignored issues
show
Bug introduced by
The variable $service does not exist. Did you mean $serviceData?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
35
            }
36
            $serviceData[$service][$space] = $data;
0 ignored issues
show
Bug introduced by
The variable $service does not exist. Did you mean $serviceData?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
37
        }
38
39
        $pool = $this->app->get(Pool::class);
40
        $property = new ReflectionProperty(Pool::class, 'resolvers');
41
        $property->setAccessible(true);
42
        $property->setValue($pool, []);
43
44 3
        $pool->registerResolver(function($service) use ($serviceData) {
45 3
            if (array_key_exists($service, $serviceData)) {
46 2
                return new Test\Mapper($this, $service);
47
            }
48 2
        });
49
    }
50
51 37
    public function setup()
52
    {
53 37
        $this->dispatch('tarantool.migrate');
54 37
    }
55
56 29
    public function tearDown()
57
    {
58 29
        $this->dispatch('tarantool.clear');
59 29
    }
60
61
    public $mockInstances = [];
62
63 4
    public function mock(string $job, array $params = [])
64
    {
65 4
        if (!array_key_exists($job, $this->mockInstances)) {
66 3
            $this->mockInstances[$job] = [];
67
        }
68
69 4
        $mock = new Test\Mock($this->get(Converter::class), $this, $params);
70
71 4
        $this->mockInstances[$job][] = $mock;
72
73 4
        return $mock;
74
    }
75
}
76