NotificationSubscriberTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSubscribedEvents() 0 8 1
A testNotify() 0 14 1
1
<?php
2
3
namespace JK\SamBundle\Tests\Event;
4
5
use JK\Sam\Event\NotificationEvent;
6
use JK\SamBundle\Event\Subscriber\NotificationSubscriber;
7
use PHPUnit\Framework\TestCase;
8
9
class NotificationSubscriberTest extends TestCase
10
{
11
    /**
12
     * The subscriber should subscribe to the notify event.
13
     */
14
    public function testGetSubscribedEvents()
15
    {
16
        $this
17
            ->assertEquals([
18
                NotificationEvent::NAME => 'notify'
19
            ], NotificationSubscriber::getSubscribedEvents())
20
        ;
21
    }
22
23
    /**
24
     * Notify method should add a notification into the subscriber. Clear method should reset the notification array.
25
     */
26
    public function testNotify()
27
    {
28
        $event = new NotificationEvent();
29
        $event->setMessage('What a test');
30
31
        $subscriber = new NotificationSubscriber();
32
        $subscriber->notify($event);
33
34
        $this->assertCount(1, $subscriber->getNotifications());
35
        $this->assertEquals('What a test', $subscriber->getNotifications()[0]);
36
37
        $subscriber->clearNotifications();
38
        $this->assertEquals([], $subscriber->getNotifications());
39
    }
40
}
41