assertArrayHasKey(DashboardEvent::DASHBOARD, $events); $methodName = $events[DashboardEvent::DASHBOARD][0]; $this->assertTrue(method_exists(DashboardSubscriber::class, $methodName)); } public function testWithNonAdminUser() { $sut = $this->getSubscriber(false, 13, 28, 37, 5); $event = new DashboardEvent(new User()); $this->assertEquals(0, count($event->getSections())); $sut->onDashboardEvent($event); $this->assertEquals(0, count($event->getSections())); } public function testWithAdminUser() { $sut = $this->getSubscriber(true, 13, 28, 37, 5); $event = new DashboardEvent(new User()); $this->assertEquals(0, count($event->getSections())); $sut->onDashboardEvent($event); $sections = $event->getSections(); $widgets = $sections[0]->getWidgets(); $this->assertEquals(1, count($sections)); $this->assertEquals(4, count($widgets)); $this->assertEquals('stats.userTotal', $widgets[0]->getTitle()); $this->assertEquals(13, $widgets[0]->getData()); $this->assertEquals('stats.customerTotal', $widgets[1]->getTitle()); $this->assertEquals(5, $widgets[1]->getData()); $this->assertEquals('stats.projectTotal', $widgets[2]->getTitle()); $this->assertEquals(37, $widgets[2]->getData()); $this->assertEquals('stats.activityTotal', $widgets[3]->getTitle()); $this->assertEquals(28, $widgets[3]->getData()); } protected function getSubscriber(bool $isAdmin, int $userCount, int $activityCount, int $projectCount, int $customerCount) { $authMock = $this->getMockBuilder(AuthorizationCheckerInterface::class)->getMock(); $authMock->method('isGranted')->willReturn($isAdmin); $userMock = $this->getMockBuilder(UserRepository::class)->disableOriginalConstructor()->getMock(); $userMock->method('countUsersForQuery')->willReturn($userCount); $projectMock = $this->getMockBuilder(ProjectRepository::class)->disableOriginalConstructor()->getMock(); $projectMock->method('countProjectsForQuery')->willReturn($projectCount); $activityMock = $this->getMockBuilder(ActivityRepository::class)->disableOriginalConstructor()->getMock(); $activityMock->method('countActivitiesForQuery')->willReturn($activityCount); $customerMock = $this->getMockBuilder(CustomerRepository::class)->disableOriginalConstructor()->getMock(); $customerMock->method('countCustomersForQuery')->willReturn($customerCount); return new DashboardSubscriber($authMock, $userMock, $activityMock, $projectMock, $customerMock); } }