Skip to content

Commit 8cc59de

Browse files
Laravel 12.x Compatibility (#140)
1 parent 8f1fad7 commit 8cc59de

14 files changed

+180
-176
lines changed

.github/workflows/run-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ jobs:
1313
strategy:
1414
fail-fast: true
1515
matrix:
16-
php: [8.3, 8.2]
17-
laravel: ['^11.15']
16+
php: [8.4, 8.3, 8.2]
17+
laravel: ['^12.0']
1818

1919
name: P${{ matrix.php }} - L${{ matrix.laravel }}
2020

2121
services:
2222
mysql:
23-
image: mysql:5.7
23+
image: mysql:8.0
2424
env:
2525
MYSQL_ALLOW_EMPTY_PASSWORD: yes
2626
MYSQL_DATABASE: model_uuid
@@ -43,6 +43,7 @@ jobs:
4343
id: composer-cache
4444
run: |
4545
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
46+
4647
- uses: actions/cache@v3
4748
with:
4849
path: ${{ steps.composer-cache.outputs.dir }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
composer.lock
33
phpunit.xml
44
.phpunit.cache
5+
pint.cache

composer.json

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
{
2-
"name": "dyrynda/laravel-model-uuid",
3-
"description": "This package allows you to easily work with UUIDs in your Laravel models.",
4-
"license": "MIT",
5-
"keywords": [
6-
"eloquent",
7-
"laravel",
8-
"model",
9-
"uuid"
10-
],
11-
"authors": [
12-
{
13-
"name": "Michael Dyrynda",
14-
"email": "michael@dyrynda.com.au",
15-
"homepage": "https://dyrynda.com.au"
16-
}
17-
],
18-
"require": {
19-
"php": "^8.2",
20-
"illuminate/container": "^11.15",
21-
"illuminate/contracts": "^11.15",
22-
"illuminate/database": "^11.15",
23-
"illuminate/events": "^11.15",
24-
"illuminate/support": "^11.15",
25-
"ramsey/uuid": "^4.7",
26-
"spatie/laravel-package-tools": "^1.16"
27-
},
28-
"autoload": {
29-
"psr-4": {
30-
"Dyrynda\\Database\\Support\\": "src/"
31-
}
32-
},
33-
"require-dev": {
34-
"laravel/legacy-factories": "^1.3",
35-
"laravel/pint": "1.17.2",
36-
"orchestra/testbench": "^8.0 || ^9.0",
37-
"phpunit/phpunit": "^9.6.0 || ^10.0.7"
38-
},
39-
"autoload-dev": {
40-
"psr-4": {
41-
"Tests\\": "tests/"
42-
}
43-
},
44-
"minimum-stability": "dev",
45-
"prefer-stable": true,
46-
"config": {
47-
"sort-packages": true
2+
"name": "dyrynda/laravel-model-uuid",
3+
"description": "This package allows you to easily work with UUIDs in your Laravel models.",
4+
"license": "MIT",
5+
"keywords": [
6+
"eloquent",
7+
"laravel",
8+
"model",
9+
"uuid"
10+
],
11+
"authors": [
12+
{
13+
"name": "Michael Dyrynda",
14+
"email": "michael@dyrynda.com.au",
15+
"homepage": "https://dyrynda.com.au"
16+
}
17+
],
18+
"require": {
19+
"php": "^8.2",
20+
"illuminate/container": "^12.0",
21+
"illuminate/contracts": "^12.0",
22+
"illuminate/database": "^12.0",
23+
"illuminate/events": "^12.0",
24+
"illuminate/support": "^12.0",
25+
"ramsey/uuid": "^4.7",
26+
"spatie/laravel-package-tools": "^1.19"
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"Dyrynda\\Database\\Support\\": "src/"
31+
}
32+
},
33+
"require-dev": {
34+
"laravel/legacy-factories": "^1.3",
35+
"laravel/pint": "^1.20",
36+
"orchestra/testbench": "^10.0",
37+
"phpunit/phpunit": "^11.5.3"
38+
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"Tests\\": "tests/"
42+
}
43+
},
44+
"minimum-stability": "dev",
45+
"prefer-stable": true,
46+
"config": {
47+
"sort-packages": true
48+
},
49+
"extra": {
50+
"branch-alias": {
51+
"dev-main": "8.x-dev"
4852
},
49-
"extra": {
50-
"branch-alias": {
51-
"dev-main": "8.x-dev"
52-
},
53-
"laravel": {
54-
"providers": [
55-
"Dyrynda\\Database\\Support\\LaravelModelUuidServiceProvider"
56-
]
57-
}
53+
"laravel": {
54+
"providers": [
55+
"Dyrynda\\Database\\Support\\LaravelModelUuidServiceProvider"
56+
]
5857
}
58+
}
5959
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tests\Concerns;
4+
5+
use Illuminate\Database\Connection;
6+
use Mockery as m;
7+
8+
trait MocksDatabaseConnection
9+
{
10+
protected function mockConnection(?string $grammar = null)
11+
{
12+
$connection = m::mock(Connection::class)
13+
->shouldReceive('getTablePrefix')->andReturn('')
14+
->shouldReceive('getConfig')->with('prefix_indexes')->andReturn(true)
15+
->getMock();
16+
17+
$grammar ??= 'MySql';
18+
$grammarClass = "Illuminate\Database\Schema\Grammars\\{$grammar}Grammar";
19+
20+
$connection->shouldReceive('getSchemaGrammar')->andReturn(new $grammarClass($connection));
21+
22+
if ($grammar === 'SQLite') {
23+
$connection->shouldReceive('getServerVersion')->andReturn('3.35');
24+
}
25+
26+
$this->beforeApplicationDestroyed(fn () => m::close());
27+
28+
return $connection;
29+
}
30+
}

tests/Feature/BindUuidTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
use Illuminate\Routing\Middleware\SubstituteBindings;
66
use Illuminate\Support\Facades\Route;
7+
use PHPUnit\Framework\Attributes\Test;
78
use Tests\Fixtures\CustomUuidRouteBoundPost;
89
use Tests\Fixtures\MultipleUuidRouteBoundPost;
910
use Tests\Fixtures\UuidRouteBoundPost;
1011
use Tests\TestCase;
1112

1213
class BindUuidTest extends TestCase
1314
{
14-
/** @test */
15+
#[Test]
1516
public function it_binds_to_default_uuid_field()
1617
{
1718
$post = factory(UuidRouteBoundPost::class)->create();
@@ -24,7 +25,7 @@ public function it_binds_to_default_uuid_field()
2425
$this->get(route('posts.show', $post))->assertSuccessful();
2526
}
2627

27-
/** @test */
28+
#[Test]
2829
public function it_fails_on_invalid_default_uuid_field_value()
2930
{
3031
$post = factory(UuidRouteBoundPost::class)->create();
@@ -37,7 +38,7 @@ public function it_fails_on_invalid_default_uuid_field_value()
3738
$this->get(route('posts.show', $post->custom_uuid))->assertNotFound();
3839
}
3940

40-
/** @test */
41+
#[Test]
4142
public function it_binds_to_custom_uuid_field()
4243
{
4344
$post = factory(CustomUuidRouteBoundPost::class)->create();
@@ -50,7 +51,7 @@ public function it_binds_to_custom_uuid_field()
5051
$this->get(route('posts.show', $post))->assertSuccessful();
5152
}
5253

53-
/** @test */
54+
#[Test]
5455
public function it_fails_on_invalid_custom_uuid_field_value()
5556
{
5657
$post = factory(CustomUuidRouteBoundPost::class)->create();
@@ -63,7 +64,7 @@ public function it_fails_on_invalid_custom_uuid_field_value()
6364
$this->get(route('posts.show', $post->uuid))->assertNotFound();
6465
}
6566

66-
/** @test */
67+
#[Test]
6768
public function it_binds_to_declared_uuid_column_instead_of_default_when_custom_key_used()
6869
{
6970
$post = factory(MultipleUuidRouteBoundPost::class)->create();
@@ -76,7 +77,7 @@ public function it_binds_to_declared_uuid_column_instead_of_default_when_custom_
7677
$this->get(route('posts.show', $post))->assertSuccessful();
7778
}
7879

79-
/** @test */
80+
#[Test]
8081
public function it_fails_on_invalid_uuid_when_custom_route_key_used()
8182
{
8283
$post = factory(MultipleUuidRouteBoundPost::class)->create();

tests/Feature/DatabaseInvalidSchemaGrammarTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@
33
namespace Tests\Feature;
44

55
use Dyrynda\Database\Support\Exceptions\UnknownGrammarClass;
6-
use Illuminate\Database\Connection;
76
use Illuminate\Database\Schema\Blueprint;
8-
use Illuminate\Database\Schema\Grammars\SqlServerGrammar;
9-
use Mockery as m;
7+
use PHPUnit\Framework\Attributes\Test;
8+
use Tests\Concerns\MocksDatabaseConnection;
109
use Tests\TestCase;
1110

1211
class DatabaseInvalidSchemaGrammarTest extends TestCase
1312
{
14-
public function tearDown(): void
15-
{
16-
m::close();
17-
}
13+
use MocksDatabaseConnection;
1814

19-
public function testAddingUuid()
15+
#[Test]
16+
public function test_adding_uuid()
2017
{
21-
$blueprint = new Blueprint('users', function ($table) {
18+
$connection = $this->mockConnection('SqlServer');
19+
20+
$blueprint = new Blueprint($connection, 'users', function ($table) {
2221
$table->uuid('foo');
2322
$table->efficientUuid('bar');
2423
});
2524

26-
$connection = m::mock(Connection::class);
27-
28-
$this->expectExceptionObject(new UnknownGrammarClass);
25+
$this->expectException(UnknownGrammarClass::class);
2926

30-
$blueprint->toSql($connection, new SqlServerGrammar);
27+
$blueprint->toSql();
3128
}
3229
}

tests/Feature/DatabaseMySqlSchemaGrammarTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,26 @@
22

33
namespace Tests\Feature;
44

5-
use Illuminate\Database\Connection;
65
use Illuminate\Database\Schema\Blueprint;
7-
use Illuminate\Database\Schema\Grammars\MySqlGrammar;
8-
use Mockery as m;
6+
use PHPUnit\Framework\Attributes\Test;
7+
use Tests\Concerns\MocksDatabaseConnection;
98
use Tests\TestCase;
109

1110
class DatabaseMySqlSchemaGrammarTest extends TestCase
1211
{
13-
public function tearDown(): void
14-
{
15-
m::close();
16-
}
12+
use MocksDatabaseConnection;
1713

18-
public function testAddingUuid()
14+
#[Test]
15+
public function test_adding_uuid()
1916
{
20-
$blueprint = new Blueprint('users', function ($table) {
17+
$blueprint = new Blueprint($this->mockConnection('MySql'), 'users', function ($table) {
2118
$table->uuid('foo');
2219
$table->efficientUuid('bar');
2320
});
2421

25-
$connection = m::mock(Connection::class);
26-
27-
$this->assertEquals(
28-
[
29-
'alter table `users` add `foo` char(36) not null',
30-
'alter table `users` add `bar` binary(16) not null',
31-
],
32-
$blueprint->toSql($connection, new MySqlGrammar)
33-
);
22+
$this->assertEquals([
23+
'alter table `users` add `foo` char(36) not null',
24+
'alter table `users` add `bar` binary(16) not null',
25+
], $blueprint->toSql());
3426
}
3527
}

tests/Feature/DatabasePostgresSchemaGrammarTest.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,26 @@
22

33
namespace Tests\Feature;
44

5-
use Illuminate\Database\Connection;
65
use Illuminate\Database\Schema\Blueprint;
7-
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
8-
use Mockery as m;
6+
use PHPUnit\Framework\Attributes\Test;
7+
use Tests\Concerns\MocksDatabaseConnection;
98
use Tests\TestCase;
109

1110
class DatabasePostgresSchemaGrammarTest extends TestCase
1211
{
13-
public function tearDown(): void
14-
{
15-
m::close();
16-
}
12+
use MocksDatabaseConnection;
1713

18-
public function testAddingUuid()
14+
#[Test]
15+
public function test_adding_uuid()
1916
{
20-
$blueprint = new Blueprint('users', function ($table) {
17+
$blueprint = new Blueprint($this->mockConnection('Postgres'), 'users', function ($table) {
2118
$table->uuid('foo');
2219
$table->efficientUuid('bar');
2320
});
2421

25-
$connection = m::mock(Connection::class);
26-
27-
$this->assertEquals(
28-
[
29-
'alter table "users" add column "foo" uuid not null',
30-
'alter table "users" add column "bar" bytea not null',
31-
],
32-
$blueprint->toSql($connection, new PostgresGrammar)
33-
);
22+
$this->assertEquals([
23+
'alter table "users" add column "foo" uuid not null',
24+
'alter table "users" add column "bar" bytea not null',
25+
], $blueprint->toSql());
3426
}
3527
}

0 commit comments

Comments
 (0)