Completed
Push — master ( b1fdaf...86da06 )
by Dmitry
06:20
created

Test::setup()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 11
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 8
nop 0
crap 20
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);
0 ignored issues
show
Bug introduced by
The property app does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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