Skip to content

Commit d79ed94

Browse files
committed
fix test for Laravel9 & PHP8.1
1 parent b81503f commit d79ed94

File tree

13 files changed

+67
-59
lines changed

13 files changed

+67
-59
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mDB_DIR=$(shell pwd)/_db-$(mV)
66
start_db:
77
@echo Starting MySQL $(V)
88
docker run --rm -d --name spatial-mysql \
9+
--platform "linux/x86_64" \
910
-p 3306:3306 \
1011
-v $(DB_DIR):/var/lib/mysql \
1112
-e MYSQL_DATABASE=spatial_test \

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "^9.5.10",
27-
"laravel/laravel": "^8.0",
27+
"laravel/laravel": "^9.0",
2828
"doctrine/dbal": "^3.3",
2929
"laravel/browser-kit-testing": "^6.3",
3030
"mockery/mockery": "^1.4.4"

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: '3.3'
22
services:
33
db:
4+
platform: linux/x86_64
45
image: mysql:5.7
56
ports:
67
- "3306:3306"

phpunit.xml.dist

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,37 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="./vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="unit">
13-
<directory suffix="Test.php">./tests/Unit</directory>
14-
</testsuite>
15-
<testsuite name="integration">
16-
<directory suffix="Test.php">./tests/Integration</directory>
17-
</testsuite>
18-
</testsuites>
19-
<listeners>
20-
<listener class="\Mockery\Adapter\Phpunit\TestListener"
21-
file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="./vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
<report>
8+
<clover outputFile="build/logs/clover.xml"/>
9+
</report>
10+
</coverage>
11+
<testsuites>
12+
<testsuite name="unit">
13+
<directory suffix="Test.php">./tests/Unit</directory>
14+
</testsuite>
15+
<testsuite name="integration">
16+
<directory suffix="Test.php">./tests/Integration</directory>
17+
</testsuite>
18+
</testsuites>
19+
<listeners>
20+
<listener class="\Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php">
2221
</listener>
23-
</listeners>
24-
<filter>
25-
<whitelist processUncoveredFilesFromWhitelist="true">
26-
<directory suffix=".php">./src</directory>
27-
</whitelist>
28-
</filter>
29-
<logging>
30-
<log type="coverage-clover" target="build/logs/clover.xml"/>
31-
</logging>
32-
<php>
33-
<env name="APP_ENV" value="testing"/>
34-
<env name="APP_DEBUG" value="true"/>
35-
<env name="APP_KEY" value="V4EYYl0MjI4Bin9GkFPUE3cpAARPCF27"/>
36-
<env name="CACHE_DRIVER" value="array"/>
37-
<env name="SESSION_DRIVER" value="array"/>
38-
<env name="QUEUE_DRIVER" value="sync"/>
39-
<env name="DB_DATABASE" value="spatial_test"/>
40-
<env name="DB_HOST" value="127.0.0.1"/>
41-
<env name="DB_PORT" value="3306"/>
42-
<env name="DB_USERNAME" value="root"/>
43-
<env name="DB_PASSWORD" value=""/>
44-
</php>
45-
</phpunit>
22+
</listeners>
23+
<logging/>
24+
<php>
25+
<env name="APP_ENV" value="testing"/>
26+
<env name="APP_DEBUG" value="true"/>
27+
<env name="APP_KEY" value="V4EYYl0MjI4Bin9GkFPUE3cpAARPCF27"/>
28+
<env name="CACHE_DRIVER" value="array"/>
29+
<env name="SESSION_DRIVER" value="array"/>
30+
<env name="QUEUE_DRIVER" value="sync"/>
31+
<env name="DB_DATABASE" value="spatial_test"/>
32+
<env name="DB_HOST" value="127.0.0.1"/>
33+
<env name="DB_PORT" value="3306"/>
34+
<env name="DB_USERNAME" value="root"/>
35+
<env name="DB_PASSWORD" value=""/>
36+
</php>
37+
</phpunit>

src/SpatialServiceProvider.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@
1414
use Grimzy\LaravelMysqlSpatial\Doctrine\Polygon;
1515
use Illuminate\Database\DatabaseManager;
1616
use Illuminate\Database\DatabaseServiceProvider;
17+
use Illuminate\Database\DatabaseTransactionsManager;
1718

1819
/**
1920
* Class DatabaseServiceProvider.
2021
*/
2122
class SpatialServiceProvider extends DatabaseServiceProvider
2223
{
2324
/**
24-
* Register the service provider.
25+
* Register the primary database bindings.
2526
*
2627
* @return void
28+
* @throws \Doctrine\DBAL\Exception
2729
*/
28-
public function register()
30+
protected function registerConnectionServices()
2931
{
3032
// The connection factory is used to create the actual connection instances on
3133
// the database. We will inject the factory into the manager so that it may
@@ -41,6 +43,18 @@ public function register()
4143
return new DatabaseManager($app, $app['db.factory']);
4244
});
4345

46+
$this->app->bind('db.connection', function ($app) {
47+
return $app['db']->connection();
48+
});
49+
50+
$this->app->bind('db.schema', function ($app) {
51+
return $app['db']->connection()->getSchemaBuilder();
52+
});
53+
54+
$this->app->singleton('db.transactions', function ($app) {
55+
return new DatabaseTransactionsManager;
56+
});
57+
4458
if (class_exists(DoctrineType::class)) {
4559
// Prevent geometry type fields from throwing a 'type not found' error when changing them
4660
$geometries = [

tests/Integration/IntegrationBaseTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function createApplication()
4444
*
4545
* @return void
4646
*/
47-
public function setUp()
47+
public function setUp(): void
4848
{
4949
parent::setUp();
5050

@@ -59,7 +59,7 @@ public function setUp()
5959
//});
6060
}
6161

62-
public function tearDown()
62+
public function tearDown(): void
6363
{
6464
$this->onMigrations(function ($migrationClass) {
6565
(new $migrationClass())->down();

tests/Unit/BaseTestCase.php

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

55
abstract class BaseTestCase extends TestCase
66
{
7-
public function tearDown()
7+
public function tearDown(): void
88
{
99
Mockery::close();
1010
}

tests/Unit/Eloquent/BuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BuilderTest extends BaseTestCase
2020
protected $builder;
2121
protected $queryBuilder;
2222

23-
protected function setUp()
23+
protected function setUp(): void
2424
{
2525
$connection = Mockery::mock(MysqlConnection::class)->makePartial();
2626
$grammar = Mockery::mock(MySqlGrammar::class)->makePartial();

tests/Unit/Eloquent/SpatialTraitTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class SpatialTraitTest extends BaseTestCase
2121
*/
2222
protected $queries;
2323

24-
public function setUp()
24+
public function setUp(): void
2525
{
2626
$this->model = new TestModel();
2727
$this->queries = &$this->model->getConnection()->getPdo()->queries;
2828
}
2929

30-
public function tearDown()
30+
public function tearDown(): void
3131
{
3232
$this->model->getConnection()->getPdo()->resetQueries();
3333
}
@@ -580,7 +580,7 @@ class TestPDO extends PDO
580580

581581
public $counter = 1;
582582

583-
public function prepare($statement, $driver_options = [])
583+
public function prepare($statement, $driver_options = []): m\MockInterface|bool|m\LegacyMockInterface|string|PDOStatement
584584
{
585585
$this->queries[] = $statement;
586586

@@ -593,9 +593,9 @@ public function prepare($statement, $driver_options = [])
593593
return $stmt;
594594
}
595595

596-
public function lastInsertId($name = null)
596+
public function lastInsertId($name = null): string|false
597597
{
598-
return $this->counter++;
598+
return (string) $this->counter++;
599599
}
600600

601601
public function resetQueries()

tests/Unit/MysqlConnectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MysqlConnectionTest extends TestCase
99
{
1010
private $mysqlConnection;
1111

12-
protected function setUp()
12+
protected function setUp(): void
1313
{
1414
$mysqlConfig = ['driver' => 'mysql', 'prefix' => 'prefix', 'database' => 'database', 'name' => 'foo'];
1515
$this->mysqlConnection = new MysqlConnection(new PDOStub(), 'database', 'prefix', $mysqlConfig);

0 commit comments

Comments
 (0)