PushTest::testForwardEventToPushServer()   B
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 32
Code Lines 19

Duplication

Lines 10
Ratio 31.25 %

Importance

Changes 0
Metric Value
dl 10
loc 32
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 19
nc 1
nop 0
1
<?php
2
3
namespace Eole\Sandstone\Tests\Integration;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Eole\Sandstone\Push\PushServerInterface;
7
use Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent;
8
9
class PushTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testForwardEventToPushServer()
12
    {
13
        $pushServerMock = $this->getMockForAbstractClass(PushServerInterface::class);
14
15
        $app = new App\AppRestApi([
16
            'debug' => true,
17
            'sandstone.push' => function () use ($pushServerMock) {
18
                return $pushServerMock;
19
            },
20
        ]);
21
22
        $app->boot();
23
24
        $pushServerMock
25
            ->expects($this->once())
26
            ->method('send')
27 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...
28
                $decodedMessage = unserialize($message);
29
                $serializedEvent = '{"propagation_stopped":false,"id":42,"title":"Unicorns spotted in Alaska","url":"http:\/\/unicorn.com\/articles\/unicorns-spotted-alaska"}';
30
31
                return
32
                    ArticleCreatedEvent::ARTICLE_CREATED_EVENT === $decodedMessage['name'] &&
33
                    ArticleCreatedEvent::class === $decodedMessage['class'] &&
34
                    $serializedEvent === $decodedMessage['event']
35
                ;
36
            }))
37
        ;
38
39
        $result = $app->handle(Request::create('/api/articles', Request::METHOD_POST));
40
41
        $this->assertEquals(42, $result->getContent());
42
    }
43
}
44