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

testDispatchingEventFromConsoleCommandTriggersPushEvent()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 30
Code Lines 19

Duplication

Lines 10
Ratio 33.33 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 10
loc 30
rs 8.8571
c 1
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\Console\Input\ArrayInput;
6
use Symfony\Component\Console\Output\NullOutput;
7
use Symfony\Component\HttpFoundation\Request;
8
use Eole\Sandstone\Push\PushServerInterface;
9
use Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent;
10
11
class PushOnConsoleCommandTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testDispatchingEventFromConsoleCommandTriggersPushEvent()
14
    {
15
        $pushServerMock = $this->getMockForAbstractClass(PushServerInterface::class);
16
17
        $app = new App\AppRestApi([
18
            'debug' => true,
19
            'sandstone.push' => function () use ($pushServerMock) {
20
                return $pushServerMock;
21
            },
22
        ]);
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
        $console = new App\Console($app);
40
        $input = new ArrayInput(['sandstone:test:push']);
41
        $console->find('sandstone:test:push')->run($input, new NullOutput());
42
    }
43
}
44