Skip to content

Commit

Permalink
Merge pull request #942 from driesvints/status-code-destroy-methods
Browse files Browse the repository at this point in the history
[7.0] Add responses for destroy methods
  • Loading branch information
taylorotwell authored Jan 21, 2019
2 parents d5362c2 + 45066e5 commit 4e3390e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Http/Controllers/AuthorizedAccessTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ public function destroy(Request $request, $tokenId)
}

$token->revoke();

return new Response('', Response::HTTP_NO_CONTENT);
}
}
8 changes: 4 additions & 4 deletions src/Http/Controllers/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function update(Request $request, $clientId)
/**
* Delete the given client.
*
* @param Request $request
* @param \Illuminate\Http\Request $request
* @param string $clientId
* @return \Illuminate\Http\Response
*/
Expand All @@ -120,8 +120,8 @@ public function destroy(Request $request, $clientId)
return new Response('', 404);
}

$this->clients->delete(
$client
);
$this->clients->delete($client);

return new Response('', Response::HTTP_NO_CONTENT);
}
}
4 changes: 3 additions & 1 deletion src/Http/Controllers/PersonalAccessTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function store(Request $request)
/**
* Delete the given token.
*
* @param Request $request
* @param \Illuminate\Http\Request $request
* @param string $tokenId
* @return \Illuminate\Http\Response
*/
Expand All @@ -88,5 +88,7 @@ public function destroy(Request $request, $tokenId)
}

$token->revoke();

return new Response('', Response::HTTP_NO_CONTENT);
}
}
5 changes: 4 additions & 1 deletion tests/AuthorizedAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laravel\Passport\Client;
use PHPUnit\Framework\TestCase;
use Laravel\Passport\TokenRepository;
use Symfony\Component\HttpFoundation\Response;
use Laravel\Passport\Http\Controllers\AuthorizedAccessTokenController;

class AuthorizedAccessTokenControllerTest extends TestCase
Expand Down Expand Up @@ -85,7 +86,9 @@ public function test_tokens_can_be_deleted()
return $user;
});

$this->controller->destroy($request, 1);
$response = $this->controller->destroy($request, 1);

$this->assertEquals(Response::HTTP_NO_CONTENT, $response->status());
}

public function test_not_found_response_is_returned_if_user_doesnt_have_token()
Expand Down
5 changes: 4 additions & 1 deletion tests/ClientControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laravel\Passport\Client;
use PHPUnit\Framework\TestCase;
use Laravel\Passport\Http\Rules\RedirectRule;
use Symfony\Component\HttpFoundation\Response;
use Laravel\Passport\Http\Controllers\ClientController;

class ClientControllerTest extends TestCase
Expand Down Expand Up @@ -155,7 +156,9 @@ public function test_clients_can_be_deleted()
$clients, $validator, m::mock(RedirectRule::class)
);

$controller->destroy($request, 1);
$response = $controller->destroy($request, 1);

$this->assertEquals(Response::HTTP_NO_CONTENT, $response->status());
}

public function test_404_response_if_client_doesnt_belong_to_user_on_delete()
Expand Down
5 changes: 4 additions & 1 deletion tests/PersonalAccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laravel\Passport\Passport;
use PHPUnit\Framework\TestCase;
use Laravel\Passport\TokenRepository;
use Symfony\Component\HttpFoundation\Response;
use Laravel\Passport\Http\Controllers\PersonalAccessTokenController;

class PersonalAccessTokenControllerTest extends TestCase
Expand Down Expand Up @@ -104,7 +105,9 @@ public function test_tokens_can_be_deleted()
$validator = m::mock('Illuminate\Contracts\Validation\Factory');
$controller = new PersonalAccessTokenController($tokenRepository, $validator);

$controller->destroy($request, 1);
$response = $controller->destroy($request, 1);

$this->assertEquals(Response::HTTP_NO_CONTENT, $response->status());
}

public function test_not_found_response_is_returned_if_user_doesnt_have_token()
Expand Down

0 comments on commit 4e3390e

Please sign in to comment.