Skip to content

Commit

Permalink
Removed expects in unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jun 19, 2024
1 parent b10131b commit 00d7238
Show file tree
Hide file tree
Showing 62 changed files with 677 additions and 499 deletions.
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions public/css/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ html[data-bs-theme=dark] .navbar-vertical::-webkit-scrollbar-thumb {
.navbar-vertical ul:not(.dropdown-menu-default) .dropdown-item {
color: var(--bs-navbar-color);
white-space: normal;
padding: 0.3rem 0;
padding: 0.3rem;
width: 100%;
}

.navbar-vertical ul:not(.dropdown-menu-default) .dropdown-item.active {
color: var(--bs-emphasis-color);

}

.navbar-vertical .dropdown-menu:not(.dropdown-menu-default) .dropdown-item:hover,
Expand Down
59 changes: 52 additions & 7 deletions src/Controller/AkismetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
use App\Service\AkismetService;
use App\Service\FakerService;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;

/**
* Controller for the Askimet service.
Expand All @@ -30,15 +33,41 @@
class AkismetController extends AbstractController
{
/**
* @throws \Symfony\Contracts\HttpClient\Exception\ExceptionInterface
* @psalm-api
*
* @throws ExceptionInterface
*/
#[Get(path: '/activity', name: 'activity')]
public function activity(
AkismetService $service,
#[MapQueryParameter]
?int $year = null,
#[MapQueryParameter]
?int $month = null,
): JsonResponse {
$results = $service->activity($year, $month);
if ($service->hasLastError()) {
return $this->json($service->getLastError());
}

return $this->json($results);
}

/**
* @psalm-api
*
* @throws ExceptionInterface
*/
#[Get(path: '/spam', name: 'spam')]
public function spam(AkismetService $service, FakerService $faker): JsonResponse
{
$comment = $faker->getGenerator()->realText(145);
$results = $service->verifyComment($comment);
public function spam(
Request $request,
AkismetService $service,
FakerService $faker,
#[MapQueryParameter]
?string $comment = null,
): JsonResponse {
$comment ??= $faker->getGenerator()->realText(145);
$results = $service->isSpam($comment, [], $request);
if ($service->hasLastError()) {
return $this->json($service->getLastError());
}
Expand All @@ -49,17 +78,33 @@ public function spam(AkismetService $service, FakerService $faker): JsonResponse
]);
}

/**
* @psalm-api
*
* @throws ExceptionInterface
*/
#[Get(path: '/usage', name: 'usage')]
public function usage(AkismetService $service): JsonResponse
{
$results = $service->usage();
if ($service->hasLastError()) {
return $this->json($service->getLastError());
}

return $this->json($results);
}

/**
* @psalm-api
*/
#[Get(path: '/verify', name: 'verify')]
public function verify(AkismetService $service): JsonResponse
{
$results = $service->verifyKey();
$result = $service->isValidKey();
if ($service->hasLastError()) {
return $this->json($service->getLastError());
}

return $this->json(['key_valid' => $results]);
return $this->json(['valid' => $result]);
}
}
4 changes: 2 additions & 2 deletions src/Service/AbstractHttpClientService.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ protected function requestPost(string $url, array $options = []): ResponseInterf
/**
* Sets the last error and log it.
*/
protected function setLastError(int $code, string $message, ?\Exception $exception = null): false
protected function setLastError(int $code, string $message, ?\Throwable $exception = null): false
{
$this->lastError = new HttpClientError($code, $message, $exception);
if ($exception instanceof \Exception) {
if ($exception instanceof \Throwable) {
$this->logException($exception, $message);
} else {
$this->logError($message);
Expand Down

0 comments on commit 00d7238

Please sign in to comment.