Skip to content

Commit

Permalink
Merge pull request #665 from ejunker/main
Browse files Browse the repository at this point in the history
Prevent out of memory with multiple requests in a test
  • Loading branch information
rubenvanassche authored Feb 14, 2024
2 parents 22fdbda + d44f7e8 commit 15ca3ac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/LaravelDataServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function () {
);

$this->app->beforeResolving(BaseData::class, function ($class, $parameters, $app) {
if ($app->has($class)) {
return;
}

$app->bind(
$class,
fn ($container) => $class::from($container['request'])
Expand Down
14 changes: 13 additions & 1 deletion tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ValidationException::class,
]);

Route::post('/example-route', function (Sim $data) {
Route::post('/example-route', function (SimpleData $data) {
return ['given' => $data->string];
});
});
Expand All @@ -38,6 +38,18 @@
->assertJson(['given' => 'Hello']);
});

it('can make multiple requests', function () {
postJson('/example-route', [
'string' => 'Hello',
])
->assertOk();

postJson('/example-route', [
'string' => 'Hello',
])
->assertOk();
});

it('can returns a 201 response code for POST requests', function () {
Route::post('/example-route', function () {
return new SimpleData(request()->input('string'));
Expand Down

0 comments on commit 15ca3ac

Please sign in to comment.