Completed
Push — master ( 6435a2...ebbf46 )
by Julien
01:57
created

EventForwarderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 25 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testForwardEventSendsExpectedMessageToPushServer() 10 37 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Eole\Sandstone\Tests\Unit\Push;
4
5
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
6
use Eole\Sandstone\Push\PushServerInterface;
7
use Eole\Sandstone\Push\EventSerializer;
8
use Eole\Sandstone\Push\EventForwarder;
9
use Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent;
10
11
class EventForwarderTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testForwardEventSendsExpectedMessageToPushServer()
14
    {
15
        $pushServerMock = $this->getMockForAbstractClass(PushServerInterface::class);
16
        $eventDispatcherMock = $this->getMockForAbstractClass(EventDispatcherInterface::class);
17
        $eventSerializerMock = $this->getMockBuilder(EventSerializer::class)->disableOriginalConstructor()->getMock();
18
19
        $eventForwarder = new EventForwarder($pushServerMock, $eventDispatcherMock, $eventSerializerMock);
20
21
        $event = new ArticleCreatedEvent(42, 'title', 'url');
22
23
        $pushServerMock
24
            ->expects($this->once())
25
            ->method('send')
26 View Code Duplication
            ->with($this->callback(function ($message) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
                $decodedMessage = unserialize($message);
28
                $serializedEvent = '{"propagation_stopped":false,"id":42,"title":"title","url":"url"}';
29
30
                return
31
                    ArticleCreatedEvent::ARTICLE_CREATED_EVENT === $decodedMessage['name'] &&
32
                    ArticleCreatedEvent::class === $decodedMessage['class'] &&
33
                    $serializedEvent === $decodedMessage['event']
34
                ;
35
            }))
36
        ;
37
38
        $eventSerializerMock
39
            ->expects($this->any())
40
            ->method('serializeEvent')
41
            ->with(
42
                $this->equalTo(ArticleCreatedEvent::ARTICLE_CREATED_EVENT),
43
                $this->equalTo($event)
44
            )
45
            ->willReturn('a:3:{s:4:"name";s:15:"article.created";s:5:"class";s:56:"Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent";s:5:"event";s:65:"{"propagation_stopped":false,"id":42,"title":"title","url":"url"}";}')
46
        ;
47
48
        $eventForwarder->forwardEvent($event, ArticleCreatedEvent::ARTICLE_CREATED_EVENT);
49
    }
50
}
51