1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\FluidSchema; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Schema; |
6
|
|
|
use Doctrine\DBAL\Types\Type; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class TdbmFluidColumnOptionsTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testOptions() |
12
|
|
|
{ |
13
|
|
|
$schema = new Schema(); |
14
|
|
|
$fluid = new TdbmFluidSchema($schema); |
15
|
|
|
|
16
|
|
|
$posts = $fluid->table('posts'); |
17
|
|
|
|
18
|
|
|
$column = $posts->column('foo'); |
19
|
|
|
$columnOptions = $column->integer(); |
20
|
|
|
|
21
|
|
|
$dbalColumn = $schema->getTable('posts')->getColumn('foo'); |
22
|
|
|
|
23
|
|
|
$columnOptions->null(); |
24
|
|
|
$this->assertSame(false, $dbalColumn->getNotnull()); |
25
|
|
|
|
26
|
|
|
$columnOptions->notNull(); |
27
|
|
|
$this->assertSame(true, $dbalColumn->getNotnull()); |
28
|
|
|
|
29
|
|
|
$columnOptions->unique(); |
30
|
|
|
$this->assertSame(true, $dbalColumn->getCustomSchemaOption('unique')); |
31
|
|
|
|
32
|
|
|
$columnOptions->comment('foo'); |
33
|
|
|
$this->assertSame('foo', $dbalColumn->getComment()); |
34
|
|
|
|
35
|
|
|
$columnOptions->autoIncrement(); |
36
|
|
|
$this->assertSame(true, $dbalColumn->getAutoincrement()); |
37
|
|
|
|
38
|
|
|
$columnOptions->default(42); |
39
|
|
|
$this->assertSame(42, $dbalColumn->getDefault()); |
40
|
|
|
|
41
|
|
|
$columnOptions->protectedGetter(); |
42
|
|
|
$this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedGetter', $dbalColumn->getComment()); |
43
|
|
|
|
44
|
|
|
$columnOptions->protectedSetter(); |
45
|
|
|
$this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedSetter', $dbalColumn->getComment()); |
46
|
|
|
|
47
|
|
|
$columnOptions->protectedOneToMany(); |
48
|
|
|
$this->assertContains('@TheCodingMachine\\TDBM\\Utils\\Annotation\\ProtectedOneToMany', $dbalColumn->getComment()); |
49
|
|
|
|
50
|
|
|
$this->assertSame($posts, $columnOptions->then()); |
51
|
|
|
|
52
|
|
|
$columnOptions->column('bar'); |
53
|
|
|
$this->assertTrue($schema->getTable('posts')->hasColumn('bar')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testIndex() |
57
|
|
|
{ |
58
|
|
|
$schema = new Schema(); |
59
|
|
|
$fluid = new TdbmFluidSchema($schema); |
60
|
|
|
|
61
|
|
|
$posts = $fluid->table('posts'); |
62
|
|
|
|
63
|
|
|
$posts->column('foo')->integer()->index(); |
64
|
|
|
|
65
|
|
|
$this->assertCount(1, $schema->getTable('posts')->getIndexes()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
public function testPrimaryKey() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$schema = new Schema(); |
71
|
|
|
$fluid = new TdbmFluidSchema($schema); |
72
|
|
|
|
73
|
|
|
$posts = $fluid->table('posts'); |
74
|
|
|
|
75
|
|
|
$posts->column('id')->integer()->primaryKey('pkname'); |
76
|
|
|
|
77
|
|
|
$this->assertTrue($schema->getTable('posts')->hasPrimaryKey()); |
78
|
|
|
$this->assertTrue($schema->getTable('posts')->hasIndex('pkname')); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.