graze /
queue
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file is part of graze/queue. |
||
| 5 | * |
||
| 6 | * Copyright (c) 2015 Nature Delivered Ltd. <https://www.graze.com> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | * |
||
| 11 | * @license https://github.com/graze/queue/blob/master/LICENSE MIT |
||
| 12 | * |
||
| 13 | * @link https://github.com/graze/queue |
||
| 14 | */ |
||
| 15 | |||
| 16 | namespace Graze\Queue; |
||
| 17 | |||
| 18 | use Aws\ResultInterface; |
||
| 19 | use Aws\Firehose\FirehoseClient; |
||
| 20 | use Graze\Queue\Adapter\Exception\FailedEnqueueException; |
||
| 21 | use Graze\Queue\Adapter\FirehoseAdapter; |
||
| 22 | use Mockery as m; |
||
| 23 | use Mockery\MockInterface; |
||
| 24 | use Graze\Queue\Test\TestCase; |
||
| 25 | |||
| 26 | class FirehoseIntegrationTest extends TestCase |
||
| 27 | { |
||
| 28 | /** @var string */ |
||
| 29 | private $deliveryStreamName; |
||
| 30 | /** @var FirehoseClient|MockInterface */ |
||
| 31 | private $firehoseClient; |
||
| 32 | /** @var Client */ |
||
| 33 | private $client; |
||
| 34 | |||
| 35 | public function setUp() |
||
| 36 | { |
||
| 37 | $this->deliveryStreamName = 'delivery_stream_foo'; |
||
| 38 | $this->firehoseClient = m::mock(FirehoseClient::class); |
||
| 39 | $this->client = new Client(new FirehoseAdapter($this->firehoseClient, 'delivery_stream_foo')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 40 | } |
||
| 41 | |||
| 42 | public function testSend() |
||
| 43 | { |
||
| 44 | $model = m::mock(ResultInterface::class); |
||
| 45 | $model->shouldReceive('get')->once()->with('RequestResponses')->andReturn([]); |
||
| 46 | |||
| 47 | $this->firehoseClient->shouldReceive('putRecordBatch')->once()->with([ |
||
| 48 | 'DeliveryStreamName' => $this->deliveryStreamName, |
||
| 49 | 'Records' => [ |
||
| 50 | ['Data' => 'foo'] |
||
| 51 | ] |
||
| 52 | ])->andReturn($model); |
||
| 53 | |||
| 54 | $this->client->send([$this->client->create('foo')]); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @expectedException \Graze\Queue\Adapter\Exception\FailedEnqueueException |
||
| 59 | */ |
||
| 60 | public function testSendError() |
||
| 61 | { |
||
| 62 | $model = m::mock(ResultInterface::class); |
||
| 63 | $model->shouldReceive('get')->once()->with('RequestResponses')->andReturn([ |
||
| 64 | [ |
||
| 65 | 'ErrorCode' => 'fooError', |
||
| 66 | 'ErrorMessage' => 'Some error message', |
||
| 67 | 'RecordId' => 'foo', |
||
| 68 | ] |
||
| 69 | ]); |
||
| 70 | |||
| 71 | $this->firehoseClient->shouldReceive('putRecordBatch')->once()->with([ |
||
| 72 | 'DeliveryStreamName' => $this->deliveryStreamName, |
||
| 73 | 'Records' => [ |
||
| 74 | ['Data' => 'foo'], |
||
| 75 | ], |
||
| 76 | ])->andReturn($model); |
||
| 77 | |||
| 78 | $this->client->send([$this->client->create('foo')]); |
||
| 79 | } |
||
| 80 | } |
||
| 81 |