ClassifyResponseTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSuccess() 0 24 3
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Tests\Message;
4
5
use Bobbyshaw\WatsonVisualRecognition\Classifier;
6
use Bobbyshaw\WatsonVisualRecognition\Image;
7
use Bobbyshaw\WatsonVisualRecognition\Message\ClassifyResponse;
8
use Bobbyshaw\WatsonVisualRecognition\Message\RequestInterface;
9
use Bobbyshaw\WatsonVisualRecognition\Tests\Base;
10
11
/**
12
 * Class ClassifyResponseTest
13
 * @package Bobbyshaw\WatsonVisualRecognition\Tests\Message
14
 */
15
class ClassifyResponseTest extends Base
16
{
17
    protected $images = array('cosmos-flower-433424_640.jpg', 'hummingbird-1047836_640.jpg');
18
19
    public function testSuccess()
20
    {
21
        /** @var RequestInterface $httpRequest */
22
        $httpRequest = $this->getMockForAbstractClass(RequestInterface::class);
23
        $httpResponse = $this->getMockHttpResponse('ClassifySuccess.txt');
24
25
        $response = new ClassifyResponse($httpRequest, $httpResponse->getBody());
26
27
        $images = $response->getImages();
28
29
        $this->assertTrue($response->isSuccessful());
30
        $this->assertCount(2, $images);
31
32
        foreach ($images as $image) {
33
            $this->assertInstanceOf(Image::class, $image);
34
            $this->assertContains($image->getName(), $this->images);
35
36
            $classifiers = $image->getClassifiers();
37
38
            foreach ($classifiers as $classifier) {
39
                $this->assertInstanceOf(Classifier::class, $classifier);
40
            }
41
        }
42
    }
43
}
44