From 697b3aacf8b3d6618e6f74174acd426a7d522108 Mon Sep 17 00:00:00 2001 From: Shift Date: Thu, 3 Feb 2022 14:58:48 +0000 Subject: [PATCH 1/5] Bump dependencies for Laravel 9 --- composer.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 4451cb50..23bfedbc 100644 --- a/composer.json +++ b/composer.json @@ -15,27 +15,27 @@ } ], "require": { - "php": ">=7.3", + "php": "^8.0", "ext-pdo": "*", "ext-json": "*", - "illuminate/database": "^8.0", + "illuminate/database": "^9.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0" }, "require-dev": { - "phpunit/phpunit": "~6.5", + "phpunit/phpunit": "^9.5.10", "laravel/laravel": "^8.0", - "doctrine/dbal": "^2.5", - "laravel/browser-kit-testing": "^2.0", - "mockery/mockery": "^1.3" + "doctrine/dbal": "^3.3", + "laravel/browser-kit-testing": "^6.3", + "mockery/mockery": "^1.4.4" }, "autoload": { "psr-4": { "Grimzy\\LaravelMysqlSpatial\\": "src/" } }, - "autoload-dev" : { - "classmap" : [ + "autoload-dev": { + "classmap": [ "tests/Unit", "tests/Integration" ] From ab8550bfa728b41a5da28fd07e29aee4fae968fd Mon Sep 17 00:00:00 2001 From: Josh Baumann Date: Tue, 7 Mar 2023 11:38:49 +1300 Subject: [PATCH 2/5] Updating to Laravel 10 --- composer.json | 12 ++++++------ src/Eloquent/SpatialExpression.php | 3 ++- src/SpatialServiceProvider.php | 4 ++++ tests/Integration/IntegrationBaseTestCase.php | 7 ++++--- tests/Unit/BaseTestCase.php | 2 +- tests/Unit/Eloquent/BuilderTest.php | 2 +- tests/Unit/Eloquent/SpatialTraitTest.php | 6 ++++-- tests/Unit/MysqlConnectionTest.php | 2 +- tests/Unit/Schema/BlueprintTest.php | 2 +- tests/Unit/Types/LineStringTest.php | 2 +- tests/Unit/Types/PolygonTest.php | 2 +- 11 files changed, 26 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 23bfedbc..60207b7c 100644 --- a/composer.json +++ b/composer.json @@ -18,16 +18,16 @@ "php": "^8.0", "ext-pdo": "*", "ext-json": "*", - "illuminate/database": "^9.0", + "illuminate/database": "^10.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^9.5.10", - "laravel/laravel": "^8.0", - "doctrine/dbal": "^3.3", - "laravel/browser-kit-testing": "^6.3", - "mockery/mockery": "^1.4.4" + "phpunit/phpunit": "^10.0", + "laravel/laravel": "^10.0", + "doctrine/dbal": "^3.4", + "laravel/browser-kit-testing": "^7.0", + "mockery/mockery": "^1.5" }, "autoload": { "psr-4": { diff --git a/src/Eloquent/SpatialExpression.php b/src/Eloquent/SpatialExpression.php index 9224af0f..04a3011b 100644 --- a/src/Eloquent/SpatialExpression.php +++ b/src/Eloquent/SpatialExpression.php @@ -6,7 +6,8 @@ class SpatialExpression extends Expression { - public function getValue() + #[\ReturnTypeWillChange] + public function getValue($grammar) { return "ST_GeomFromText(?, ?, 'axis-order=long-lat')"; } diff --git a/src/SpatialServiceProvider.php b/src/SpatialServiceProvider.php index 3b859f8e..17147156 100644 --- a/src/SpatialServiceProvider.php +++ b/src/SpatialServiceProvider.php @@ -41,6 +41,10 @@ public function register() return new DatabaseManager($app, $app['db.factory']); }); + $this->app->bind('db.schema', function ($app) { + return $app['db']->connection()->getSchemaBuilder(); + }); + if (class_exists(DoctrineType::class)) { // Prevent geometry type fields from throwing a 'type not found' error when changing them $geometries = [ diff --git a/tests/Integration/IntegrationBaseTestCase.php b/tests/Integration/IntegrationBaseTestCase.php index 04634734..db3c8b55 100644 --- a/tests/Integration/IntegrationBaseTestCase.php +++ b/tests/Integration/IntegrationBaseTestCase.php @@ -44,7 +44,7 @@ public function createApplication() * * @return void */ - public function setUp() + public function setUp(): void { parent::setUp(); @@ -59,7 +59,7 @@ public function setUp() //}); } - public function tearDown() + public function tearDown(): void { $this->onMigrations(function ($migrationClass) { (new $migrationClass())->down(); @@ -71,7 +71,8 @@ public function tearDown() // MySQL 8.0.4 fixed bug #26941370 and bug #88031 private function isMySQL8AfterFix() { - $results = DB::select(DB::raw('select version()')); + $expression = DB::raw('select version()'); + $results = DB::select($expression->getValue(DB::connection()->getQueryGrammar())); $mysql_version = $results[0]->{'version()'}; return version_compare($mysql_version, '8.0.4', '>='); diff --git a/tests/Unit/BaseTestCase.php b/tests/Unit/BaseTestCase.php index 219f737d..215690ef 100644 --- a/tests/Unit/BaseTestCase.php +++ b/tests/Unit/BaseTestCase.php @@ -4,7 +4,7 @@ abstract class BaseTestCase extends TestCase { - public function tearDown() + public function tearDown(): void { Mockery::close(); } diff --git a/tests/Unit/Eloquent/BuilderTest.php b/tests/Unit/Eloquent/BuilderTest.php index d9a12a55..5d88ba19 100644 --- a/tests/Unit/Eloquent/BuilderTest.php +++ b/tests/Unit/Eloquent/BuilderTest.php @@ -20,7 +20,7 @@ class BuilderTest extends BaseTestCase protected $builder; protected $queryBuilder; - protected function setUp() + protected function setUp(): void { $connection = Mockery::mock(MysqlConnection::class)->makePartial(); $grammar = Mockery::mock(MySqlGrammar::class)->makePartial(); diff --git a/tests/Unit/Eloquent/SpatialTraitTest.php b/tests/Unit/Eloquent/SpatialTraitTest.php index 8ece7d25..80c2d3bd 100644 --- a/tests/Unit/Eloquent/SpatialTraitTest.php +++ b/tests/Unit/Eloquent/SpatialTraitTest.php @@ -21,13 +21,13 @@ class SpatialTraitTest extends BaseTestCase */ protected $queries; - public function setUp() + public function setUp(): void { $this->model = new TestModel(); $this->queries = &$this->model->getConnection()->getPdo()->queries; } - public function tearDown() + public function tearDown(): void { $this->model->getConnection()->getPdo()->resetQueries(); } @@ -580,6 +580,7 @@ class TestPDO extends PDO public $counter = 1; + #[\ReturnTypeWillChange] public function prepare($statement, $driver_options = []) { $this->queries[] = $statement; @@ -593,6 +594,7 @@ public function prepare($statement, $driver_options = []) return $stmt; } + #[\ReturnTypeWillChange] public function lastInsertId($name = null) { return $this->counter++; diff --git a/tests/Unit/MysqlConnectionTest.php b/tests/Unit/MysqlConnectionTest.php index cae970a2..c80b14fe 100644 --- a/tests/Unit/MysqlConnectionTest.php +++ b/tests/Unit/MysqlConnectionTest.php @@ -9,7 +9,7 @@ class MysqlConnectionTest extends TestCase { private $mysqlConnection; - protected function setUp() + protected function setUp(): void { $mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo']; $this->mysqlConnection = new MysqlConnection(new PDOStub(), 'database', 'prefix', $mysqlConfig); diff --git a/tests/Unit/Schema/BlueprintTest.php b/tests/Unit/Schema/BlueprintTest.php index c22c9518..457adab1 100644 --- a/tests/Unit/Schema/BlueprintTest.php +++ b/tests/Unit/Schema/BlueprintTest.php @@ -14,7 +14,7 @@ class BlueprintTest extends BaseTestCase */ protected $blueprint; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Unit/Types/LineStringTest.php b/tests/Unit/Types/LineStringTest.php index ce5713d2..0262dea0 100644 --- a/tests/Unit/Types/LineStringTest.php +++ b/tests/Unit/Types/LineStringTest.php @@ -7,7 +7,7 @@ class LineStringTest extends BaseTestCase { private $points; - protected function setUp() + protected function setUp(): void { $this->points = [new Point(0, 0), new Point(1, 1), new Point(2, 2)]; } diff --git a/tests/Unit/Types/PolygonTest.php b/tests/Unit/Types/PolygonTest.php index aaab437b..b572f121 100644 --- a/tests/Unit/Types/PolygonTest.php +++ b/tests/Unit/Types/PolygonTest.php @@ -8,7 +8,7 @@ class PolygonTest extends BaseTestCase { private $polygon; - protected function setUp() + protected function setUp(): void { $collection = new LineString( [ From d2f8aeaa56a5fd3a25ee6adcb5d0474c7e06949d Mon Sep 17 00:00:00 2001 From: Casper Bloemendaal Date: Tue, 12 Mar 2024 19:25:54 +0100 Subject: [PATCH 3/5] Laravel 11 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 60207b7c..74b3ff98 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,16 @@ } ], "require": { - "php": "^8.0", + "php": "^8.2", "ext-pdo": "*", "ext-json": "*", - "illuminate/database": "^10.0", + "illuminate/database": "^11.0", "geo-io/wkb-parser": "^1.0", "jmikola/geojson": "^1.0" }, "require-dev": { "phpunit/phpunit": "^10.0", - "laravel/laravel": "^10.0", + "laravel/laravel": "^11.0", "doctrine/dbal": "^3.4", "laravel/browser-kit-testing": "^7.0", "mockery/mockery": "^1.5" From fc849a61116af14e7ce3a9ff4bee679ee0018188 Mon Sep 17 00:00:00 2001 From: Casper Bloemendaal Date: Tue, 12 Mar 2024 19:34:51 +0100 Subject: [PATCH 4/5] fix coding standards --- src/SpatialServiceProvider.php | 2 +- tests/Unit/Eloquent/SpatialTraitTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SpatialServiceProvider.php b/src/SpatialServiceProvider.php index 17147156..4e32f5d3 100644 --- a/src/SpatialServiceProvider.php +++ b/src/SpatialServiceProvider.php @@ -42,7 +42,7 @@ public function register() }); $this->app->bind('db.schema', function ($app) { - return $app['db']->connection()->getSchemaBuilder(); + return $app['db']->connection()->getSchemaBuilder(); }); if (class_exists(DoctrineType::class)) { diff --git a/tests/Unit/Eloquent/SpatialTraitTest.php b/tests/Unit/Eloquent/SpatialTraitTest.php index 80c2d3bd..87dc6f59 100644 --- a/tests/Unit/Eloquent/SpatialTraitTest.php +++ b/tests/Unit/Eloquent/SpatialTraitTest.php @@ -214,7 +214,7 @@ public function testSettingRawAttributes() $attributes['point'] = "\0\0\0\0".'0101000000000000000000f03f0000000000000040'; $this->model->setRawAttributes($attributes); - $this->assertInstanceOf(Point::class, ($this->model->point)); + $this->assertInstanceOf(Point::class, $this->model->point); } public function testSpatialFieldsNotDefinedException() From a31a949e49f01a76b4eb8795f1d9273b876141e2 Mon Sep 17 00:00:00 2001 From: Casper Bloemendaal Date: Tue, 12 Mar 2024 19:38:08 +0100 Subject: [PATCH 5/5] considered refactoring --- src/SpatialServiceProvider.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/SpatialServiceProvider.php b/src/SpatialServiceProvider.php index 4e32f5d3..732d84bb 100644 --- a/src/SpatialServiceProvider.php +++ b/src/SpatialServiceProvider.php @@ -30,20 +30,14 @@ public function register() // The connection factory is used to create the actual connection instances on // the database. We will inject the factory into the manager so that it may // make the connections while they are actually needed and not of before. - $this->app->singleton('db.factory', function ($app) { - return new ConnectionFactory($app); - }); + $this->app->singleton('db.factory', fn ($app) => new ConnectionFactory($app)); // The database manager is used to resolve various connections, since multiple // connections might be managed. It also implements the connection resolver // interface which may be used by other components requiring connections. - $this->app->singleton('db', function ($app) { - return new DatabaseManager($app, $app['db.factory']); - }); + $this->app->singleton('db', fn ($app) => new DatabaseManager($app, $app['db.factory'])); - $this->app->bind('db.schema', function ($app) { - return $app['db']->connection()->getSchemaBuilder(); - }); + $this->app->bind('db.schema', fn ($app) => $app['db']->connection()->getSchemaBuilder()); if (class_exists(DoctrineType::class)) { // Prevent geometry type fields from throwing a 'type not found' error when changing them