-
Notifications
You must be signed in to change notification settings - Fork 17
/
PartitionTest.php
141 lines (122 loc) · 3.56 KB
/
PartitionTest.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
declare(strict_types=1);
namespace Umbrellio\Postgres\Unit\Schema\Blueprint;
use Illuminate\Support\Carbon;
use InvalidArgumentException;
use Umbrellio\Postgres\Tests\TestCase;
use Umbrellio\Postgres\Tests\Unit\Helpers\BlueprintAssertions;
class PartitionTest extends TestCase
{
use BlueprintAssertions;
private const TABLE = 'test_table';
protected function setUp(): void
{
parent::setUp();
$this->initializeMock(static::TABLE);
}
/**
* @test
*/
public function detachPartition(): void
{
$this->blueprint->detachPartition('some_partition');
$this->assertSameSql('alter table "test_table" detach partition some_partition');
}
/**
* @test
*/
public function attachPartitionRangeInt(): void
{
$this->blueprint->attachPartition('some_partition')
->range([
'from' => 10,
'to' => 100,
]);
$this->assertSameSql('alter table "test_table" attach partition some_partition for values from (10) to (100)');
}
/**
* @test
*/
public function attachPartitionFailedWithoutForValuesPart(): void
{
$this->blueprint->attachPartition('some_partition');
$this->expectException(InvalidArgumentException::class);
$this->runToSql();
}
/**
* @test
*/
public function attachPartitionRangeDates(): void
{
$today = Carbon::today();
$tomorrow = Carbon::tomorrow();
$this->blueprint->attachPartition('some_partition')
->range([
'from' => $today,
'to' => $tomorrow,
]);
$this->assertSameSql(sprintf(
'alter table "test_table" attach partition some_partition for values from (\'%s\') to (\'%s\')',
$today->toDateTimeString(),
$tomorrow->toDateTimeString()
));
}
/**
* @test
*/
public function attachPartitionStringDates(): void
{
$today = '2010-01-01';
$tomorrow = '2010-12-31';
$this->blueprint->attachPartition('some_partition')
->range([
'from' => $today,
'to' => $tomorrow,
]);
$this->assertSameSql(sprintf(
'alter table "test_table" attach partition some_partition for values from (\'%s\') to (\'%s\')',
$today,
$tomorrow
));
}
/**
* @test
*/
public function addingTsrangeColumn()
{
$this->blueprint->tsrange('foo');
$this->assertSameSql('alter table "test_table" add column "foo" tsrange not null');
}
/**
* @test
*/
public function addingDaterangeColumn()
{
$this->blueprint->daterange('foo');
$this->assertSameSql('alter table "test_table" add column "foo" daterange not null');
}
/**
* @test
*/
public function addingNumericColumnWithVariablePrecicion()
{
$this->blueprint->numeric('foo');
$this->assertSameSql('alter table "test_table" add column "foo" numeric not null');
}
/**
* @test
*/
public function addingNumericColumnWithDefinedPrecicion()
{
$this->blueprint->numeric('foo', 8);
$this->assertSameSql('alter table "test_table" add column "foo" numeric(8) not null');
}
/**
* @test
*/
public function addingNumericColumnWithDefinedPrecicionAndScope()
{
$this->blueprint->numeric('foo', 8, 2);
$this->assertSameSql('alter table "test_table" add column "foo" numeric(8, 2) not null');
}
}