Skip to content

Commit e3113dc

Browse files
committed
fix tests
Fix styling cleanup fix tests Fix styling fix test fix test Fix styling fix tests debugging tests
1 parent 7006c90 commit e3113dc

File tree

11 files changed

+51
-90
lines changed

11 files changed

+51
-90
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: run-tests
1+
name: PHP Tests
22

33
on:
44
push:
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
php-version: ${{ matrix.php }}
3939
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, mysql
40-
coverage: none
40+
coverage: xdebug
4141

4242
- name: Setup problem matchers
4343
run: |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"php": "^8.1",
2222
"ext-json": "*",
2323
"ext-pdo": "*",
24-
"doctrine/dbal": "^3.0",
24+
"doctrine/dbal": "^3.5",
2525
"geo-io/wkb-parser": "^1.0",
2626
"illuminate/contracts": "^10.0",
2727
"illuminate/database": "^10.0",

tests/Unit/Eloquent/TestModel.php renamed to tests/Integration/Eloquent/TestModel.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?php
22

3-
namespace Grimzy\LaravelMysqlSpatial\Tests\Unit\Eloquent;
3+
namespace Grimzy\LaravelMysqlSpatial\Tests\Integration\Eloquent;
44

5-
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
65
use Illuminate\Database\Eloquent\Model;
7-
use Mockery as m;
86

97
class TestModel extends Model
108
{
@@ -16,15 +14,6 @@ class TestModel extends Model
1614

1715
public static $pdo;
1816

19-
public static function resolveConnection($connection = null)
20-
{
21-
if (is_null(static::$pdo)) {
22-
static::$pdo = m::mock(TestPDO::class)->makePartial();
23-
}
24-
25-
return new MysqlConnection(static::$pdo);
26-
}
27-
2817
public function testrelatedmodels()
2918
{
3019
return $this->hasMany(TestRelatedModel::class);

tests/Unit/Eloquent/TestRelatedModel.php renamed to tests/Integration/Eloquent/TestRelatedModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Grimzy\LaravelMysqlSpatial\Tests\Unit\Eloquent;
3+
namespace Grimzy\LaravelMysqlSpatial\Tests\Integration\Eloquent;
44

55
class TestRelatedModel extends TestModel
66
{

tests/Integration/Migrations/CreateTables.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ class CreateTables extends Migration
1313
*/
1414
public function up(): void
1515
{
16+
Schema::create('test_models', function (Blueprint $table) {
17+
$table->charset = 'utf8mb4';
18+
$table->collation = 'utf8mb4_unicode_ci';
19+
$table->increments('id');
20+
$table->geometryCollection('geometrycollection')->default(null)->nullable();
21+
$table->lineString('linestring')->default(null)->nullable();
22+
$table->multiLineString('multilinestring')->default(null)->nullable();
23+
$table->multiPoint('multipoint')->default(null)->nullable();
24+
$table->multiPolygon('multipolygon')->default(null)->nullable();
25+
$table->point('point')->default(null)->nullable();
26+
$table->polygon('polygon')->default(null)->nullable();
27+
$table->timestamps();
28+
});
29+
1630
Schema::create('geometry', function (Blueprint $table) {
1731
$table->charset = 'utf8mb4';
1832
$table->collation = 'utf8mb4_unicode_ci';
@@ -56,5 +70,6 @@ public function down(): void
5670
Schema::drop('geometry');
5771
Schema::drop('no_spatial_fields');
5872
Schema::drop('with_srid');
73+
Schema::drop('test_models');
5974
}
6075
}

tests/Unit/Eloquent/SpatialTraitTest.php renamed to tests/Integration/SpatialTraitTest.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
<?php
22

3-
namespace Grimzy\LaravelMysqlSpatial\Tests\Unit\Eloquent;
3+
namespace Grimzy\LaravelMysqlSpatial\Tests\Integration;
44

55
use Grimzy\LaravelMysqlSpatial\Eloquent\SpatialTrait;
66
use Grimzy\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException;
7-
use Grimzy\LaravelMysqlSpatial\Tests\Unit\BaseTestCase;
7+
use Grimzy\LaravelMysqlSpatial\Tests\Integration\Eloquent\TestModel;
88
use Grimzy\LaravelMysqlSpatial\Types\Point;
99
use Illuminate\Database\Eloquent\Model;
10+
use Illuminate\Database\Events\QueryExecuted;
1011
use Illuminate\Support\Facades\DB;
1112
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1213

13-
class SpatialTraitTest extends BaseTestCase
14+
class SpatialTraitTest extends IntegrationBaseCase
1415
{
1516
use MockeryPHPUnitIntegration;
1617

1718
protected TestModel $model;
1819

19-
protected array $queries;
20+
protected array $queries = [];
2021

2122
public function setUp(): void
2223
{
2324
parent::setUp();
2425

2526
$this->model = new TestModel();
26-
$this->queries = &$this->model->getConnection()->getPdo()->queries;
27+
DB::listen(function (QueryExecuted $query) {
28+
$this->queries[] = $query->sql;
29+
});
2730
}
2831

2932
public function tearDown(): void
3033
{
31-
$this->model->getConnection()->getPdo()->resetQueries();
34+
$this->queries = [];
3235
}
3336

3437
public function testInsertUpdatePointHasCorrectSql()
@@ -78,23 +81,30 @@ public function testInsertUpdatePolygonHasCorrectSql()
7881
{
7982
$point1 = new Point(1, 2);
8083
$point2 = new Point(2, 3);
81-
$linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]);
8284
$point3 = new Point(3, 2);
8385
$point4 = new Point(2, 1);
84-
$linestring2 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point3, $point4]);
86+
87+
$polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([
88+
new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2, $point3, $point4, $point1]),
89+
]);
8590

8691
$this->assertFalse($this->model->exists);
8792

88-
$this->model->polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]);
93+
$this->model->polygon = $polygon;
8994
$this->model->save();
9095

9196
$this->assertStringStartsWith('insert', $this->queries[0]);
9297
$this->assertStringContainsString('insert into `test_models` (`polygon`) values (ST_GeomFromText(?, ?, \'axis-order=long-lat\'))', $this->queries[0]);
9398
// TODO: assert bindings in query
9499
$this->assertTrue($this->model->exists);
95100

96-
$this->model->polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]);
101+
$polygon = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([
102+
new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2, $point3, $point4, $point1]),
103+
]);
104+
105+
$this->model->polygon = $polygon;
97106
$this->model->save();
107+
98108
$this->assertStringStartsWith('update', $this->queries[1]);
99109
$this->assertStringContainsString('update `test_models` set `polygon` = ST_GeomFromText(?, ?, \'axis-order=long-lat\') where `id` = ?', $this->queries[1]);
100110
// TODO: assert bindings in query
@@ -153,19 +163,19 @@ public function testInsertUpdateMultiPolygonHasCorrectSql()
153163
{
154164
$point1 = new Point(1, 2);
155165
$point2 = new Point(2, 3);
156-
$linestring1 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2]);
157166
$point3 = new Point(3, 2);
158167
$point4 = new Point(2, 1);
159-
$linestring2 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point3, $point4]);
160-
$polygon1 = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring1, $linestring2]);
168+
$polygon1 = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([
169+
new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point1, $point2, $point3, $point1]),
170+
]);
161171

162172
$point5 = new Point(4, 5);
163173
$point6 = new Point(5, 6);
164-
$linestring3 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point5, $point6]);
165174
$point7 = new Point(6, 5);
166175
$point8 = new Point(5, 4);
167-
$linestring4 = new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point7, $point8]);
168-
$polygon2 = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring3, $linestring4]);
176+
$polygon2 = new \Grimzy\LaravelMysqlSpatial\Types\Polygon([
177+
new \Grimzy\LaravelMysqlSpatial\Types\LineString([$point5, $point6, $point7, $point5]),
178+
]);
169179

170180
$this->assertFalse($this->model->exists);
171181

tests/Integration/SridSpatialTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,8 @@ public function testInsertPointWithWrongSrid()
111111
$geo->location = new Point(1, 2);
112112

113113
$this->assertException(
114-
Illuminate\Database\QueryException::class,
115-
'SQLSTATE[HY000]: General error: 3643 The SRID of the geometry '.
116-
'does not match the SRID of the column \'location\'. The SRID '.
117-
'of the geometry is 0, but the SRID of the column is 3857. '.
118-
'Consider changing the SRID of the geometry or the SRID property '.
119-
'of the column. (SQL: insert into `with_srid` (`location`) values '.
120-
'(ST_GeomFromText(POINT(2 1), 0, \'axis-order=long-lat\')))'
114+
\Illuminate\Database\QueryException::class,
115+
"SQLSTATE[HY000]: General error: 3643 The SRID of the geometry does not match the SRID of the column 'location'. The SRID of the geometry is 0, but the SRID of the column is 3857. Consider changing the SRID of the geometry or the SRID property of the column. (Connection: mysql, SQL: insert into `with_srid` (`location`) values (ST_GeomFromText(POINT(2 1), 0, 'axis-order=long-lat')))"
121116
);
122117
$geo->save();
123118
}

tests/Unit/Connectors/ConnectionFactoryTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
use Grimzy\LaravelMysqlSpatial\Connectors\ConnectionFactory;
66
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
77
use Grimzy\LaravelMysqlSpatial\Tests\Unit\BaseTestCase;
8-
use Grimzy\LaravelMysqlSpatial\Tests\Unit\Stubs\PDOStub;
98
use Illuminate\Container\Container;
109
use Mockery;
1110

1211
class ConnectionFactoryTest extends BaseTestCase
1312
{
1413
public function testMakeCallsCreateConnection()
1514
{
16-
$pdo = new PDOStub();
15+
$pdo = $this->createMock(\PDO::class);
1716

1817
$factory = Mockery::mock(ConnectionFactory::class, [new Container()])->makePartial();
1918
$factory->shouldAllowMockingProtectedMethods();
@@ -24,7 +23,7 @@ public function testMakeCallsCreateConnection()
2423

2524
public function testCreateConnectionDifferentDriver()
2625
{
27-
$pdo = new PDOStub();
26+
$pdo = $this->createMock(\PDO::class);
2827

2928
$factory = Mockery::mock(ConnectionFactory::class, [new Container()])->makePartial();
3029
$factory->shouldAllowMockingProtectedMethods();

tests/Unit/Eloquent/TestPDO.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/Unit/MysqlConnectionTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Grimzy\LaravelMysqlSpatial\MysqlConnection;
66
use Grimzy\LaravelMysqlSpatial\Schema\Builder;
7-
use Grimzy\LaravelMysqlSpatial\Tests\Unit\Stubs\PDOStub;
87
use PHPUnit\Framework\TestCase;
98

109
class MysqlConnectionTest extends TestCase
@@ -14,7 +13,7 @@ class MysqlConnectionTest extends TestCase
1413
protected function setUp(): void
1514
{
1615
$mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo'];
17-
$this->mysqlConnection = new MysqlConnection(new PDOStub(), 'database', 'prefix', $mysqlConfig);
16+
$this->mysqlConnection = new MysqlConnection($this->createMock(\PDO::class), 'database', 'prefix', $mysqlConfig);
1817
}
1918

2019
public function testGetSchemaBuilder()

0 commit comments

Comments
 (0)