|
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 |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
public function setup() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::setup(); |
|
13
|
|
|
|
|
14
|
|
|
$fs = $this->app->get(Filesystem::class); |
|
|
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.