Completed
Push — develop ( bdc471...890a38 )
by Tom
02:35
created

DeleteClassifierCommandTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 42.31 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 4
dl 22
loc 52
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testCommand() 0 23 1
A testCommandFail() 22 22 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
3
namespace Bobbyshaw\WatsonVisualRecognition\Tests\Commands;
4
5
use Bobbyshaw\WatsonVisualRecognition\Client;
6
use Bobbyshaw\WatsonVisualRecognition\Commands\DeleteClassifierCommand;
7
use Bobbyshaw\WatsonVisualRecognition\Tests\Base;
8
use GuzzleHttp\Psr7\Response;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\Console\Output\BufferedOutput;
11
12
class DeleteClassifierCommandTest extends Base
13
{
14
    /**
15
     * Test that the command outputs a success info message.
16
     */
17
    public function testCommand()
18
    {
19
        $container = [];
20
        $httpClient = $this->getMockHttpClientWithHistoryAndResponses($container, [new Response(200, [], '{}')]);
21
22
        $arguments = [
23
            'username' => 'test',
24
            'password' => 'test',
25
            'classifier_id' => 'Magenta',
26
            '--version-date' => '2016-01-01',
27
        ];
28
        $input = new ArrayInput($arguments);
29
        $output = new BufferedOutput();
30
31
        $command = new DeleteClassifierCommand(null, new Client($httpClient));
32
        $command->run($input, $output);
33
34
        $this->assertEquals('classifier:delete', $command->getName());
35
36
        $correctOutput = file_get_contents('Tests/Mock/Commands/DeleteClassifierSuccess.txt');
37
38
        $this->assertEquals($correctOutput, $output->fetch());
39
    }
40
41 View Code Duplication
    public function testCommandFail()
1 ignored issue
show
Duplication introduced by
This method 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...
42
    {
43
        $container = [];
44
        $response = $this->getMockHttpResponse('DeleteClassifierFail.txt');
45
        $httpClient = $this->getMockHttpClientWithHistoryAndResponses($container, [$response]);
46
47
        $arguments = [
48
            'username' => 'test',
49
            'password' => 'test',
50
            'classifier_id' => 'Sunset',
51
            '--version-date' => '2016-01-01',
52
        ];
53
        $input = new ArrayInput($arguments);
54
        $output = new BufferedOutput();
55
56
        $command = new DeleteClassifierCommand(null, new Client($httpClient));
57
        $command->run($input, $output);
58
59
        $this->assertEquals('classifier:delete', $command->getName());
60
61
        $this->assertEquals("Cannot delete classifier: Sunset\n", $output->fetch());
62
    }
63
}
64