Skip to content

Commit ef71a03

Browse files
authored
Merge pull request #129 from joshhanley/josh/laravel-13-support
Add Laravel 13 support
2 parents bf18497 + e7ccdf1 commit ef71a03

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
php: [7.1, 7.2, 7.3, 7.4, '8.0', 8.1, 8.2, 8.3, 8.4]
18-
laravel: [5.8.*, 6.*, 7.*, 8.*, 9.*, 10.*, 11.*, 12.*]
18+
laravel: [5.8.*, 6.*, 7.*, 8.*, 9.*, 10.*, 11.*, 12.*, 13.*]
1919
os: [ubuntu-latest]
2020
include:
21+
- laravel: 13.*
22+
testbench: 11.*
2123
- laravel: 12.*
2224
testbench: 10.*
2325
- laravel: 11.*
@@ -127,6 +129,20 @@ jobs:
127129
php: '8.0'
128130
- laravel: 12.*
129131
php: '8.1'
132+
- laravel: 13.*
133+
php: 7.1
134+
- laravel: 13.*
135+
php: 7.2
136+
- laravel: 13.*
137+
php: 7.3
138+
- laravel: 13.*
139+
php: 7.4
140+
- laravel: 13.*
141+
php: '8.0'
142+
- laravel: 13.*
143+
php: '8.1'
144+
- laravel: 13.*
145+
php: 8.2
130146

131147
name: PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }}
132148

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"php": "^7.1.3|^8.0",
1313
"ext-pdo_sqlite": "*",
1414
"ext-sqlite3": "*",
15-
"illuminate/database": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0",
16-
"illuminate/support": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0"
15+
"illuminate/database": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0",
16+
"illuminate/support": "^5.8 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0"
1717
},
1818
"require-dev": {
1919
"doctrine/dbal": "^2.9 || ^3.1.4",
20-
"orchestra/testbench": "3.8.* || 3.9.* || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
21-
"phpunit/phpunit": "^7.5 || ^8.4 || ^9.0 || ^10.0 || ^11.0"
20+
"orchestra/testbench": "3.8.* || 3.9.* || ^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0",
21+
"phpunit/phpunit": "^7.5 || ^8.4 || ^9.0 || ^10.0 || ^11.0 || ^12.5"
2222
},
2323
"autoload": {
2424
"psr-4": {

src/Sushi.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,26 @@ protected function sushiCacheDirectory()
5757

5858
public static function bootSushi()
5959
{
60-
$instance = (new static);
60+
// Laravel 13 (laravel/framework#55685) throws a LogicException if a new
61+
// model instance is created while the model is still booting (i.e.
62+
// during a boot* trait method). Since Sushi needs to create an instance
63+
// to configure its SQLite connection, we defer that work until after
64+
// booting has finished using the "whenBooted" method, which was added
65+
// in Laravel 12.8 (laravel/framework#55286). For older Laravel versions
66+
// we call it directly since there is no re-entrancy guard and the
67+
// original behaviour works fine.
68+
if (method_exists(static::class, 'whenBooted')) {
69+
static::whenBooted(function () {
70+
static::configureSushiConnection();
71+
});
72+
} else {
73+
static::configureSushiConnection();
74+
}
75+
}
76+
77+
protected static function configureSushiConnection()
78+
{
79+
$instance = new static;
6180

6281
$cachePath = $instance->sushiCachePath();
6382
$dataPath = $instance->sushiCacheReferencePath();

tests/SushiTest.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public function tearDown(): void
3939
parent::tearDown();
4040
}
4141

42-
/** @test */
43-
function basic_usage()
42+
function test_basic_usage()
4443
{
4544
$this->assertEquals(3, Foo::count());
4645
$this->assertEquals('bar', Foo::first()->foo);
@@ -50,8 +49,7 @@ function basic_usage()
5049
$this->assertEquals('lob', Bar::whereBob('lob')->first()->bob);
5150
}
5251

53-
/** @test */
54-
function columns_with_varying_types()
52+
function test_columns_with_varying_types()
5553
{
5654
$row = ModelWithVaryingTypeColumns::first();
5755
$connectionBuilder = ModelWithVaryingTypeColumns::resolveConnection()->getSchemaBuilder();
@@ -65,8 +63,7 @@ function_exists('\Orchestra\Testbench\laravel_version_compare') && laravel_versi
6563
$this->assertEquals(null, $row->null);
6664
}
6765

68-
/** @test */
69-
function model_with_custom_schema()
66+
function test_model_with_custom_schema()
7067
{
7168
ModelWithCustomSchema::count();
7269
$connectionBuilder = ModelWithCustomSchema::resolveConnection()->getSchemaBuilder();
@@ -80,17 +77,15 @@ function_exists('\Orchestra\Testbench\laravel_version_compare') && laravel_versi
8077
);
8178
}
8279

83-
/** @test */
84-
function models_using_the_get_rows_property_arent_cached()
80+
function test_models_using_the_get_rows_property_arent_cached()
8581
{
8682
Bar::$hasBeenAccessedBefore = false;
8783
$this->assertEquals(2, Bar::count());
8884
Bar::resetStatics();
8985
$this->assertEquals(3, Bar::count());
9086
}
9187

92-
/** @test */
93-
function uses_in_memory_if_the_cache_directory_is_not_writeable_or_not_found()
88+
function test_uses_in_memory_if_the_cache_directory_is_not_writeable_or_not_found()
9489
{
9590
config(['sushi.cache-path' => $path = __DIR__ . '/non-existant-path']);
9691

@@ -100,8 +95,7 @@ function uses_in_memory_if_the_cache_directory_is_not_writeable_or_not_found()
10095
$this->assertEquals(':memory:', (new Foo)->getConnection()->getDatabaseName());
10196
}
10297

103-
/** @test */
104-
function caches_sqlite_file_if_storage_cache_folder_is_available()
98+
function test_caches_sqlite_file_if_storage_cache_folder_is_available()
10599
{
106100
Foo::count();
107101

@@ -112,8 +106,7 @@ function caches_sqlite_file_if_storage_cache_folder_is_available()
112106
);
113107
}
114108

115-
/** @test */
116-
function avoids_error_when_creating_database_concurrently()
109+
function test_avoids_error_when_creating_database_concurrently()
117110
{
118111
$actualFactory = app(ConnectionFactory::class);
119112
$actualConnection = $actualFactory->make([
@@ -144,30 +137,26 @@ function avoids_error_when_creating_database_concurrently()
144137
}
145138

146139
/**
147-
* @test
148140
* @group skipped
149-
* */
150-
function uses_same_cache_between_requests()
141+
*/
142+
function test_uses_same_cache_between_requests()
151143
{
152144
$this->markTestSkipped("I can't find a good way to test this right now.");
153145
}
154146

155-
/** @test */
156-
function adds_primary_key_if_needed()
147+
function test_adds_primary_key_if_needed()
157148
{
158149
$this->assertEquals([5,6], ModelWithNonStandardKeys::orderBy('id')->pluck('id')->toArray());
159150
$this->assertEquals(1, Foo::find(1)->getKey());
160151
}
161152

162153

163-
/** @test */
164-
function it_returns_an_empty_collection()
154+
function test_it_returns_an_empty_collection()
165155
{
166156
$this->assertEquals(0, Blank::count());
167157
}
168158

169-
/** @test */
170-
function can_use_exists_validation_rule()
159+
function test_can_use_exists_validation_rule()
171160
{
172161
ModelWithNonStandardKeys::all();
173162
Foo::all();
@@ -185,22 +174,15 @@ function can_use_exists_validation_rule()
185174
: $this->assertFalse(Validator::make(['bob' => 'ble'], ['bob' => 'exists:'.ModelWithNonStandardKeys::class.'.model_with_non_standard_keys'])->passes());
186175
}
187176

188-
/** @test */
189-
public function it_runs_method_after_migration_when_defined()
177+
public function test_it_runs_method_after_migration_when_defined()
190178
{
191179
$model = ModelWithAddedTableOperations::all();
192180
$this->assertEquals('columnWasAdded', $model->first()->columnAdded, 'The runAfterMigrating method was not triggered.');
193181
}
194182

195-
/**
196-
* @test
197-
* @define-env usesSqliteConnection
198-
* */
199-
function sushi_models_can_relate_to_models_in_regular_sqlite_databases()
183+
function test_sushi_models_can_relate_to_models_in_regular_sqlite_databases()
200184
{
201-
if (! trait_exists('\Orchestra\Testbench\Concerns\HandlesAnnotations')) {
202-
$this->markTestSkipped('Requires HandlesAnnotation trait to define sqlite connection using PHPUnit annotation');
203-
}
185+
$this->usesSqliteConnection($this->app);
204186

205187
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
206188
$this->artisan('migrate', ['--database' => 'testbench-sqlite'])->run();

0 commit comments

Comments
 (0)