1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Connection; |
4
|
|
|
use LaravelSpatial\MysqlConnection; |
5
|
|
|
use LaravelSpatial\Schema\Blueprint; |
6
|
|
|
use LaravelSpatial\Schema\Grammars\MySqlGrammar; |
7
|
|
|
|
8
|
|
|
class MySqlGrammarBaseTest extends BaseTestCase |
9
|
|
|
{ |
10
|
|
|
public function testAddingGeometry() |
11
|
|
|
{ |
12
|
|
|
$blueprint = new Blueprint('test'); |
13
|
|
|
$blueprint->geometry('foo'); |
14
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
15
|
|
|
|
16
|
|
|
$this->assertEquals(1, count($statements)); |
17
|
|
|
$this->assertContains('GEOMETRY', $statements[0]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testAddingPoint() |
21
|
|
|
{ |
22
|
|
|
$blueprint = new Blueprint('test'); |
23
|
|
|
$blueprint->point('foo'); |
24
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
25
|
|
|
|
26
|
|
|
$this->assertEquals(1, count($statements)); |
27
|
|
|
$this->assertContains('POINT', $statements[0]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testAddingLinestring() |
31
|
|
|
{ |
32
|
|
|
$blueprint = new Blueprint('test'); |
33
|
|
|
$blueprint->linestring('foo'); |
34
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
35
|
|
|
|
36
|
|
|
$this->assertEquals(1, count($statements)); |
37
|
|
|
$this->assertContains('LINESTRING', $statements[0]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testAddingPolygon() |
41
|
|
|
{ |
42
|
|
|
$blueprint = new Blueprint('test'); |
43
|
|
|
$blueprint->polygon('foo'); |
44
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
45
|
|
|
|
46
|
|
|
$this->assertEquals(1, count($statements)); |
47
|
|
|
$this->assertContains('POLYGON', $statements[0]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testAddingMultipoint() |
51
|
|
|
{ |
52
|
|
|
$blueprint = new Blueprint('test'); |
53
|
|
|
$blueprint->multipoint('foo'); |
54
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
55
|
|
|
|
56
|
|
|
$this->assertEquals(1, count($statements)); |
57
|
|
|
$this->assertContains('MULTIPOINT', $statements[0]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testAddingMultiLinestring() |
61
|
|
|
{ |
62
|
|
|
$blueprint = new Blueprint('test'); |
63
|
|
|
$blueprint->multilinestring('foo'); |
64
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(1, count($statements)); |
67
|
|
|
$this->assertContains('MULTILINESTRING', $statements[0]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testAddingMultiPolygon() |
71
|
|
|
{ |
72
|
|
|
$blueprint = new Blueprint('test'); |
73
|
|
|
$blueprint->multipolygon('foo'); |
74
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
75
|
|
|
|
76
|
|
|
$this->assertEquals(1, count($statements)); |
77
|
|
|
$this->assertContains('MULTIPOLYGON', $statements[0]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testAddingGeometryCollection() |
81
|
|
|
{ |
82
|
|
|
$blueprint = new Blueprint('test'); |
83
|
|
|
$blueprint->geometrycollection('foo'); |
84
|
|
|
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
85
|
|
|
|
86
|
|
|
$this->assertEquals(1, count($statements)); |
87
|
|
|
$this->assertContains('GEOMETRYCOLLECTION', $statements[0]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testAddRemoveSpatialIndex() |
91
|
|
|
{ |
92
|
|
|
$blueprint = new Blueprint('test'); |
93
|
|
|
$blueprint->point('foo'); |
94
|
|
|
$blueprint->spatialIndex('foo'); |
95
|
|
|
$addStatements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
96
|
|
|
|
97
|
|
|
$this->assertEquals(2, count($addStatements)); |
98
|
|
|
$this->assertContains('alter table `test` add spatial index `test_foo_spatialindex`(`foo`)', $addStatements[1]); |
99
|
|
|
|
100
|
|
|
$blueprint->dropSpatialIndex(['foo']); |
101
|
|
|
$blueprint->dropSpatialIndex('test_foo_spatialindex'); |
102
|
|
|
$dropStatements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
103
|
|
|
|
104
|
|
|
$expectedSql = 'alter table `test` drop index `test_foo_spatialindex`'; |
105
|
|
|
$this->assertEquals(5, count($dropStatements)); |
106
|
|
|
$this->assertContains($expectedSql, $dropStatements[3]); |
107
|
|
|
$this->assertContains($expectedSql, $dropStatements[4]); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Connection |
112
|
|
|
*/ |
113
|
|
|
protected function getConnection() |
114
|
|
|
{ |
115
|
|
|
return Mockery::mock(MysqlConnection::class); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
protected function getGrammar() |
119
|
|
|
{ |
120
|
|
|
return new MySqlGrammar(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|