createMock(EventDispatcherInterface::class); $dispatcher->expects($this->exactly($isGranted ? 1 : 0))->method('dispatch')->willReturnCallback(function ($event) { $this->assertInstanceOf(ReportingEvent::class, $event); }); $security = $this->createMock(AuthorizationCheckerInterface::class); $security->expects($this->any())->method('isGranted')->willReturn($isGranted); return new ReportingService($dispatcher, $security); } public function testGetAvailableReports() { $sut = $this->getSut(); $reports = $sut->getAvailableReports(new User()); self::assertIsArray($reports); self::assertEmpty($reports); } public function testGetAvailableReportsWithPermission() { $sut = $this->getSut(true); $reports = $sut->getAvailableReports(new User()); self::assertIsArray($reports); self::assertCount(8, $reports); } }