Completed
Pull Request — master (#42)
by
unknown
02:18
created

FirehoseIntegrationTest::testSendError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
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 PHPUnit_Framework_TestCase as 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'));
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([
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Aws\Firehose\FirehoseClient.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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([
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Aws\Firehose\FirehoseClient.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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