Skip to content

Commit 03a5c43

Browse files
committed
Various test fixes
1 parent 02f89da commit 03a5c43

File tree

3 files changed

+61
-57
lines changed

3 files changed

+61
-57
lines changed

phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<directory suffix="Test.php">./tests/Feature</directory>
1717
</testsuite>
1818
</testsuites>
19+
<listeners>
20+
<listener class="\Mockery\Adapter\Phpunit\TestListener"
21+
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php">
22+
</listener>
23+
</listeners>
1924
<php>
2025
<env name="APP_ENV" value="testing"/>
2126
<env name="APP_DEBUG" value="true"/>

tests/Unit/Eloquent/BuilderTest.php

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,92 +9,83 @@
99
use Grimzy\LaravelSpatial\Types\Polygon;
1010
use Illuminate\Database\Eloquent\Model;
1111
use Illuminate\Database\Query\Builder as QueryBuilder;
12-
use Illuminate\Database\Query\Expression;
12+
use Illuminate\Database\Query\Grammars\MySqlGrammar;
1313
use Mockery;
1414

1515
class BuilderTest extends BaseTestCase
1616
{
1717
protected $builder;
18-
19-
/**
20-
* @var \Mockery\MockInterface $queryBuilder
21-
*/
2218
protected $queryBuilder;
2319

2420
protected function setUp()
2521
{
2622
$connection = Mockery::mock(MysqlConnection::class)->makePartial();
27-
$this->queryBuilder = Mockery::mock(QueryBuilder::class, [$connection])->makePartial();
23+
$grammar = Mockery::mock(MySqlGrammar::class)->makePartial();
24+
$this->queryBuilder = Mockery::mock(QueryBuilder::class, [$connection, $grammar]);
2825

2926
$this->queryBuilder
3027
->shouldReceive('from')
28+
->once()
3129
->andReturn($this->queryBuilder);
3230

33-
$this->queryBuilder
34-
->shouldReceive('take')
35-
->with(1)
36-
->andReturn($this->queryBuilder);
37-
38-
$this->queryBuilder
39-
->shouldReceive('get')
40-
->andReturn([]);
41-
4231
$this->builder = new Builder($this->queryBuilder);
4332
$this->builder->setModel(new TestBuilderModel());
4433
}
4534

46-
public function testUpdate()
35+
public function testUpdatePoint()
4736
{
4837
$this->queryBuilder
4938
->shouldReceive('raw')
5039
->with("GeomFromText('POINT(2 1)')")
51-
->andReturn(new Expression("GeomFromText('POINT(2 1)')"));
40+
->once();
5241

5342
$this->queryBuilder
54-
->shouldReceive('update');
55-
56-
$builder = Mockery::mock(Builder::class, [$this->queryBuilder])->makePartial();
57-
$builder->shouldAllowMockingProtectedMethods();
58-
$builder
59-
->shouldReceive('addUpdatedAtColumn')
60-
->andReturn(['point' => new Point(1, 2)]);
43+
->shouldReceive('update')
44+
->once();
6145

62-
$builder->update(['point' => new Point(1, 3)]);
46+
$this->builder->update(['point' => new Point(1, 2)]);
6347
}
6448

6549
public function testUpdateLinestring()
6650
{
6751
$this->queryBuilder
6852
->shouldReceive('raw')
69-
->with("ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')")
70-
->andReturn(new Expression("ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)')"));
53+
->with("GeomFromText('LINESTRING(0 0,1 1,2 2)')")
54+
->once();
7155

7256
$this->queryBuilder
7357
->shouldReceive('update')
74-
->andReturn(1);
58+
->once();
7559

7660
$linestring = new LineString([new Point(0, 0), new Point(1, 1), new Point(2, 2)]);
7761

78-
$builder = Mockery::mock(Builder::class, [$this->queryBuilder])->makePartial();
79-
$builder->shouldAllowMockingProtectedMethods();
80-
$builder
81-
->shouldReceive('addUpdatedAtColumn')
82-
->andReturn(['linestring' => $linestring]);
62+
$this->builder->update(['linestring' => $linestring]);
63+
}
64+
65+
public function testUpdatePolygon()
66+
{
67+
$this->queryBuilder
68+
->shouldReceive('raw')
69+
->with("GeomFromText('POLYGON((0 0,1 0),(1 0,1 1),(1 1,0 0))')")
70+
->once();
71+
72+
$this->queryBuilder
73+
->shouldReceive('update')
74+
->once();
8375

84-
$builder
85-
->shouldReceive('asWKT')->with($linestring)->once();
76+
$linestrings[] = new LineString([new Point(0, 0), new Point(0, 1)]);
77+
$linestrings[] = new LineString([new Point(0, 1), new Point(1, 1)]);
78+
$linestrings[] = new LineString([new Point(1, 1), new Point(0, 0)]);
79+
$polygon = new Polygon($linestrings);
8680

87-
$builder->update(['linestring' => $linestring]);
81+
$this->builder->update(['polygon' => $polygon]);
8882
}
8983
}
9084

9185
class TestBuilderModel extends Model
9286
{
9387
use SpatialTrait;
9488

95-
protected $spatialFields = [
96-
'point' => Point::class,
97-
'linestring' => LineString::class,
98-
'polygon' => Polygon::class
99-
];
89+
public $timestamps = false;
90+
protected $spatialFields = ['point', 'linestring', 'polygon'];
10091
}

tests/Unit/Schema/BlueprintTest.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,71 +20,79 @@ public function setUp()
2020
public function testGeometry()
2121
{
2222
$this->blueprint
23-
->shouldReceive('addCommand')
24-
->with('geometry', ['col', null, 2, true]);
23+
->shouldReceive('addColumn')
24+
->with('geometry', 'col')
25+
->once();
2526

2627
$this->blueprint->geometry('col');
2728
}
2829

2930
public function testPoint()
3031
{
3132
$this->blueprint
32-
->shouldReceive('addCommand')
33-
->with('point', ['col', null, 2, true]);
33+
->shouldReceive('addColumn')
34+
->with('point', 'col')
35+
->once();
3436

3537
$this->blueprint->point('col');
3638
}
3739

3840
public function testLinestring()
3941
{
4042
$this->blueprint
41-
->shouldReceive('addCommand')
42-
->with('linestring', ['col', null, 2, true]);
43+
->shouldReceive('addColumn')
44+
->with('linestring', 'col')
45+
->once();
4346

4447
$this->blueprint->linestring('col');
4548
}
4649

4750
public function testPolygon()
4851
{
4952
$this->blueprint
50-
->shouldReceive('addCommand')
51-
->with('polygon', ['col', null, 2, true]);
53+
->shouldReceive('addColumn')
54+
->with('polygon', 'col')
55+
->once();
5256

5357
$this->blueprint->polygon('col');
5458
}
5559

5660
public function testMultiPoint()
5761
{
5862
$this->blueprint
59-
->shouldReceive('addCommand')
60-
->with('multipoint', ['col', null, 2, true]);
63+
->shouldReceive('addColumn')
64+
->with('multipoint', 'col')
65+
->once();
6166

6267
$this->blueprint->multipoint('col');
6368
}
6469

6570
public function testMultiLineString()
6671
{
6772
$this->blueprint
68-
->shouldReceive('addCommand')
69-
->with('multilinestring', ['col', null, 2, true]);
73+
->shouldReceive('addColumn')
74+
->with('multilinestring', 'col')
75+
->once();
7076

7177
$this->blueprint->multilinestring('col');
7278
}
7379

7480
public function testMulltiPolygon()
7581
{
7682
$this->blueprint
77-
->shouldReceive('addCommand')
78-
->with('multipolygon', ['col', null, 2, true]);
83+
->shouldReceive('addColumn')
84+
->with('multipolygon', 'col')
85+
->once();
7986

8087
$this->blueprint->multipolygon('col');
8188
}
8289

8390
public function testGeometryCollection()
8491
{
8592
$this->blueprint
86-
->shouldReceive('addCommand')
87-
->with('geometrycollection', ['col', null, 2, true]);
93+
->shouldReceive('addColumn')
94+
->with('geometrycollection', 'col')
95+
->once();
8896

8997
$this->blueprint->geometrycollection('col');
9098
}

0 commit comments

Comments
 (0)