-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJobResponseTest.php
More file actions
81 lines (70 loc) · 2.66 KB
/
JobResponseTest.php
File metadata and controls
81 lines (70 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace V2\Parsing;
use DateTime;
use Mindee\Error\ErrorItem;
use Mindee\Parsing\V2\ErrorResponse;
use Mindee\Parsing\V2\JobResponse;
use PHPUnit\Framework\TestCase;
use TestingUtilities;
require_once(__DIR__ . "/../../TestingUtilities.php");
class TestJobResponse extends TestCase
{
/**
* Load a job sample JSON file and return its decoded contents.
*
* @param string $jsonFile Name of the JSON file to load.
* @return array Decoded JSON data.
*/
private static function getJobSamples(string $jsonFile): array
{
$fullPath = TestingUtilities::getV2DataDir() . "/job/$jsonFile";
$content = file_get_contents($fullPath);
return json_decode($content, true);
}
/**
* Should load when status is Processing.
* @return void
*/
public function testShouldLoadWhenStatusIsProcessing(): void
{
$jsonSample = self::getJobSamples('ok_processing.json');
$response = new JobResponse($jsonSample);
$this->assertNotNull($response->job);
$this->assertSame('Processing', $response->job->status);
$this->assertNull($response->job->completedAt);
$this->assertNull($response->job->error);
$this->assertIsArray($response->job->webhooks);
$this->assertCount(0, $response->job->webhooks);
}
/**
* Should load when status is Processed.
* @return void
*/
public function testShouldLoadWhenStatusIsProcessed(): void
{
$jsonSample = self::getJobSamples('ok_processed_webhooks_ok.json');
$response = new JobResponse($jsonSample);
$this->assertNotNull($response->job);
$this->assertSame('Processed', $response->job->status);
$this->assertInstanceOf(DateTime::class, $response->job->completedAt);
$this->assertNull($response->job->error);
}
/**
* Should load with 422 error.
* @return void
*/
public function testShouldLoadWith422Error(): void
{
$jsonSample = self::getJobSamples('fail_422.json');
$response = new JobResponse($jsonSample);
$this->assertNotNull($response->job);
$this->assertSame('Failed', $response->job->status);
$this->assertInstanceOf(DateTime::class, $response->job->completedAt);
$this->assertInstanceOf(ErrorResponse::class, $response->job->error);
$this->assertSame(422, $response->job->error->status);
$this->assertStringStartsWith('422-', $response->job->error->code);
$this->assertIsArray($response->job->error->errors);
$this->assertCount(1, $response->job->error->errors);
$this->assertInstanceOf(ErrorItem::class, $response->job->error->errors[0]);
}
}