|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yiisoft\Yii\Cycle\Tests\Conveyor; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Yiisoft\Yii\Cycle\Conveyor\AnnotatedSchemaConveyor; |
|
7
|
|
|
use Yiisoft\Yii\Cycle\Exception\EmptyEntityPathsException; |
|
8
|
|
|
use Yiisoft\Yii\Cycle\Tests\Conveyor\Stub\FakeContainer; |
|
9
|
|
|
use Yiisoft\Yii\Cycle\Tests\Conveyor\Stub\FakeGenerator; |
|
10
|
|
|
|
|
11
|
|
|
class AnnotatedSchemaConveyorTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testDefaultGeneratorsOrder(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$conveyor = $this->createConveyor(); |
|
16
|
|
|
|
|
17
|
|
|
// get generators list |
|
18
|
|
|
/** @var string[] $generators */ |
|
19
|
|
|
$generators = array_map( |
|
20
|
|
|
fn ($value) => $value instanceof FakeGenerator ? $value->originClass() : get_class($value), |
|
21
|
|
|
$conveyor->getGenerators() |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertSame([ |
|
25
|
|
|
'Cycle\Schema\Generator\ResetTables', |
|
26
|
|
|
'Cycle\Annotated\Embeddings', |
|
27
|
|
|
'Cycle\Annotated\Entities', |
|
28
|
|
|
'Cycle\Annotated\MergeColumns', |
|
29
|
|
|
'Cycle\Schema\Generator\GenerateRelations', |
|
30
|
|
|
'Cycle\Schema\Generator\ValidateEntities', |
|
31
|
|
|
'Cycle\Schema\Generator\RenderTables', |
|
32
|
|
|
'Cycle\Schema\Generator\RenderRelations', |
|
33
|
|
|
'Cycle\Annotated\MergeIndexes', |
|
34
|
|
|
'Cycle\Schema\Generator\GenerateTypecast', |
|
35
|
|
|
], $generators); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testAddCustomGenerator(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$conveyor = $this->createConveyor(); |
|
41
|
|
|
$conveyor->addGenerator($conveyor::STAGE_USERLAND, \Cycle\Schema\Generator\SyncTables::class); |
|
42
|
|
|
|
|
43
|
|
|
// get generators list |
|
44
|
|
|
/** @var string[] $generators */ |
|
45
|
|
|
$generators = array_map( |
|
46
|
|
|
fn ($value) => $value instanceof FakeGenerator ? $value->originClass() : get_class($value), |
|
47
|
|
|
$conveyor->getGenerators() |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame([ |
|
51
|
|
|
'Cycle\Schema\Generator\ResetTables', |
|
52
|
|
|
'Cycle\Annotated\Embeddings', |
|
53
|
|
|
'Cycle\Annotated\Entities', |
|
54
|
|
|
'Cycle\Annotated\MergeColumns', |
|
55
|
|
|
'Cycle\Schema\Generator\GenerateRelations', |
|
56
|
|
|
'Cycle\Schema\Generator\ValidateEntities', |
|
57
|
|
|
'Cycle\Schema\Generator\RenderTables', |
|
58
|
|
|
'Cycle\Schema\Generator\RenderRelations', |
|
59
|
|
|
'Cycle\Annotated\MergeIndexes', |
|
60
|
|
|
'Cycle\Schema\Generator\SyncTables', |
|
61
|
|
|
'Cycle\Schema\Generator\GenerateTypecast', |
|
62
|
|
|
], $generators); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testEmptyEntityPaths(): void |
|
66
|
|
|
{ |
|
67
|
|
|
$conveyor = $this->createConveyor([]); |
|
68
|
|
|
|
|
69
|
|
|
$this->expectException(EmptyEntityPathsException::class); |
|
70
|
|
|
|
|
71
|
|
|
$conveyor->getGenerators(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function createConveyor($entityPaths = ['@test-dir']): AnnotatedSchemaConveyor |
|
75
|
|
|
{ |
|
76
|
|
|
$conveyor = new AnnotatedSchemaConveyor(new FakeContainer($this)); |
|
77
|
|
|
$conveyor->addEntityPaths($entityPaths); |
|
78
|
|
|
|
|
79
|
|
|
return $conveyor; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|