Completed
Branch testing (7f3043)
by Hennik
05:13
created

PostgresGrammarBaseTest::testEnablePostgis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
use Illuminate\Database\Connection;
4
use LaravelSpatial\PostgresConnection;
5
use LaravelSpatial\Schema\Blueprint;
6
use LaravelSpatial\Schema\Grammars\PostgresGrammar;
7
// use LaravelSpatial\Exceptions\PostgresTypesMalformedException;
8
// use LaravelSpatial\Exceptions\UnsupportedGeomtypeException;
9
10
class PostgresGrammarBaseTest extends BaseTestCase
11
{
12
    public function testAddingPoint()
13
    {
14
        $blueprint = new Blueprint('test');
15
        $blueprint->point('foo');
16
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
17
18
        $this->assertEquals(1, count($statements));
19
        $this->assertContains('GEOGRAPHY(POINT, 4326)', $statements[0]);
20
    }
21
22
    public function testAddingLinestring()
23
    {
24
        $blueprint = new Blueprint('test');
25
        $blueprint->linestring('foo');
26
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
27
28
        $this->assertEquals(1, count($statements));
29
        $this->assertContains('GEOGRAPHY(LINESTRING, 4326)', $statements[0]);
30
    }
31
32
    public function testAddingPolygon()
33
    {
34
        $blueprint = new Blueprint('test');
35
        $blueprint->polygon('foo');
36
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
37
38
        $this->assertEquals(1, count($statements));
39
        $this->assertContains('GEOGRAPHY(POLYGON, 4326)', $statements[0]);
40
    }
41
42
    public function testAddingMultipoint()
43
    {
44
        $blueprint = new Blueprint('test');
45
        $blueprint->multipoint('foo');
46
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
47
48
        $this->assertEquals(1, count($statements));
49
        $this->assertContains('GEOGRAPHY(MULTIPOINT, 4326)', $statements[0]);
50
    }
51
52
    public function testAddingMultiLinestring()
53
    {
54
        $blueprint = new Blueprint('test');
55
        $blueprint->multilinestring('foo');
56
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
57
58
        $this->assertEquals(1, count($statements));
59
        $this->assertContains('GEOGRAPHY(MULTILINESTRING, 4326)', $statements[0]);
60
    }
61
62
    public function testAddingMultiPolygon()
63
    {
64
        $blueprint = new Blueprint('test');
65
        $blueprint->multipolygon('foo');
66
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
67
68
        $this->assertEquals(1, count($statements));
69
        $this->assertContains('GEOGRAPHY(MULTIPOLYGON, 4326)', $statements[0]);
70
    }
71
72
    public function testAddingGeometry()
73
    {
74
        $blueprint = new Blueprint('test');
75
        $blueprint->geometry('foo');
76
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
77
78
        $this->assertEquals(1, count($statements));
79
        $this->assertContains('GEOMETRY', strtoupper($statements[0]));
80
    }
81
82
    public function testAddingGeometryCollection()
83
    {
84
        $blueprint = new Blueprint('test');
85
        $blueprint->geometrycollection('foo');
86
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
87
88
        $this->assertEquals(1, count($statements));
89
        $this->assertContains('GEOMETRYCOLLECTION', strtoupper($statements[0]));
90
    }
91
92
    public function testEnablePostgis()
93
    {
94
        $blueprint = new Blueprint('test');
95
        $blueprint->enablePostgis();
96
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
97
98
        $this->assertEquals(1, count($statements));
99
        $this->assertContains('CREATE EXTENSION postgis', $statements[0]);
100
    }
101
102
    public function testDisablePostgis()
103
    {
104
        $blueprint = new Blueprint('test');
105
        $blueprint->disablePostgis();
106
        $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
107
108
        $this->assertEquals(1, count($statements));
109
        $this->assertContains('DROP EXTENSION postgis', $statements[0]);
110
    }
111
112
    /**
113
     * @return Connection
114
     */
115
    protected function getConnection()
116
    {
117
        return Mockery::mock(PostgresConnection::class);
1 ignored issue
show
Bug Best Practice introduced by
The expression return Mockery::mock(Lar...tgresConnection::class) returns the type Mockery\MockInterface which is incompatible with the documented return type Illuminate\Database\Connection.
Loading history...
118
    }
119
120
    protected function getGrammar()
121
    {
122
        return new PostgresGrammar();
123
    }
124
}
125