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

PushOnConsoleCommandTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 30.3 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 8
dl 10
loc 33
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testDispatchingEventFromConsoleCommandTriggersPushEvent() 10 30 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\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