Completed
Push — master ( ea3156...ec95d0 )
by Dmitry
03:39
created

TarantoolTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setup() 0 17 3
B testMigrationOrder() 0 30 2
A testMigrationGenerator() 0 14 1
A testEntity() 0 17 1
A testRepositoryRegistration() 0 5 1
1
<?php
2
3
use Basis\Filesystem;
4
use Tarantool\Mapper\Bootstrap;
5
use Tarantool\Mapper\Mapper;
6
use Repository\Note;
7
8
class TarantoolTest extends TestSuite
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    public function setup()
11
    {
12
        parent::setup();
13
14
        $fs = $this->app->get(Filesystem::class);
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...
15
        $classes = $fs->listClasses('Migration');
16
17
        $dirs = [];
18
        foreach ($classes as $class) {
19
            $filename = $fs->getPath('php/'.str_replace('\\', '/', $class).'.php');
20
            unlink($filename);
21
            $dirs[dirname($filename)] = true;
22
        }
23
        foreach ($dirs as $dir => $_) {
24
            rmdir($dir);
25
        }
26
    }
27
28
    public function testMigrationOrder()
29
    {
30
        $this->app->dispatch('generate.migration', [
31
            'name' => 'b',
32
        ]);
33
34
        sleep(1);
35
36
        $this->app->dispatch('generate.migration', [
37
            'name' => 'a',
38
        ]);
39
40
        $this->app->dispatch('tarantool.migrate');
41
42
        $bootstrap = $this->app->get(Bootstrap::class);
43
44
        $reflection = new ReflectionClass(Bootstrap::class);
45
        $property = $reflection->getProperty('migrations');
46
        $property->setAccessible(true);
47
48
        $migrations = $property->getValue($bootstrap);
49
50
        $this->assertCount(2, $migrations);
51
52
        $order = [];
53
        foreach ($migrations as $migration) {
54
            $order[] = substr($migration, -1);
55
        }
56
        $this->assertSame(['B', 'A'], $order);
57
    }
58
59
    public function testMigrationGenerator()
60
    {
61
        $fs = $this->app->get(Filesystem::class);
62
63
        $classes = $fs->listClasses('Migration');
64
        $this->assertCount(0, $classes);
65
66
        $this->app->dispatch('generate.migration', [
67
            'name' => 'my migration created at ' . time(),
68
        ]);
69
70
        $classes = $fs->listClasses('Migration');
71
        $this->assertCount(1, $classes);
72
    }
73
74
    public function testEntity()
75
    {
76
        $this->app->dispatch('tarantool.migrate');
77
78
        $mapper = $this->app->get(Mapper::class);
79
        $mapper->getRepository('note')->truncate();
80
        $note = $mapper->getRepository('note')->create('zzz');
81
        $this->assertSame($note->message, 'zzz');
82
83
        $note->message = 'test';
84
        $note->save();
85
86
        $this->assertNotNull($note->id);
87
        $this->assertSame($note->message, 'test');
88
89
        $this->assertSame($note->app, $this->app);
90
    }
91
92
    public function testRepositoryRegistration()
93
    {
94
        $repository = $this->app->get(Note::class);
95
        $this->assertSame($this->app->get(Mapper::class), $repository->getMapper());
96
    }
97
}
98