Skip to content

Commit

Permalink
adds test
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmastech committed Dec 5, 2024
1 parent a60ee0f commit 114a1ec
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,39 @@ public static function fromRequest(Request $request)
->assertJson(['name' => 'Rick Astley']);
}
);

it('can build authorize parameters from the container', function (): void {
class SomeDependency
{
public function __construct(public string $street)
{
}
}

app()->bind(SomeDependency::class, fn () => new SomeDependency('Sesame'));
class AuthorizeFromContainerRequest extends Data
{
public static string $street;

public function __construct(public string $name)
{
}

public static function authorize(SomeDependency $dependency): bool
{
self::$street = $dependency->street;

return $dependency->street === 'Sesame';
}
}

Route::post('/route-with-authorization-dependencies', function (\AuthorizeFromContainerRequest $data) {
return ['name' => $data->name, 'street' => \AuthorizeFromContainerRequest::$street];
});

postJson('/route-with-authorization-dependencies', [
'name' => 'Rick Astley',
])
->assertOk()
->assertJson(['name' => 'Rick Astley', 'street' => 'Sesame']);
});

0 comments on commit 114a1ec

Please sign in to comment.