Skip to content

Commit 437754f

Browse files
authored
Merge pull request #101 from mikebronner/feat/99-add-laravel-13-support
feat(compat): Add Laravel 13 support
2 parents 9d25b0c + 1322ee2 commit 437754f

File tree

21 files changed

+234
-99
lines changed

21 files changed

+234
-99
lines changed

.github/workflows/tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php: ['8.2', '8.3', '8.4', '8.5']
17+
laravel: ['11.*', '12.*', '13.*']
18+
exclude:
19+
- php: '8.5'
20+
laravel: '11.*'
21+
- php: '8.2'
22+
laravel: '13.*'
23+
include:
24+
- laravel: '11.*'
25+
testbench: '9.*'
26+
- laravel: '12.*'
27+
testbench: '10.*'
28+
- laravel: '13.*'
29+
testbench: '11.*'
30+
31+
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
32+
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v4
36+
37+
- name: Setup PHP
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: ${{ matrix.php }}
41+
extensions: mbstring, pdo, pdo_sqlite
42+
coverage: none
43+
44+
- name: Install dependencies
45+
run: |
46+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
47+
composer update --prefer-dist --no-interaction
48+
49+
- name: Run tests
50+
run: vendor/bin/phpunit

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ Provide a simple method of managing ACL in a Laravel application built on the
1818
for Laravel.
1919

2020
## Requirements
21-
- PHP >=7.1.3
22-
- Laravel >= 5.5
21+
22+
| Laravel | PHP | Package |
23+
|---------|----------------|---------|
24+
| 10.x | 8.2+ | latest |
25+
| 11.x | 8.2+ | latest |
26+
| 12.x | 8.2+ | latest |
27+
| 13.x | 8.3+ | latest |
28+
29+
### Additional Requirements
2330
- Bootstrap 3 (needs to be included in your layout file)
2431
- FontAwesome 4 (needs to be included in your layout file)
2532

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
}
1010
],
1111
"require": {
12-
"illuminate/database": "^9.0|^10.0|^11.0|^12.0",
13-
"illuminate/support": "^9.0|^10.0|^11.0|^12.0",
14-
"php": "^7.3|^8.0",
12+
"php": "^8.2",
13+
"illuminate/database": "^11.0|^12.0|^13.0",
14+
"illuminate/support": "^11.0|^12.0|^13.0",
1515
"ramsey/uuid": "^4.0"
1616
},
1717
"require-dev": {
18-
"doctrine/dbal": "^2.9",
18+
"doctrine/dbal": "^3.0|^4.0",
1919
"fakerphp/faker": "^1.23",
20-
"laravel/legacy-factories": "^1.0",
21-
"orchestra/testbench": "^7.0|^8.0|^9.0|^10.0",
22-
"phpunit/phpunit": "^9.5|^10.0|^11.0",
20+
"orchestra/testbench": "^9.0|^10.0|^11.0",
21+
"phpunit/phpunit": "^10.0|^11.0|^12.0",
2322
"symfony/thanks": "^1.2"
2423
},
2524
"autoload": {
@@ -38,6 +37,7 @@
3837
],
3938
"psr-4": {
4039
"GeneaLabs\\LaravelGovernor\\Tests\\": "tests/",
40+
"GeneaLabs\\LaravelGovernor\\Tests\\Database\\Factories\\": "tests/database/factories/",
4141
"App\\": "tests/Fixtures/App/"
4242
}
4343
},

phpunit.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
backupGlobals="false"
4-
backupStaticAttributes="false"
54
bootstrap="vendor/autoload.php"
65
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
106
processIsolation="false"
117
stopOnFailure="true"
12-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
8+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.0/phpunit.xsd"
139
>
14-
<coverage processUncoveredFiles="true">
10+
<source>
1511
<include>
1612
<directory suffix=".php">./src</directory>
1713
</include>
18-
</coverage>
14+
</source>
1915
<testsuites>
2016
<testsuite name="Setup">
21-
<directory>./tests/AlwaysRunFirstTest.php</directory>
17+
<file>./tests/AlwaysRunFirstTest.php</file>
2218
</testsuite>
2319
<testsuite name="IntegrationTests">
2420
<directory suffix="Test.php">./tests/Integration</directory>

tests/AlwaysRunFirstTest.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<?php namespace GeneaLabs\LaravelGovernor\Tests;
22

3-
use Orchestra\Testbench\TestCase as BaseTestCase;
4-
use GeneaLabs\LaravelGovernor\Tests\Fixtures\User;
53
use GeneaLabs\LaravelGovernor\Database\Seeders\LaravelGovernorDatabaseSeeder;
4+
use GeneaLabs\LaravelGovernor\Tests\Fixtures\User;
5+
use Orchestra\Testbench\TestCase as BaseTestCase;
6+
use PHPUnit\Framework\Attributes\Test;
67

78
class AlwaysRunFirstTest extends BaseTestCase
89
{
@@ -18,54 +19,56 @@ protected function getPackageProviders($app)
1819

1920
protected function getEnvironmentSetUp($app)
2021
{
21-
parent::getEnvironmentSetUp($app);
22+
$sqliteDatabase = __DIR__ . '/database/database.sqlite';
2223

23-
shell_exec("cd " . __DIR__ . "/database && rm *.sqlite && touch database.sqlite");
24+
if (file_exists($sqliteDatabase)) {
25+
unlink($sqliteDatabase);
26+
}
27+
touch($sqliteDatabase);
2428

2529
$app['config']->set('genealabs-laravel-governor.models', [
26-
'auth' => User::class,
27-
'action' => \GeneaLabs\LaravelGovernor\Action::class,
30+
'auth' => User::class,
31+
'action' => \GeneaLabs\LaravelGovernor\Action::class,
2832
'assignment' => \GeneaLabs\LaravelGovernor\Assignment::class,
29-
'entity' => \GeneaLabs\LaravelGovernor\Entity::class,
30-
'group' => \GeneaLabs\LaravelGovernor\Group::class,
31-
'ownership' => \GeneaLabs\LaravelGovernor\Ownership::class,
33+
'entity' => \GeneaLabs\LaravelGovernor\Entity::class,
34+
'group' => \GeneaLabs\LaravelGovernor\Group::class,
35+
'ownership' => \GeneaLabs\LaravelGovernor\Ownership::class,
3236
'permission' => \GeneaLabs\LaravelGovernor\Permission::class,
33-
'role' => \GeneaLabs\LaravelGovernor\Role::class,
34-
'team' => \GeneaLabs\LaravelGovernor\Team::class,
37+
'role' => \GeneaLabs\LaravelGovernor\Role::class,
38+
'team' => \GeneaLabs\LaravelGovernor\Team::class,
3539
'invitation' => \GeneaLabs\LaravelGovernor\TeamInvitation::class,
3640
]);
3741
$app['config']->set('database.default', 'sqlite');
3842
$app['config']->set('database.connections.sqlite', [
39-
'driver' => 'sqlite',
40-
"url" => null,
41-
'database' => __DIR__ . '/database/database.sqlite',
42-
'prefix' => '',
43-
"foreign_key_constraints" => false,
43+
'driver' => 'sqlite',
44+
'url' => null,
45+
'database' => $sqliteDatabase,
46+
'prefix' => '',
47+
'foreign_key_constraints' => false,
4448
]);
4549
}
4650

47-
public function setUp() : void
51+
public function setUp(): void
4852
{
4953
parent::setUp();
5054

51-
$this->loadLaravelMigrations();
52-
$this->loadMigrationsFrom(__DIR__ . "/../database/migrations");
53-
$this->loadMigrationsFrom(__DIR__ . "/database/migrations");
55+
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
56+
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
5457
$this->artisan('migrate');
5558
$this->artisan('db:seed', [
56-
"--database" => "sqlite",
57-
'--class' => LaravelGovernorDatabaseSeeder::class,
59+
'--database' => 'sqlite',
60+
'--class' => LaravelGovernorDatabaseSeeder::class,
5861
'--no-interaction' => true,
5962
]);
6063
}
6164

62-
public function tearDown() : void
65+
public function tearDown(): void
6366
{
64-
$this->app['config']->set('database.default', 'testing');
67+
parent::tearDown();
6568
}
6669

67-
/** @test */
68-
public function migrateAndInstallTheDatabase()
70+
#[Test]
71+
public function testMigrateAndInstallTheDatabase(): void
6972
{
7073
$this->assertTrue(true);
7174
}

tests/CreatesApplication.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,8 @@ protected function setUp(): void
4141
{
4242
parent::setUp();
4343

44-
$this->withFactories(__DIR__ . "/database/factories");
45-
$this->loadLaravelMigrations();
46-
$this->loadMigrationsFrom(__DIR__ . "/../database/migrations");
4744
$this->loadMigrationsFrom(__DIR__ . "/database/migrations");
45+
$this->loadMigrationsFrom(__DIR__ . "/../database/migrations");
4846
$this->artisan('migrate');
4947
$this->artisan('db:seed', [
5048
'--class' => LaravelGovernorDatabaseSeeder::class,

tests/Fixtures/Author.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<?php namespace GeneaLabs\LaravelGovernor\Tests\Fixtures;
22

3+
use GeneaLabs\LaravelGovernor\Tests\Database\Factories\AuthorFactory;
34
use GeneaLabs\LaravelGovernor\Traits\Governable;
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
46
use Illuminate\Database\Eloquent\Model;
57

68
class Author extends Model
79
{
810
use Governable;
11+
use HasFactory;
912

1013
protected $fillable = [
1114
"name",
1215
];
13-
}
16+
17+
protected static function newFactory(): AuthorFactory
18+
{
19+
return AuthorFactory::new();
20+
}
21+
}

tests/Fixtures/User.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?php namespace GeneaLabs\LaravelGovernor\Tests\Fixtures;
22

3+
use GeneaLabs\LaravelGovernor\Tests\Database\Factories\UserFactory;
34
use GeneaLabs\LaravelGovernor\Traits\Governing;
45
use Illuminate\Contracts\Auth\MustVerifyEmail;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
57
use Illuminate\Foundation\Auth\User as Authenticatable;
68
use Illuminate\Notifications\Notifiable;
79

810
class User extends Authenticatable implements MustVerifyEmail
911
{
1012
use Governing;
13+
use HasFactory;
1114
use Notifiable;
1215

1316
protected $fillable = [
@@ -20,4 +23,9 @@ class User extends Authenticatable implements MustVerifyEmail
2023
"remember_token",
2124
"activation_token",
2225
];
23-
}
26+
27+
protected static function newFactory(): UserFactory
28+
{
29+
return UserFactory::new();
30+
}
31+
}

tests/Integration/Notifications/TeamInvitationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setUp() : void
1414
{
1515
parent::setUp();
1616

17-
$this->user = factory(User::class)->create();
17+
$this->user = User::factory()->create();
1818
$this->actingAs($this->user);
1919
$this->team = (new Team)->create([
2020
"name" => "Test Team",

tests/Integration/Policies/BasePolicyTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ public function setUp(): void
1919
{
2020
parent::setUp();
2121

22-
$this->userWithoutRoles = factory(User::class)->create();
22+
$this->userWithoutRoles = User::factory()->create();
2323
$this->userWithoutRoles->roles()->sync([]);
2424
$this->userWithoutRoles->teams()->sync([]);
25-
$this->otherUser = factory(User::class)->create();
25+
$this->otherUser = User::factory()->create();
2626
$this->otherUser->roles()->attach("SuperAdmin");
2727
$this->actingAs($this->otherUser);
2828
$this->otherTeam = (new Team)->create([
2929
"name" => "Test Team",
3030
"description" => "bla bla bla",
3131
]);
32-
$this->otherAuthor = factory(Author::class)->create();
32+
$this->otherAuthor = Author::factory()->create();
3333
$this->otherAuthor->teams()->attach($this->otherTeam);
3434

35-
$this->user = factory(User::class)->create();
35+
$this->user = User::factory()->create();
3636
$this->actingAs($this->user);
3737
$this->team = (new Team)->create([
3838
"name" => "Test Team",
3939
"description" => "bla bla bla",
4040
]);
41-
$this->author = factory(Author::class)->create();
41+
$this->author = Author::factory()->create();
4242
$this->author->teams()->attach($this->team);
4343
}
4444

0 commit comments

Comments
 (0)