remove notifications of deleted comments from the DB
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
006da9afd7
commit
a35d4e7b44
|
@ -53,12 +53,20 @@ class EventHandler implements ICommentsEventHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $event->getEvent() === CommentsEvent::EVENT_ADD
|
$eventType = $event->getEvent();
|
||||||
|
if( $eventType === CommentsEvent::EVENT_ADD
|
||||||
&& $event instanceof CommentsEvent
|
&& $event instanceof CommentsEvent
|
||||||
) {
|
) {
|
||||||
$this->onAdd($event);
|
$this->onAdd($event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( $eventType === CommentsEvent::EVENT_DELETE
|
||||||
|
&& $event instanceof CommentsEvent
|
||||||
|
) {
|
||||||
|
$this->onDelete($event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,4 +83,15 @@ class EventHandler implements ICommentsEventHandler {
|
||||||
$activityListener = $c->query(ActivityListener::class);
|
$activityListener = $c->query(ActivityListener::class);
|
||||||
$activityListener->commentEvent($event);
|
$activityListener->commentEvent($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CommentsEvent $event
|
||||||
|
*/
|
||||||
|
private function onDelete(CommentsEvent $event) {
|
||||||
|
$c = $this->app->getContainer();
|
||||||
|
|
||||||
|
/** @var NotificationListener $notificationListener */
|
||||||
|
$notificationListener = $c->query(NotificationListener::class);
|
||||||
|
$notificationListener->evaluate($event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,14 +71,13 @@ class EventHandlerTest extends TestCase {
|
||||||
|
|
||||||
public function notHandledProvider() {
|
public function notHandledProvider() {
|
||||||
return [
|
return [
|
||||||
[CommentsEvent::EVENT_DELETE],
|
|
||||||
[CommentsEvent::EVENT_UPDATE]
|
[CommentsEvent::EVENT_UPDATE]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider notHandledProvider
|
* @dataProvider notHandledProvider
|
||||||
* @param $eventType
|
* @param string $eventType
|
||||||
*/
|
*/
|
||||||
public function testNotHandled($eventType) {
|
public function testNotHandled($eventType) {
|
||||||
/** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */
|
/** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */
|
||||||
|
@ -103,7 +102,18 @@ class EventHandlerTest extends TestCase {
|
||||||
$this->eventHandler->handle($event);
|
$this->eventHandler->handle($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHandled() {
|
public function handledProvider() {
|
||||||
|
return [
|
||||||
|
[CommentsEvent::EVENT_DELETE],
|
||||||
|
[CommentsEvent::EVENT_ADD]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider handledProvider
|
||||||
|
* @param string $eventType
|
||||||
|
*/
|
||||||
|
public function testHandled($eventType) {
|
||||||
/** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */
|
/** @var IComment|\PHPUnit_Framework_MockObject_MockObject $comment */
|
||||||
$comment = $this->getMockBuilder(IComment::class)->getMock();
|
$comment = $this->getMockBuilder(IComment::class)->getMock();
|
||||||
$comment->expects($this->once())
|
$comment->expects($this->once())
|
||||||
|
@ -119,7 +129,7 @@ class EventHandlerTest extends TestCase {
|
||||||
->willReturn($comment);
|
->willReturn($comment);
|
||||||
$event->expects($this->atLeastOnce())
|
$event->expects($this->atLeastOnce())
|
||||||
->method('getEvent')
|
->method('getEvent')
|
||||||
->willReturn(CommentsEvent::EVENT_ADD);
|
->willReturn($eventType);
|
||||||
|
|
||||||
$notificationListener = $this->getMockBuilder(NotificationListener::class)
|
$notificationListener = $this->getMockBuilder(NotificationListener::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
|
@ -131,13 +141,13 @@ class EventHandlerTest extends TestCase {
|
||||||
$activityListener = $this->getMockBuilder(ActivityListener::class)
|
$activityListener = $this->getMockBuilder(ActivityListener::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$activityListener->expects($this->once())
|
$activityListener->expects($this->any())
|
||||||
->method('commentEvent')
|
->method('commentEvent')
|
||||||
->with($event);
|
->with($event);
|
||||||
|
|
||||||
/** @var IContainer|\PHPUnit_Framework_MockObject_MockObject $c */
|
/** @var IContainer|\PHPUnit_Framework_MockObject_MockObject $c */
|
||||||
$c = $this->getMockBuilder(IContainer::class)->getMock();
|
$c = $this->getMockBuilder(IContainer::class)->getMock();
|
||||||
$c->expects($this->exactly(2))
|
$c->expects($this->atLeastOnce())
|
||||||
->method('query')
|
->method('query')
|
||||||
->withConsecutive([NotificationListener::class], [ActivityListener::class])
|
->withConsecutive([NotificationListener::class], [ActivityListener::class])
|
||||||
->willReturnOnConsecutiveCalls($notificationListener, $activityListener);
|
->willReturnOnConsecutiveCalls($notificationListener, $activityListener);
|
||||||
|
|
Loading…
Reference in New Issue