Completed
Push — develop ( fe8c75...3bcd98 )
by Tom
02:26
created

ClassifiersResponseTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 58.73 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 3
dl 37
loc 63
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSuccess() 18 18 2
A testVerbose() 19 19 2

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\Message;
4
5
use Bobbyshaw\WatsonVisualRecognition\Classifier;
6
use Bobbyshaw\WatsonVisualRecognition\Message\ClassifiersResponse;
7
use Bobbyshaw\WatsonVisualRecognition\Message\RequestInterface;
8
use Bobbyshaw\WatsonVisualRecognition\Tests\Base;
9
10
/**
11
 * Class ClassifiersResponseTest
12
 * @package Bobbyshaw\WatsonVisualRecognition\Tests\Message
13
 */
14
class ClassifiersResponseTest extends Base
15
{
16
    protected $images = array('cosmos-flower-433424_640.jpg', 'hummingbird-1047836_640.jpg');
17
18
    protected $classifiers = [
19
        "Black" => "Black",
20
        "Blue" => "Blue",
21
        "Brown" => "Brown",
22
        "Cyan" => "Cyan",
23
        "Green" => "Green",
24
        "Magenta" => "Magenta",
25
        "Mixed_Color" => "Mixed_Color",
26
        "Orange" => "Orange",
27
        "Red" => "Red",
28
        "Violet" => "Violet",
29
        "White" => "White",
30
        "Yellow" => "Yellow",
31
        "Black_and_white" => "Black_and_white",
32
        "Color" => "Color",
33
    ];
34
35 View Code Duplication
    public function testSuccess()
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...
36
    {
37
        /** @var RequestInterface $httpRequest */
38
        $httpRequest = $this->getMockForAbstractClass(RequestInterface::class);
39
        $httpResponse = $this->getMockHttpResponse('GetClassifiersSuccess.txt');
40
41
        $response = new ClassifiersResponse($httpRequest, $httpResponse->getBody());
42
43
        $classifiers = $response->getClassifiers();
44
45
        $this->assertTrue($response->isSuccessful());
46
        $this->assertCount(14, $classifiers);
47
48
        foreach ($classifiers as $classifier) {
49
            $this->assertInstanceOf(Classifier::class, $classifier);
50
            $this->assertContains($classifier->getName(), $this->classifiers);
51
        }
52
    }
53
54
    /**
55
     * Test versbose response
56
     */
57 View Code Duplication
    public function testVerbose()
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...
58
    {
59
        /** @var RequestInterface $httpRequest */
60
        $httpRequest = $this->getMockForAbstractClass(RequestInterface::class);
61
        $httpResponse = $this->getMockHttpResponse('GetClassifiersVerbose.txt');
62
63
        $response = new ClassifiersResponse($httpRequest, $httpResponse->getBody());
64
65
        $classifiers = $response->getClassifiers();
66
67
        $this->assertTrue($response->isSuccessful());
68
        $this->assertCount(713, $classifiers);
69
70
        foreach ($classifiers as $classifier) {
71
            $this->assertInstanceOf(Classifier::class, $classifier);
72
            $this->assertInstanceOf(\DateTime::class, $classifier->getCreated());
73
            $this->assertEquals('IBM', $classifier->getOwner());
74
        }
75
    }
76
}
77