Completed
Push — master ( 4848aa...64d9da )
by Dmitry
03:44
created

Test.php$0 ➔ dispatch()   F

Complexity

Conditions 12

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 12.0155

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 20
cts 21
cp 0.9524
rs 2.7855
c 0
b 0
f 0
cc 12
crap 12.0155

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Basis;
4
5
use Basis\Converter;
6
use Basis\Runner;
7
use Exception;
8
use PHPUnit\Framework\TestCase;
9
use ReflectionProperty;
10
use Tarantool\Mapper\Pool;
11
12
abstract class Test extends TestCase
13
{
14
    use Toolkit;
15
16
    public $params = [];
17
    public $disableRemote = true;
18
19
    public $mocks = [];
20
    public $data = [];
21
22 3
    public function __construct()
23
    {
24
        parent::__construct();
25
26
        $this->app = new Test\Application($this);
27
28
        foreach ($this->mocks as [$method, $params, $result]) {
29
            $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...
30
        }
31
32
        $serviceData = [];
33
        foreach ($this->data as $space => $data) {
34
            [$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...
35
            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...
36
                $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...
37
            }
38
            $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...
39
        }
40
41
        $pool = $this->app->get(Pool::class);
42
        $property = new ReflectionProperty(Pool::class, 'resolvers');
43
        $property->setAccessible(true);
44
        $property->setValue($pool, []);
45
46 3
        $pool->registerResolver(function($service) use ($serviceData) {
47 3
            if (array_key_exists($service, $serviceData)) {
48 2
                $mapper = new Test\Mapper($serviceData[$service]);
49 2
                $mapper->serviceName = $service;
0 ignored issues
show
Bug introduced by
The property serviceName does not seem to exist in Basis\Test\Mapper.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
50 2
                return $mapper;
51
            }
52 2
        });
53
    }
54
55 31
    public function setup()
56
    {
57 31
        $this->dispatch('tarantool.clear');
58 31
        $this->dispatch('tarantool.migrate');
59 31
    }
60
61 24
    public function tearDown()
62
    {
63 24
        $this->dispatch('tarantool.clear');
64 24
    }
65
66
    public $mockInstances = [];
67
68 4
    public function mock(string $job, array $params = [])
69
    {
70 4
        if (!array_key_exists($job, $this->mockInstances)) {
71 4
            $this->mockInstances[$job] = [];
72
        }
73
74 4
        $mock = new Test\Mock($this->get(Converter::class), $this);
75
76 4
        if (count($params)) {
77
            $mock->params = $params;
78
        }
79
80 4
        $this->mockInstances[$job][] = $mock;
81
82 4
        return $mock;
83
    }
84
}
85