Skip to content

Commit

Permalink
fix tests with notices
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari committed Nov 23, 2024
1 parent ca016b9 commit d7f42dd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 52 deletions.
13 changes: 5 additions & 8 deletions tests/Unit/AuthorizedAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,13 @@ public function test_tokens_can_be_deleted()

public function test_not_found_response_is_returned_if_user_doesnt_have_token()
{
$request = Request::create('/', 'GET');

$this->tokenRepository->shouldReceive('findForUser')->with(3, 1)->andReturnNull();
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$request->setUserResolver(function () {
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$request = Request::create('/', 'GET');
$request->setUserResolver(fn () => $user);

return $user;
});
$this->tokenRepository->shouldReceive('findForUser')->with(3, $user)->andReturnNull();

$this->assertSame(404, $this->controller->destroy($request, 3)->status());
}
Expand Down
60 changes: 24 additions & 36 deletions tests/Unit/ClientControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class ClientControllerTest extends TestCase

public function test_all_the_clients_for_the_current_user_can_be_retrieved()
{
$clientRepository = m::mock(ClientRepository::class);
$clientRepository->shouldReceive('forUser')->once()->with(1)
->andReturn($clients = (new Client)->newCollection());

$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$clientRepository = m::mock(ClientRepository::class);
$clientRepository->shouldReceive('forUser')->once()->with($user)
->andReturn($clients = (new Client)->newCollection());

$request = Request::create('/', 'GET');
$request->setUserResolver(fn () => $user);

Expand Down Expand Up @@ -114,18 +114,15 @@ public function test_public_clients_can_be_stored()

public function test_clients_can_be_updated()
{
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$clients = m::mock(ClientRepository::class);
$client = m::mock(Client::class);
$clients->shouldReceive('findForUser')->with(1, 1)->andReturn($client);
$clients->shouldReceive('findForUser')->with(1, $user)->andReturn($client);

$request = Request::create('/', 'GET', ['name' => 'client name', 'redirect' => 'http://localhost']);

$request->setUserResolver(function () {
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
$request->setUserResolver(fn () => $user);

$clients->shouldReceive('update')->once()->with(
$client, 'client name', ['http://localhost']
Expand All @@ -152,17 +149,14 @@ public function test_clients_can_be_updated()

public function test_404_response_if_client_doesnt_belong_to_user()
{
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$clients = m::mock(ClientRepository::class);
$clients->shouldReceive('findForUser')->with(1, 1)->andReturnNull();
$clients->shouldReceive('findForUser')->with(1, $user)->andReturnNull();

$request = Request::create('/', 'GET', ['name' => 'client name', 'redirect' => 'http://localhost']);

$request->setUserResolver(function () {
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
$request->setUserResolver(fn () => $user);

$clients->shouldReceive('update')->never();

Expand All @@ -177,18 +171,15 @@ public function test_404_response_if_client_doesnt_belong_to_user()

public function test_clients_can_be_deleted()
{
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$clients = m::mock(ClientRepository::class);
$client = m::mock(Client::class);
$clients->shouldReceive('findForUser')->with(1, 1)->andReturn($client);
$clients->shouldReceive('findForUser')->with(1, $user)->andReturn($client);

$request = Request::create('/', 'GET', ['name' => 'client name', 'redirect' => 'http://localhost']);

$request->setUserResolver(function () {
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
$request->setUserResolver(fn () => $user);

$clients->shouldReceive('delete')->once()->with(
m::type(Client::class)
Expand All @@ -207,17 +198,14 @@ public function test_clients_can_be_deleted()

public function test_404_response_if_client_doesnt_belong_to_user_on_delete()
{
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$clients = m::mock(ClientRepository::class);
$clients->shouldReceive('findForUser')->with(1, 1)->andReturnNull();
$clients->shouldReceive('findForUser')->with(1, $user)->andReturnNull();

$request = Request::create('/', 'GET', ['name' => 'client name', 'redirect' => 'http://localhost']);

$request->setUserResolver(function () {
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

return $user;
});
$request->setUserResolver(fn () => $user);

$clients->shouldReceive('delete')->never();

Expand Down
13 changes: 5 additions & 8 deletions tests/Unit/PersonalAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,14 @@ public function test_tokens_can_be_deleted()

public function test_not_found_response_is_returned_if_user_doesnt_have_token()
{
$request = Request::create('/', 'GET');
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);

$tokenRepository = m::mock(TokenRepository::class);
$tokenRepository->shouldReceive('findForUser')->with(3, 1)->andReturnNull();

$request->setUserResolver(function () {
$user = m::mock(Authenticatable::class);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$tokenRepository->shouldReceive('findForUser')->with(3, $user)->andReturnNull();

return $user;
});
$request = Request::create('/', 'GET');
$request->setUserResolver(fn () => $user);

$validator = m::mock(Factory::class);
$controller = new PersonalAccessTokenController($tokenRepository, $validator);
Expand Down

0 comments on commit d7f42dd

Please sign in to comment.