0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-04-18 19:28:57 +00:00
kevinpapst_kimai2/tests/EventSubscriber/PagerfantaExceptionSubscriberTest.php
Kevin Papst 2e6b700b43
Release 2.32 (#5411)
* bump packages
* dynamic invoice options
* make sure that invoice previews can be detected
* support for mpdf associated files
* do not include any future times in work contract calculation
* re-add username column in Excel spreadsheet
* deactivate internal rate editing
* show if plugin update exists
* shorten name to Kimai only, without Time-Tracking
* remove check for existing id in work contract
* fix metafield already defined in search
* helper methods to unlock months
* new translation
* send event on unlock month
2025-04-06 09:53:48 +02:00

63 lines
2.6 KiB
PHP

<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\EventSubscriber;
use App\EventSubscriber\PagerfantaExceptionSubscriber;
use Pagerfanta\Exception\NotValidMaxPerPageException;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* @covers \App\EventSubscriber\PagerfantaExceptionSubscriber
*/
class PagerfantaExceptionSubscriberTest extends TestCase
{
public function testGetSubscribedEvents(): void
{
$events = PagerfantaExceptionSubscriber::getSubscribedEvents();
self::assertArrayHasKey(KernelEvents::EXCEPTION, $events);
$methodName = $events[KernelEvents::EXCEPTION][0];
self::assertIsString($methodName);
self::assertTrue(method_exists(PagerfantaExceptionSubscriber::class, $methodName));
}
public function testWithExceptions(): void
{
$sut = new PagerfantaExceptionSubscriber();
$kernel = $this->createMock(HttpKernelInterface::class);
$request = $this->createMock(Request::class);
$exception = new \Exception();
$requestType = HttpKernelInterface::MAIN_REQUEST;
$event = new ExceptionEvent($kernel, $request, $requestType, $exception);
$sut->onCoreException($event);
self::assertSame($exception, $event->getThrowable());
$event = new ExceptionEvent($kernel, $request, $requestType, new NotValidMaxPerPageException('Foo baaaaar!', 999));
$sut->onCoreException($event);
self::assertInstanceOf(NotFoundHttpException::class, $event->getThrowable());
self::assertEquals('Foo baaaaar!', $event->getThrowable()->getMessage());
self::assertEquals(999, $event->getThrowable()->getCode());
self::assertEquals(404, $event->getThrowable()->getStatusCode());
$event = new ExceptionEvent($kernel, $request, $requestType, new OutOfRangeCurrentPageException('Trölölölölölö', 123));
$sut->onCoreException($event);
self::assertInstanceOf(NotFoundHttpException::class, $event->getThrowable());
self::assertEquals('Trölölölölölö', $event->getThrowable()->getMessage());
self::assertEquals(123, $event->getThrowable()->getCode());
self::assertEquals(404, $event->getThrowable()->getStatusCode());
}
}