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); |
|
|
|
|
33
|
|
|
if (!array_key_exists($service, $serviceData)) { |
|
|
|
|
34
|
|
|
$serviceData[$service] = []; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
$serviceData[$service][$space] = $data; |
|
|
|
|
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
|
|
|
|
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.