Skip to content

Commit 546a4f6

Browse files
committed
Fixes for pass all tests
1 parent d79ed94 commit 546a4f6

File tree

4 files changed

+58
-42
lines changed

4 files changed

+58
-42
lines changed

src/Connectors/ConnectionFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Grimzy\LaravelMysqlSpatial\Connectors;
44

55
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
6+
use Illuminate\Database\Connection;
67
use Illuminate\Database\Connectors\ConnectionFactory as IlluminateConnectionFactory;
78
use PDO;
89

@@ -19,8 +20,8 @@ class ConnectionFactory extends IlluminateConnectionFactory
1920
*/
2021
protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])
2122
{
22-
if ($this->container->bound($key = "db.connection.{$driver}")) {
23-
return $this->container->make($key, [$connection, $database, $prefix, $config]); // @codeCoverageIgnore
23+
if ($resolver = Connection::getResolver($driver)) {
24+
return $resolver($connection, $database, $prefix, $config); // @codeCoverageIgnore
2425
}
2526

2627
if ($driver === 'mysql') {

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public function testInsertUpdatePointHasCorrectSql()
4040
$this->model->save();
4141

4242
$this->assertStringStartsWith('insert', $this->queries[0]);
43-
$this->assertContains('insert into `test_models` (`point`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
43+
$this->assertEquals('insert into `test_models` (`point`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
4444
// TODO: assert bindings in query
4545
$this->assertTrue($this->model->exists);
4646

4747
$this->model->point = new Point(1, 2);
4848
$this->model->save();
4949

5050
$this->assertStringStartsWith('update', $this->queries[1]);
51-
$this->assertContains('update `test_models` set `point` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
51+
$this->assertEquals('update `test_models` set `point` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
5252
// TODO: assert bindings in query
5353
}
5454

@@ -63,15 +63,15 @@ public function testInsertUpdateLineStringHasCorrectSql()
6363
$this->model->save();
6464

6565
$this->assertStringStartsWith('insert', $this->queries[0]);
66-
$this->assertContains('insert into `test_models` (`linestring`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
66+
$this->assertEquals('insert into `test_models` (`linestring`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
6767
// TODO: assert bindings in query
6868
$this->assertTrue($this->model->exists);
6969

7070
$this->model->linestring = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]);
7171
$this->model->save();
7272

7373
$this->assertStringStartsWith('update', $this->queries[1]);
74-
$this->assertContains('update `test_models` set `linestring` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
74+
$this->assertEquals('update `test_models` set `linestring` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
7575
// TODO: assert bindings in query
7676
}
7777

@@ -90,14 +90,14 @@ public function testInsertUpdatePolygonHasCorrectSql()
9090
$this->model->save();
9191

9292
$this->assertStringStartsWith('insert', $this->queries[0]);
93-
$this->assertContains('insert into `test_models` (`polygon`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
93+
$this->assertEquals('insert into `test_models` (`polygon`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
9494
// TODO: assert bindings in query
9595
$this->assertTrue($this->model->exists);
9696

9797
$this->model->polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]);
9898
$this->model->save();
9999
$this->assertStringStartsWith('update', $this->queries[1]);
100-
$this->assertContains('update `test_models` set `polygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
100+
$this->assertEquals('update `test_models` set `polygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
101101
// TODO: assert bindings in query
102102
}
103103

@@ -112,15 +112,15 @@ public function testInsertUpdateMultiPointHasCorrectSql()
112112
$this->model->save();
113113

114114
$this->assertStringStartsWith('insert', $this->queries[0]);
115-
$this->assertContains('insert into `test_models` (`multipoint`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
115+
$this->assertEquals('insert into `test_models` (`multipoint`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
116116
// TODO: assert bindings in query
117117
$this->assertTrue($this->model->exists);
118118

119119
$this->model->multipoint = new \Grimzy\LaravelMysqlSpatial\Types\MultiPoint([$point1, $point2]);
120120
$this->model->save();
121121

122122
$this->assertStringStartsWith('update', $this->queries[1]);
123-
$this->assertContains('update `test_models` set `multipoint` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
123+
$this->assertEquals('update `test_models` set `multipoint` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
124124
// TODO: assert bindings in query
125125
}
126126

@@ -139,14 +139,14 @@ public function testInsertUpdateMultiLineStringHasCorrectSql()
139139
$this->model->save();
140140

141141
$this->assertStringStartsWith('insert', $this->queries[0]);
142-
$this->assertContains('insert into `test_models` (`multilinestring`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
142+
$this->assertEquals('insert into `test_models` (`multilinestring`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
143143
// TODO: assert bindings in query
144144
$this->assertTrue($this->model->exists);
145145

146146
$this->model->multilinestring = new \Grimzy\LaravelMysqlSpatial\Types\MultiLineString([$linestring1, $linestring2]);
147147
$this->model->save();
148148
$this->assertStringStartsWith('update', $this->queries[1]);
149-
$this->assertContains('update `test_models` set `multilinestring` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
149+
$this->assertEquals('update `test_models` set `multilinestring` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
150150
// TODO: assert bindings in query
151151
}
152152

@@ -174,14 +174,14 @@ public function testInsertUpdateMultiPolygonHasCorrectSql()
174174
$this->model->save();
175175

176176
$this->assertStringStartsWith('insert', $this->queries[0]);
177-
$this->assertContains('insert into `test_models` (`multipolygon`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
177+
$this->assertEquals('insert into `test_models` (`multipolygon`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
178178
// TODO: assert bindings in query
179179
$this->assertTrue($this->model->exists);
180180

181181
$this->model->multipolygon = new \Grimzy\LaravelMysqlSpatial\Types\MultiPolygon([$polygon1, $polygon2]);
182182
$this->model->save();
183183
$this->assertStringStartsWith('update', $this->queries[1]);
184-
$this->assertContains('update `test_models` set `multipolygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
184+
$this->assertEquals('update `test_models` set `multipolygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
185185
// TODO: assert bindings in query
186186
}
187187

@@ -198,14 +198,14 @@ public function testInsertUpdateGeometryCollectionHasCorrectSql()
198198
$this->model->save();
199199

200200
$this->assertStringStartsWith('insert', $this->queries[0]);
201-
$this->assertContains('insert into `test_models` (`geometrycollection`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
201+
$this->assertEquals('insert into `test_models` (`geometrycollection`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
202202
// TODO: assert bindings in query
203203
$this->assertTrue($this->model->exists);
204204

205205
$this->model->geometrycollection = new \Grimzy\LaravelMysqlSpatial\Types\GeometryCollection([$point1, $linestring1]);
206206
$this->model->save();
207207
$this->assertStringStartsWith('update', $this->queries[1]);
208-
$this->assertContains('update `test_models` set `geometrycollection` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
208+
$this->assertEquals('update `test_models` set `geometrycollection` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
209209
// TODO: assert bindings in query
210210
}
211211

@@ -379,7 +379,7 @@ public function testScopeComparison()
379379
$this->assertNotEmpty($q->wheres);
380380
$bindings = $q->getRawBindings()['where'];
381381
$this->assertNotEmpty($bindings);
382-
$this->assertContains('st_within(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
382+
$this->assertEquals('st_within(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
383383
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
384384
}
385385

@@ -392,7 +392,7 @@ public function testScopeWithin()
392392
$this->assertNotEmpty($q->wheres);
393393
$bindings = $q->getRawBindings()['where'];
394394
$this->assertNotEmpty($bindings);
395-
$this->assertContains('st_within(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
395+
$this->assertEquals('st_within(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
396396
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
397397
}
398398

@@ -405,7 +405,7 @@ public function testScopeCrosses()
405405
$this->assertNotEmpty($q->wheres);
406406
$bindings = $q->getRawBindings()['where'];
407407
$this->assertNotEmpty($bindings);
408-
$this->assertContains('st_crosses(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
408+
$this->assertEquals('st_crosses(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
409409
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
410410
}
411411

@@ -418,7 +418,7 @@ public function testScopeContains()
418418
$this->assertNotEmpty($q->wheres);
419419
$bindings = $q->getRawBindings()['where'];
420420
$this->assertNotEmpty($bindings);
421-
$this->assertContains('st_contains(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
421+
$this->assertEquals('st_contains(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
422422
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
423423
}
424424

@@ -431,7 +431,7 @@ public function testScopeDisjoint()
431431
$this->assertNotEmpty($q->wheres);
432432
$bindings = $q->getRawBindings()['where'];
433433
$this->assertNotEmpty($bindings);
434-
$this->assertContains('st_disjoint(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
434+
$this->assertEquals('st_disjoint(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
435435
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
436436
}
437437

@@ -444,7 +444,7 @@ public function testScopeEquals()
444444
$this->assertNotEmpty($q->wheres);
445445
$bindings = $q->getRawBindings()['where'];
446446
$this->assertNotEmpty($bindings);
447-
$this->assertContains('st_equals(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
447+
$this->assertEquals('st_equals(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
448448
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
449449
}
450450

@@ -457,7 +457,7 @@ public function testScopeIntersects()
457457
$this->assertNotEmpty($q->wheres);
458458
$bindings = $q->getRawBindings()['where'];
459459
$this->assertNotEmpty($bindings);
460-
$this->assertContains('st_intersects(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
460+
$this->assertEquals('st_intersects(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
461461
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
462462
}
463463

@@ -470,7 +470,7 @@ public function testScopeOverlaps()
470470
$this->assertNotEmpty($q->wheres);
471471
$bindings = $q->getRawBindings()['where'];
472472
$this->assertNotEmpty($bindings);
473-
$this->assertContains('st_overlaps(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
473+
$this->assertEquals('st_overlaps(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
474474
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
475475
}
476476

@@ -483,7 +483,7 @@ public function testScopeDoesTouch()
483483
$this->assertNotEmpty($q->wheres);
484484
$bindings = $q->getRawBindings()['where'];
485485
$this->assertNotEmpty($bindings);
486-
$this->assertContains('st_touches(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
486+
$this->assertEquals('st_touches(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $q->wheres[0]['sql']);
487487
$this->assertEquals('POLYGON((1 1,2 1),(2 1,2 2),(2 2,1 1))', $bindings[0]);
488488
}
489489

@@ -507,7 +507,7 @@ public function testScopeOrderByDistance()
507507
$this->assertNotEmpty($q->orders);
508508
$bindings = $q->getRawBindings()['order'];
509509
$this->assertNotEmpty($bindings);
510-
$this->assertContains('st_distance(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) asc', $q->orders[0]['sql']);
510+
$this->assertEquals('st_distance(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) asc', $q->orders[0]['sql']);
511511
$this->assertEquals('POINT(2 1)', $bindings[0]);
512512
}
513513

@@ -521,7 +521,7 @@ public function testScopeOrderByDistanceSphere()
521521
$this->assertNotEmpty($q->orders);
522522
$bindings = $q->getRawBindings()['order'];
523523
$this->assertNotEmpty($bindings);
524-
$this->assertContains('st_distance_sphere(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) asc', $q->orders[0]['sql']);
524+
$this->assertEquals('st_distance_sphere(`point`, ST_GeomFromText(?, ?, \'axis-order=long-lat\')) asc', $q->orders[0]['sql']);
525525
$this->assertEquals('POINT(2 1)', $bindings[0]);
526526
}
527527
}
@@ -539,7 +539,19 @@ class TestModel extends Model
539539
public static function resolveConnection($connection = null)
540540
{
541541
if (is_null(static::$pdo)) {
542-
static::$pdo = m::mock('TestPDO')->makePartial();
542+
$pdo = m::mock('TestPDO')->makePartial();
543+
$pdo->shouldReceive('prepare')->andReturnUsing(function ($statement, $driver_options = []) use ($pdo) {
544+
$pdo->queries[] = $statement;
545+
546+
$stmt = m::mock('PDOStatement');
547+
$stmt->shouldReceive('bindValue')->zeroOrMoreTimes();
548+
$stmt->shouldReceive('execute');
549+
$stmt->shouldReceive('fetchAll')->andReturn([['id' => 1, 'point' => 'POINT(1 2)']]);
550+
$stmt->shouldReceive('rowCount')->andReturn(1);
551+
552+
return $stmt;
553+
});
554+
static::$pdo = $pdo;
543555
}
544556

545557
return new MysqlConnection(static::$pdo);
@@ -580,19 +592,6 @@ class TestPDO extends PDO
580592

581593
public $counter = 1;
582594

583-
public function prepare($statement, $driver_options = []): m\MockInterface|bool|m\LegacyMockInterface|string|PDOStatement
584-
{
585-
$this->queries[] = $statement;
586-
587-
$stmt = m::mock('PDOStatement');
588-
$stmt->shouldReceive('bindValue')->zeroOrMoreTimes();
589-
$stmt->shouldReceive('execute');
590-
$stmt->shouldReceive('fetchAll')->andReturn([['id' => 1, 'point' => 'POINT(1 2)']]);
591-
$stmt->shouldReceive('rowCount')->andReturn(1);
592-
593-
return $stmt;
594-
}
595-
596595
public function lastInsertId($name = null): string|false
597596
{
598597
return (string) $this->counter++;
@@ -602,4 +601,12 @@ public function resetQueries()
602601
{
603602
$this->queries = [];
604603
}
604+
605+
public function getAttribute(int $attribute): mixed
606+
{
607+
return match ($attribute) {
608+
self::ATTR_SERVER_VERSION => '8.0',
609+
default => parent::getAttribute($attribute),
610+
};
611+
}
605612
}

tests/Unit/Stubs/PDOStub.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@ class PDOStub extends \PDO
77
public function __construct()
88
{
99
}
10+
11+
public function getAttribute(int $attribute): mixed
12+
{
13+
return match ($attribute) {
14+
self::ATTR_SERVER_VERSION => '8.0',
15+
default => parent::getAttribute($attribute),
16+
};
17+
}
1018
}

tests/Unit/Types/GeometryCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testToArray()
7171
{
7272
$geometryCollection = $this->getGeometryCollection();
7373

74-
$this->assertInternalType('array', $geometryCollection->toArray());
74+
$this->assertIsArray($geometryCollection->toArray());
7575
}
7676

7777
public function testIteratorAggregate()

0 commit comments

Comments
 (0)