0
0
mirror of https://github.com/kevinpapst/kimai2.git synced 2024-12-22 12:18:29 +00:00
kevinpapst_kimai2/tests/Reporting/ReportingServiceTest.php
2024-12-22 01:25:30 +01:00

55 lines
1.7 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\Reporting;
use App\Entity\User;
use App\Event\ReportingEvent;
use App\Reporting\ReportingService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @covers \App\Reporting\ReportingService
*/
class ReportingServiceTest extends TestCase
{
protected function getSut(bool $isGranted = false): ReportingService
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects($this->exactly($isGranted ? 1 : 0))->method('dispatch')->willReturnCallback(function ($event) {
self::assertInstanceOf(ReportingEvent::class, $event);
return $event;
});
$security = $this->createMock(AuthorizationCheckerInterface::class);
$security->expects($this->any())->method('isGranted')->willReturn($isGranted);
return new ReportingService($dispatcher, $security);
}
public function testGetAvailableReports(): void
{
$sut = $this->getSut();
$reports = $sut->getAvailableReports(new User());
self::assertIsArray($reports);
self::assertEmpty($reports);
}
public function testGetAvailableReportsWithPermission(): void
{
$sut = $this->getSut(true);
$reports = $sut->getAvailableReports(new User());
self::assertIsArray($reports);
self::assertCount(11, $reports);
}
}