-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[11.x] Supports laravel/serializable-closure
2
#53552
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
cd3706e
[11.x] Supports `laravel/serializable-closure` 2
crynobone e7bd462
Apply fixes from StyleCI
StyleCIBot 4a94170
wip
crynobone d3e7371
wip
crynobone 9ba37ae
wip
crynobone 24bf692
Apply fixes from StyleCI
StyleCIBot 268cc1d
wip
crynobone f0bb1e5
Merge remote-tracking branch 'upstream/serializable-closure-2' into s…
crynobone 08f644d
wip
crynobone cc5e56e
Apply fixes from StyleCI
StyleCIBot 0a8cac8
wip
crynobone 0f7b106
wip
crynobone e39f526
wip
crynobone 3926779
wip
crynobone 1e1d2d5
wip
crynobone ba80144
wip
crynobone 5319978
wip
crynobone 43f218b
Apply fixes from StyleCI
StyleCIBot fda9eea
Update SerializableClosureV1QueueTest.php
crynobone 31a41b9
Merge branch '11.x' into serializable-closure-2
crynobone 4c09f62
wip
crynobone 3ca0a75
Apply suggestions from code review
crynobone e38a7b8
wip
crynobone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Queue\Fixtures\Jobs; | ||
|
||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Auth\User; | ||
use Illuminate\Foundation\Queue\Queueable; | ||
|
||
class DeleteUser implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* Create a new job instance. | ||
*/ | ||
public function __construct( | ||
public User $user | ||
) { | ||
log($user); | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
$this->user->delete(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
tests/Integration/Queue/SerializableClosureV1QueueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Queue; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\DB; | ||
use Orchestra\Testbench\Attributes\WithMigration; | ||
use Orchestra\Testbench\Factories\UserFactory; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
#[WithMigration] | ||
class SerializableClosureV1QueueTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** {@inheritDoc} */ | ||
#[\Override] | ||
protected function defineEnvironment($app) | ||
{ | ||
$this->markTestSkippedWhen($this->usingInMemoryDatabase(), 'Test does not support using :memory: database connection'); | ||
|
||
tap($app->make('config'), function ($config) { | ||
$config->set([ | ||
'app.key' => 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF', | ||
'queue.default' => 'database', | ||
]); | ||
}); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
protected function afterRefreshingDatabase() | ||
{ | ||
UserFactory::new()->create([ | ||
'id' => 100, | ||
'name' => 'Taylor Otwell', | ||
'email' => 'taylor@laravel.com', | ||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', | ||
]); | ||
|
||
DB::table('jobs')->insert([ | ||
'queue' => 'default', | ||
'payload' => "{\"uuid\":\"d7c0856d-733a-4e73-89c8-eca4dea621ff\",\"displayName\":\"Illuminate\\\\Tests\\\\Integration\\\\Queue\\\\Fixtures\\\\Jobs\\\\DeleteUser\",\"job\":\"Illuminate\\\\Queue\\\\CallQueuedHandler@call\",\"maxTries\":null,\"maxExceptions\":null,\"failOnTimeout\":false,\"backoff\":null,\"timeout\":null,\"retryUntil\":null,\"data\":{\"commandName\":\"Illuminate\\\\Tests\\\\Integration\\\\Queue\\\\Fixtures\\\\Jobs\\\\DeleteUser\",\"command\":\"O:59:\\\"Illuminate\\\\Tests\\\\Integration\\\\Queue\\\\Fixtures\\\\Jobs\\\\DeleteUser\\\":3:{s:4:\\\"user\\\";O:45:\\\"Illuminate\\\\Contracts\\\\Database\\\\ModelIdentifier\\\":5:{s:5:\\\"class\\\";s:31:\\\"Illuminate\\\\Foundation\\\\Auth\\\\User\\\";s:2:\\\"id\\\";i:100;s:9:\\\"relations\\\";a:0:{}s:10:\\\"connection\\\";s:6:\\\"sqlite\\\";s:15:\\\"collectionClass\\\";N;}s:7:\\\"chained\\\";a:1:{i:0;s:571:\\\"O:34:\\\"Illuminate\\\\Queue\\\\CallQueuedClosure\\\":1:{s:7:\\\"closure\\\";O:47:\\\"Laravel\\\\SerializableClosure\\\\SerializableClosure\\\":1:{s:12:\\\"serializable\\\";O:46:\\\"Laravel\\\\SerializableClosure\\\\Serializers\\\\Signed\\\":2:{s:12:\\\"serializable\\\";s:282:\\\"O:46:\\\"Laravel\\\\SerializableClosure\\\\Serializers\\\\Native\\\":5:{s:3:\\\"use\\\";a:0:{}s:8:\\\"function\\\";s:57:\\\"function () {\\n \\\\info('Hello world');\\n }\\\";s:5:\\\"scope\\\";s:44:\\\"Illuminate\\\\Foundation\\\\Console\\\\ClosureCommand\\\";s:4:\\\"this\\\";N;s:4:\\\"self\\\";s:32:\\\"000000000000021e0000000000000000\\\";}\\\";s:4:\\\"hash\\\";s:44:\\\"VGMlRmFr2\\/U1E8lksExnzODwffyWR8oD01WOcQ2SUjE=\\\";}}}\\\";}s:19:\\\"chainCatchCallbacks\\\";a:1:{i:0;O:47:\\\"Laravel\\\\SerializableClosure\\\\SerializableClosure\\\":1:{s:12:\\\"serializable\\\";O:46:\\\"Laravel\\\\SerializableClosure\\\\Serializers\\\\Signed\\\":2:{s:12:\\\"serializable\\\";s:309:\\\"O:46:\\\"Laravel\\\\SerializableClosure\\\\Serializers\\\\Native\\\":5:{s:3:\\\"use\\\";a:0:{}s:8:\\\"function\\\";s:84:\\\"function (\\\\Throwable \$e) {\\n \\\\Illuminate\\\\Support\\\\Facades\\\\Log::error(\$e);\\n }\\\";s:5:\\\"scope\\\";s:44:\\\"Illuminate\\\\Foundation\\\\Console\\\\ClosureCommand\\\";s:4:\\\"this\\\";N;s:4:\\\"self\\\";s:32:\\\"00000000000002380000000000000000\\\";}\\\";s:4:\\\"hash\\\";s:44:\\\"RBSD4RFLgmKL9WJEGY66aeZtWDkX\\/aY1J+MJ8LQSYi4=\\\";}}}}\"}}", | ||
'attempts' => 0, | ||
'available_at' => 1731919764, | ||
'created_at' => 1731919764, | ||
]); | ||
} | ||
|
||
public function testItCanProcessQueueFromSerializableClosureV1() | ||
{ | ||
$this->assertDatabaseHas('users', [ | ||
'name' => 'Taylor Otwell', | ||
'email' => 'taylor@laravel.com', | ||
]); | ||
|
||
$this->artisan('queue:work', [ | ||
'connection' => 'database', | ||
'--stop-when-empty' => true, | ||
'--memory' => 1024, | ||
])->assertExitCode(0); | ||
|
||
$this->assertDatabaseMissing('users', [ | ||
'name' => 'Taylor Otwell', | ||
'email' => 'taylor@laravel.com', | ||
]); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
tests/Integration/Routing/SerializableClosureV1CacheRouteTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Route; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Orchestra\Testbench\Attributes\WithConfig; | ||
use Orchestra\Testbench\Attributes\WithMigration; | ||
use Orchestra\Testbench\Factories\UserFactory; | ||
use Orchestra\Testbench\TestCase; | ||
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily; | ||
|
||
use function Illuminate\Filesystem\join_paths; | ||
|
||
#[RequiresOperatingSystemFamily('Linux|Darwin')] | ||
#[WithConfig('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF')] | ||
#[WithMigration] | ||
class SerializableClosureV1CacheRouteTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** {@inheritDoc} */ | ||
#[\Override] | ||
protected function getPackageProviders($app) | ||
{ | ||
return [ | ||
\Illuminate\Foundation\Support\Providers\RouteServiceProvider::class, | ||
]; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
#[\Override] | ||
protected function setUp(): void | ||
{ | ||
$_ENV['APP_ROUTES_CACHE'] = realpath(join_paths(__DIR__, 'stubs', 'serializable-closure-v1', 'routes-v7.php')); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
#[\Override] | ||
protected function tearDown(): void | ||
{ | ||
unset($_ENV['APP_ROUTES_CACHE']); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
public function testItCanUseCachedRouteFromSerializableClosureV1() | ||
{ | ||
$user = UserFactory::new()->create(); | ||
|
||
$this->assertTrue($this->app->routesAreCached()); | ||
|
||
$this->get('/')->assertSee('Laravel'); | ||
|
||
$this->get("/users/{$user->getKey()}") | ||
->assertJson($user->toArray()); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
tests/Integration/Routing/stubs/serializable-closure-v1/routes-v7.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
app('router')->setCompiledRoutes( | ||
[ | ||
'compiled' => [ | ||
0 => false, | ||
1 => [ | ||
'/' => [ | ||
0 => [ | ||
0 => [ | ||
'_route' => 'generated::7CFionvE02fEbBNP', | ||
], | ||
1 => null, | ||
2 => [ | ||
'GET' => 0, | ||
'HEAD' => 1, | ||
], | ||
3 => null, | ||
4 => false, | ||
5 => false, | ||
6 => null, | ||
], | ||
], | ||
], | ||
2 => [ | ||
0 => '{^(?|/users/([^/]++)(*:22))/?$}sDu', | ||
], | ||
3 => [ | ||
22 => [ | ||
0 => [ | ||
0 => [ | ||
'_route' => 'generated::YmZUvOCRFrqhC2sO', | ||
], | ||
1 => [ | ||
0 => 'user', | ||
], | ||
2 => [ | ||
'GET' => 0, | ||
'HEAD' => 1, | ||
], | ||
3 => null, | ||
4 => false, | ||
5 => true, | ||
6 => null, | ||
], | ||
1 => [ | ||
0 => null, | ||
1 => null, | ||
2 => null, | ||
3 => null, | ||
4 => false, | ||
5 => false, | ||
6 => 0, | ||
], | ||
], | ||
], | ||
4 => null, | ||
], | ||
'attributes' => [ | ||
'generated::7CFionvE02fEbBNP' => [ | ||
'methods' => [ | ||
0 => 'GET', | ||
1 => 'HEAD', | ||
], | ||
'uri' => '/', | ||
'action' => [ | ||
'middleware' => [ | ||
0 => 'web', | ||
], | ||
'uses' => 'O:55:"Laravel\\SerializableClosure\\UnsignedSerializableClosure":1:{s:12:"serializable";O:46:"Laravel\\SerializableClosure\\Serializers\\Native":5:{s:3:"use";a:0:{}s:8:"function";s:44:"function () { | ||
return \\view(\'welcome\'); | ||
}";s:5:"scope";s:37:"Illuminate\\Routing\\RouteFileRegistrar";s:4:"this";N;s:4:"self";s:32:"00000000000002f00000000000000000";}}', | ||
'namespace' => null, | ||
'prefix' => '', | ||
'where' => [ | ||
], | ||
'as' => 'generated::7CFionvE02fEbBNP', | ||
], | ||
'fallback' => false, | ||
'defaults' => [ | ||
], | ||
'wheres' => [ | ||
], | ||
'bindingFields' => [ | ||
], | ||
'lockSeconds' => null, | ||
'waitSeconds' => null, | ||
'withTrashed' => false, | ||
], | ||
'generated::YmZUvOCRFrqhC2sO' => [ | ||
'methods' => [ | ||
0 => 'GET', | ||
1 => 'HEAD', | ||
], | ||
'uri' => 'users/{user}', | ||
'action' => [ | ||
'middleware' => [ | ||
0 => 'web', | ||
], | ||
'uses' => 'O:55:"Laravel\\SerializableClosure\\UnsignedSerializableClosure":1:{s:12:"serializable";O:46:"Laravel\\SerializableClosure\\Serializers\\Native":5:{s:3:"use";a:0:{}s:8:"function";s:52:"fn (\\Illuminate\\Foundation\\Auth\\User $user) => $user";s:5:"scope";s:37:"Illuminate\\Routing\\RouteFileRegistrar";s:4:"this";N;s:4:"self";s:32:"00000000000002f20000000000000000";}}', | ||
'namespace' => null, | ||
'prefix' => '', | ||
'where' => [ | ||
], | ||
'as' => 'generated::YmZUvOCRFrqhC2sO', | ||
], | ||
'fallback' => false, | ||
'defaults' => [ | ||
], | ||
'wheres' => [ | ||
], | ||
'bindingFields' => [ | ||
], | ||
'lockSeconds' => null, | ||
'waitSeconds' => null, | ||
'withTrashed' => false, | ||
], | ||
], | ||
] | ||
); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending
laravel/serializable-closure
v2 release