Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Feb 14, 2024
1 parent 4838990 commit 1588650
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
19 changes: 19 additions & 0 deletions tests/CreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;
use Illuminate\Support\Facades\Route;
use Illuminate\Validation\ValidationException;

use function Pest\Laravel\postJson;

use Spatie\LaravelData\Attributes\Computed;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\Attributes\Validation\Min;
Expand Down Expand Up @@ -917,3 +921,18 @@ public function __construct(public string $string)

expect($data->items)->toEqual(collect(['Well, hello this cast is used!']));
});

it('can inject a data object in a controller', function () {
class TestControllerDataInjection
{
public function __invoke(SimpleData $data)
{
return response('ok');
}
}

Route::post('test', TestControllerDataInjection::class);

postJson(action(TestControllerDataInjection::class), ['string' => 'Hello World'])->assertOk();
postJson(action(TestControllerDataInjection::class), ['string' => 'Hello World'])->assertOk(); // caused an infinite loop once
});
12 changes: 0 additions & 12 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@
->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 1588650

Please sign in to comment.