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