Completed
Pull Request — master (#42)
by
unknown
06:09
created

FirehoseIntegrationTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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\FirehoseAdapter;
21
use Mockery as m;
22
use Mockery\MockInterface;
23
use PHPUnit_Framework_TestCase as TestCase;
24
25
class FirehoseIntegrationTest extends TestCase
26
{
27
    /** @var string */
28
    private $queueName;
0 ignored issues
show
Unused Code introduced by
The property $queueName is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
29
    /** @var FirehoseClient|MockInterface */
30
    private $firehoseClient;
31
    /** @var Client */
32
    private $client;
33
34
    public function setUp()
35
    {
36
        $this->deliveryStreamName = 'delivery_stream_foo';
0 ignored issues
show
Bug introduced by
The property deliveryStreamName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
37
        $this->firehoseClient = m::mock(FirehoseClient::class);
38
        $this->client = new Client(new FirehoseAdapter($this->firehoseClient, 'delivery_stream_foo'));
39
    }
40
41
    public function testSend()
42
    {
43
        $model = m::mock(ResultInterface::class);
44
        $model->shouldReceive('get')->once()->with('RequestResponses')->andReturn([]);
45
46
        $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...
47
            'DeliveryStreamName' => $this->deliveryStreamName,
48
            'Records' => [
49
                ['Data' => json_encode(['Id' => 0, 'MessageBody' => 'foo', 'MessageAttributes' => []])]
50
            ]
51
        ])->andReturn($model);
52
53
        $this->client->send([$this->client->create('foo')]);
54
    }
55
}
56