/** * {@inheritdoc} */ public function getNotifications($event, $object) { $notifications = []; switch ($event) { case 'postPersist': if ($object->getAssignee() != $object->getReporter()) { $url = $this->router->generate('get_issue', ['issueId' => $object->getId()]); $notification = $this->notificationFactory->create(); $notification->setProject($object->getProject())->setTitle($object->getTitle())->setDescription($object->getDescription())->setType(self::EVENT_ISSUE_NEW)->setResourceUrl($url)->setWebUrl($url)->setUser($object->getAssignee()); $notifications[] = $notification; } break; } return $notifications; }
function it_gets_notifications(IssueInterface $issue, UserInterface $assignee, UserInterface $reporter, ProjectInterface $project, RouterInterface $router, NotificationFactory $factory, NotificationInterface $notification) { $issue->getAssignee()->shouldBeCalled()->willReturn($assignee); $issue->getReporter()->shouldBeCalled()->willReturn($reporter); $issue->getProject()->shouldBeCalled()->willReturn($project); $issue->getId()->shouldBeCalled()->willReturn('issue-id'); $router->generate('get_issue', ['issueId' => 'issue-id'])->shouldBeCalled()->willReturn('http://kreta.io'); $factory->create()->shouldBeCalled()->willReturn($notification); $issue->getProject()->shouldBeCalled()->willReturn($project); $notification->setProject($project)->shouldBeCalled()->willReturn($notification); $issue->getTitle()->shouldBeCalled()->willReturn('Issue title'); $notification->setTitle('Issue title')->shouldBeCalled()->willReturn($notification); $issue->getDescription()->shouldBeCalled()->willReturn('The issue description'); $notification->setDescription('The issue description')->shouldBeCalled()->willReturn($notification); $notification->setType('issue_new')->shouldBeCalled()->willReturn($notification); $notification->setResourceUrl('http://kreta.io')->shouldBeCalled()->willReturn($notification); $notification->setWebUrl('http://kreta.io')->shouldBeCalled()->willReturn($notification); $issue->getAssignee()->shouldBeCalled()->willReturn($assignee); $notification->setUser($assignee)->shouldBeCalled()->willReturn($notification); $this->getNotifications('postPersist', $issue)->shouldReturn([$notification]); }