Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Aug 23, 2024
1 parent bb6e9de commit 0508b77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
5 changes: 2 additions & 3 deletions src/Contracts/AuthorizationViewResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ interface AuthorizationViewResponse extends Responsable
/**
* Specify the parameters that should be passed to the view.
*
* @param array $parameters
* @return $this
* @param array<string, mixed> $parameters
*/
public function withParameters($parameters = []);
public function withParameters(array $parameters = []): static;
}
23 changes: 6 additions & 17 deletions src/Http/Responses/SimpleViewResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,32 @@

namespace Laravel\Passport\Http\Responses;

use Closure;
use Illuminate\Contracts\Support\Responsable;
use Laravel\Passport\Contracts\AuthorizationViewResponse;

class SimpleViewResponse implements AuthorizationViewResponse
{
/**
* The name of the view or the callable used to generate the view.
*
* @var callable|string
*/
protected $view;

/**
* An array of arguments that may be passed to the view response and used in the view.
*
* @var array
* @var array<string, mixed>
*/
protected $parameters;
protected array $parameters = [];

/**
* Create a new response instance.
*
* @param callable|string $view
* @return void
*/
public function __construct($view)
public function __construct(protected Closure|string $view)
{
$this->view = $view;
}

/**
* Add parameters to response.
*
* @param array $parameters
* @return $this
* @param array<string, mixed> $parameters
*/
public function withParameters($parameters = [])
public function withParameters(array $parameters = []): static
{
$this->parameters = $parameters;

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/AuthorizationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public function test_authorization_view_is_presented()

$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request) {
$response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request, $response) {
$this->assertEquals($client, $data['client']);
$this->assertEquals($user, $data['user']);
$this->assertEquals($request, $data['request']);
$this->assertSame('description', $data['scopes'][0]->description);

return 'view';
return $response;
});

$this->assertSame('view', $controller->authorize(
$this->assertSame($response, $controller->authorize(
m::mock(ServerRequestInterface::class), $request, $clients
));
}
Expand Down Expand Up @@ -221,16 +221,16 @@ public function test_authorization_view_is_presented_if_request_has_prompt_equal
$clients->shouldReceive('find')->with(1)->andReturn($client = m::mock(Client::class));
$client->shouldReceive('skipsAuthorization')->andReturn(false);

$response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request) {
$response->shouldReceive('withParameters')->once()->andReturnUsing(function ($data) use ($client, $user, $request, $response) {
$this->assertEquals($client, $data['client']);
$this->assertEquals($user, $data['user']);
$this->assertEquals($request, $data['request']);
$this->assertSame('description', $data['scopes'][0]->description);

return 'view';
return $response;
});

$this->assertSame('view', $controller->authorize(
$this->assertSame($response, $controller->authorize(
m::mock(ServerRequestInterface::class), $request, $clients
));
}
Expand Down

0 comments on commit 0508b77

Please sign in to comment.