FirehoseAdapterTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 90
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testInterface() 0 3 1
A testDelete() 0 4 1
A testAcknowledge() 0 4 1
A testPurge() 0 4 1
A testDequeue() 0 4 1
A testEnqueue() 0 20 1
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\Adapter;
17
18
use Aws\ResultInterface;
19
use Aws\Firehose\FirehoseClient;
20
use Graze\Queue\Adapter\Exception\MethodNotSupportedException;
21
use Graze\Queue\Message\MessageFactoryInterface;
22
use Graze\Queue\Message\MessageInterface;
23
use Mockery as m;
24
use Mockery\MockInterface;
25
use Graze\Queue\Test\TestCase;
26
27
class FirehoseAdapterTest extends TestCase
28
{
29
    /** @var MessageInterface|MockInterface */
30
    private $messageA;
31
    /** @var MessageInterface|MockInterface */
32
    private $messageB;
33
    /** @var MessageInterface|MockInterface */
34
    private $messageC;
35
    /** @var MessageInterface[]|MockInterface[] */
36
    private $messages;
37
    /** @var ResultInterface|MockInterface */
38
    private $model;
39
    /** @var MessageFactoryInterface|MockInterface */
40
    private $factory;
41
    /** @var FirehoseClient */
42
    private $client;
43
44
    public function setUp()
45
    {
46
        $this->client = m::mock(FirehoseClient::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like Mockery::mock(Aws\Firehose\FirehoseClient::class) of type Mockery\MockInterface is incompatible with the declared type Aws\Firehose\FirehoseClient of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
47
        $this->model = m::mock(ResultInterface::class);
48
        $this->factory = m::mock(MessageFactoryInterface::class);
49
50
        $this->messageA = $a = m::mock(MessageInterface::class);
51
        $this->messageB = $b = m::mock(MessageInterface::class);
52
        $this->messageC = $c = m::mock(MessageInterface::class);
53
        $this->messages = [$a, $b, $c];
54
    }
55
56
    public function testInterface()
57
    {
58
        assertThat(new FirehoseAdapter($this->client, 'foo'), is(anInstanceOf('Graze\Queue\Adapter\AdapterInterface')));
59
    }
60
61
    public function testEnqueue()
62
    {
63
        $adapter = new FirehoseAdapter($this->client, 'foo');
64
65
        $this->messageA->shouldReceive('getBody')->once()->withNoArgs()->andReturn('foo');
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Graze\Queue\Message\MessageInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        $this->messageA->/** @scrutinizer ignore-call */ 
66
                         shouldReceive('getBody')->once()->withNoArgs()->andReturn('foo');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
        $this->messageB->shouldReceive('getBody')->once()->withNoArgs()->andReturn('bar');
67
        $this->messageC->shouldReceive('getBody')->once()->withNoArgs()->andReturn('baz');
68
69
        $this->model->shouldReceive('get')->once()->with('RequestResponses')->andReturn([]);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Aws\ResultInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
        $this->model->/** @scrutinizer ignore-call */ 
70
                      shouldReceive('get')->once()->with('RequestResponses')->andReturn([]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
71
        $this->client->shouldReceive('putRecordBatch')->once()->with([
72
            'DeliveryStreamName' => 'foo',
73
            'Records' => [
74
                ['Data' => 'foo'],
75
                ['Data' => 'bar'],
76
                ['Data' => 'baz'],
77
            ],
78
        ])->andReturn($this->model);
79
80
        $adapter->enqueue($this->messages);
81
    }
82
83
    /**
84
     * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException
85
     */
86
    public function testAcknowledge()
87
    {
88
        $adapter = new FirehoseAdapter($this->client, 'foo');
89
        $adapter->acknowledge($this->messages);
90
    }
91
92
    /**
93
     * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException
94
     */
95
    public function testDequeue()
96
    {
97
        $adapter = new FirehoseAdapter($this->client, 'foo');
98
        $adapter->dequeue($this->factory, 10);
0 ignored issues
show
Bug introduced by
It seems like $this->factory can also be of type Mockery\MockInterface; however, parameter $factory of Graze\Queue\Adapter\FirehoseAdapter::dequeue() does only seem to accept Graze\Queue\Message\MessageFactoryInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

98
        $adapter->dequeue(/** @scrutinizer ignore-type */ $this->factory, 10);
Loading history...
99
    }
100
101
    /**
102
     * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException
103
     */
104
    public function testPurge()
105
    {
106
        $adapter = new FirehoseAdapter($this->client, 'foo');
107
        $adapter->purge();
108
    }
109
110
    /**
111
     * @expectedException \Graze\Queue\Adapter\Exception\MethodNotSupportedException
112
     */
113
    public function testDelete()
114
    {
115
        $adapter = new FirehoseAdapter($this->client, 'foo');
116
        $adapter->delete();
117
    }
118
}
119