|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Basis; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Tarantool\Mapper\Mapper; |
|
7
|
|
|
use Tarantool\Mapper\Entity; |
|
8
|
|
|
|
|
9
|
|
|
abstract class Test extends TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function setup() |
|
12
|
|
|
{ |
|
13
|
|
|
$root = getcwd(); |
|
14
|
|
|
|
|
15
|
|
|
$service = getenv('SERVICE_NAME') ?: basename($root); |
|
16
|
|
|
$host = getenv('TARANTOOL_SERVICE_HOST') ?: '127.0.0.1'; |
|
17
|
|
|
$port = getenv('TARANTOOL_SERVICE_PORT') ?: '3302'; |
|
18
|
|
|
|
|
19
|
|
|
$this->app = new Application($root); |
|
|
|
|
|
|
20
|
|
|
$this->get(Config::class)['service'] = $service; |
|
21
|
|
|
$this->get(Config::class)['tarantool'] = "tcp://$host:$port"; |
|
22
|
|
|
$this->dispatch('tarantool.migrate'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function tearDown() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->dispatch('tarantool.clear'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function dispatch(string $job, array $params = []) |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->app->dispatch($job, $params); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function get(string $class) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->app->get($class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getMapper() : Mapper |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->get(Mapper::class); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function find(string $space, array $params = []) : array |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->getMapper()->find($space, $params); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function findOne(string $space, array $params = []) : Entity |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->getMapper()->findOne($space, $params); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function findOrFail(string $space, array $params = []) : Entity |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->getMapper()->findOrFail($space, $params); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function findOrCreate(string $space, array $params = []) : Entity |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getMapper()->findOrCreate($space, $params); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: