forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseSchemaBlueprintTest.php
More file actions
executable file
·75 lines (61 loc) · 3.03 KB
/
DatabaseSchemaBlueprintTest.php
File metadata and controls
executable file
·75 lines (61 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
use Mockery as m;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Grammars\MySqlGrammar;
use Illuminate\Database\Schema\Grammars\SQLiteGrammar;
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
use Illuminate\Database\Schema\Grammars\SqlServerGrammar;
class DatabaseSchemaBlueprintTest extends PHPUnit_Framework_TestCase
{
public function tearDown()
{
m::close();
}
public function testToSqlRunsCommandsFromBlueprint()
{
$conn = m::mock('Illuminate\Database\Connection');
$conn->shouldReceive('statement')->once()->with('foo');
$conn->shouldReceive('statement')->once()->with('bar');
$grammar = m::mock('Illuminate\Database\Schema\Grammars\MySqlGrammar');
$blueprint = $this->getMock('Illuminate\Database\Schema\Blueprint', ['toSql'], ['users']);
$blueprint->expects($this->once())->method('toSql')->with($this->equalTo($conn), $this->equalTo($grammar))->will($this->returnValue(['foo', 'bar']));
$blueprint->build($conn, $grammar);
}
public function testIndexDefaultNames()
{
$blueprint = new Blueprint('users');
$blueprint->unique(['foo', 'bar']);
$commands = $blueprint->getCommands();
$this->assertEquals('users_foo_bar_unique', $commands[0]->index);
$blueprint = new Blueprint('users');
$blueprint->index('foo');
$commands = $blueprint->getCommands();
$this->assertEquals('users_foo_index', $commands[0]->index);
}
public function testDropIndexDefaultNames()
{
$blueprint = new Blueprint('users');
$blueprint->dropUnique(['foo', 'bar']);
$commands = $blueprint->getCommands();
$this->assertEquals('users_foo_bar_unique', $commands[0]->index);
$blueprint = new Blueprint('users');
$blueprint->dropIndex(['foo']);
$commands = $blueprint->getCommands();
$this->assertEquals('users_foo_index', $commands[0]->index);
}
public function testDefaultCurrentTimestamp()
{
$base = new Blueprint('users', function ($table) {
$table->timestamp('created')->useCurrent();
});
$connection = m::mock('Illuminate\Database\Connection');
$blueprint = clone $base;
$this->assertEquals(['alter table `users` add `created` timestamp default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new MySqlGrammar));
$blueprint = clone $base;
$this->assertEquals(['alter table "users" add column "created" timestamp(0) without time zone default CURRENT_TIMESTAMP(0) not null'], $blueprint->toSql($connection, new PostgresGrammar));
$blueprint = clone $base;
$this->assertEquals(['alter table "users" add column "created" datetime default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new SQLiteGrammar));
$blueprint = clone $base;
$this->assertEquals(['alter table "users" add "created" datetime default CURRENT_TIMESTAMP not null'], $blueprint->toSql($connection, new SqlServerGrammar));
}
}