-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathVendTest.php
More file actions
86 lines (63 loc) · 2.67 KB
/
Copy pathVendTest.php
File metadata and controls
86 lines (63 loc) · 2.67 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
82
83
84
85
86
<?php
use PHPUnit\Framework\TestCase;
use SimpleSquid\Vend\Exceptions\BadRequestException;
use SimpleSquid\Vend\Exceptions\NotFoundException;
use SimpleSquid\Vend\Resources\TwoDotZero\ProductCollection;
use SimpleSquid\Vend\Vend;
class VendTest extends TestCase
{
/** @var \Mockery\LegacyMockInterface|\Mockery\MockInterface|GuzzleHttp\Client */
private $http;
/** @var \SimpleSquid\Vend\Vend */
private $vend;
public function setUp(): void
{
parent::setUp();
$this->vend = Vend::getInstance();
$this->vend->guzzle = $this->http = Mockery::mock('GuzzleHttp\Client');
$this->vend->userAgent('Vend SDK')
->domainPrefix('abc')
->personalAccessToken('def');
}
public function tearDown(): void
{
Mockery::close();
}
/** @test */
public function test_handling_404_errors()
{
$this->expectException(NotFoundException::class);
$this->http->shouldReceive('request')->once()
->with('GET', 'https://abc.vendhq.com/api/2.0/products', Mockery::type('array'))
->andReturn($response = Mockery::mock('GuzzleHttp\Psr7\Response'));
$response->shouldReceive('getStatusCode')->twice()->andReturn(404);
$response->shouldReceive('getBody')->once();
$this->vend->product->get();
}
/** @test */
public function test_handling_bad_request_errors()
{
$this->http->shouldReceive('request')->once()
->with('GET', 'https://abc.vendhq.com/api/2.0/products', Mockery::type('array'))
->andReturn($response = Mockery::mock('GuzzleHttp\Psr7\Response'));
$response->shouldReceive('getStatusCode')->twice()->andReturn(400);
$response->shouldReceive('getBody')->once()->andReturn(json_encode(['error' => 'Error!']));
$e = new BadRequestException();
try {
$this->vend->product->get();
} catch (BadRequestException $e) {
}
$this->assertEquals(['error' => 'Error!'], $e->errors());
}
/** @test */
public function test_making_basic_requests()
{
$this->http->shouldReceive('request')->once()
->with('GET', 'https://abc.vendhq.com/api/2.0/products', Mockery::type('array'))
->andReturn($response = Mockery::mock('GuzzleHttp\Psr7\Response'));
$response->shouldReceive('getStatusCode')->once()->andReturn(200);
$response->shouldReceive('getBody')->once()
->andReturn(json_encode(['data' => (new ProductCollection())->toArray()]));
$this->assertInstanceOf(ProductCollection::class, $this->vend->product->get());
}
}