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

testForwardEventSendsExpectedMessageToPushServer()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 37
Code Lines 24

Duplication

Lines 10
Ratio 27.03 %

Importance

Changes 0
Metric Value
dl 10
loc 37
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 24
nc 1
nop 0
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