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
|
|
|
|