Completed
Push — master ( 95b8e4...b19727 )
by Dmitry
06:52
created

src/Test.php (4 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 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);
28
        }
29
30
        $serviceData = [];
31
        foreach ($this->data as $space => $data) {
32
            [$service, $space] = explode('.', $space);
0 ignored issues
show
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
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
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
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 45
    public function setup()
52
    {
53 45
        $this->dispatch('tarantool.migrate');
54 45
    }
55
56 45
    public function tearDown()
57
    {
58 45
        $this->dispatch('tarantool.clear');
59 45
    }
60
61
    public $mockInstances = [];
62
63 5
    public function mock(string $job, array $params = [])
64
    {
65 5
        if (!array_key_exists($job, $this->mockInstances)) {
66 4
            $this->mockInstances[$job] = [];
67
        }
68
69 5
        $mock = new Test\Mock($this->get(Converter::class), $this, $params);
70
71 5
        $this->mockInstances[$job][] = $mock;
72
73 5
        return $mock;
74
    }
75
}
76