QueueDeleteCommandTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 47
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B キューを削除するコマンドを実行する() 32 32 1
A getInputStream() 8 8 1

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
namespace Tavii\SQSJobQueueBundle\Tests\Command;
3
4
use Phake;
5
use SebastianBergmann\PHPCOV\Application;
6
use Symfony\Component\Console\Tester\CommandTester;
7
use Tavii\SQSJobQueueBundle\Command\QueueDeleteCommand;
8
9 View Code Duplication
class QueueDeleteCommandTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
10
{
11
    /**
12
     * @test
13
     */
14
    public function キューを削除するコマンドを実行する()
15
    {
16
        $client = Phake::mock('Aws\Sqs\SqsClient');
17
        $container = Phake::mock('Symfony\Component\DependencyInjection\Container');
18
19
        Phake::when($container)->get('sqs_job_queue.client')->thenReturn($client);
20
        Phake::when($client)->getQueueUrl(array(
21
            'QueueName' => 'test_queue'
22
        ))->thenReturn(array(
23
            'QueueUrl' => '/path/to/url'
24
        ));
25
26
        $application = new Application();
27
        $application->add(new QueueDeleteCommand());
28
29
        $command = $application->get('sqs_job_queue:queue-delete');
30
        $command->setContainer($container);
31
32
        $dialog = $command->getHelper('dialog');
33
        $dialog->setInputStream($this->getInputStream("yes\n"));
34
35
        $tester = new CommandTester($command);
36
        $tester->execute(array(
37
            'command' => $command->getName(),
38
            'queue' => 'test_queue'
39
        ));
40
41
        Phake::verify($container)->get('sqs_job_queue.client');
42
        Phake::verify($client)->deleteQueue(array(
43
            'QueueUrl' => '/path/to/url',
44
        ));
45
    }
46
47
    protected function getInputStream($input)
48
    {
49
        $stream = fopen('php://memory', 'r+', false);
50
        fputs($stream, $input);
51
        rewind($stream);
52
53
        return $stream;
54
    }
55
}
56
57
58