Completed
Push — master ( 03ffe6...2c1c5a )
by Will
11s
created

testHandleTrueResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
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\Handler;
17
18
use ArrayIterator;
19
use Closure;
20
use Graze\Queue\Adapter\AdapterInterface;
21
use Graze\Queue\Message\MessageInterface;
22
use Mockery as m;
23
use Mockery\MockInterface;
24
use PHPUnit_Framework_TestCase as TestCase;
25
26
class ResultAcknowledgementHandlerTest extends TestCase
27
{
28
    /** @var AdapterInterface|MockInterface */
29
    private $adapter;
30
    /** @var ResultAcknowledgementHandler */
31
    private $handler;
32
    /** @var MessageInterface|MockInterface */
33
    private $message;
34
    /** @var ArrayIterator */
35
    private $messages;
36
37
    public function setUp()
38
    {
39
        $this->adapter = m::mock('Graze\Queue\Adapter\AdapterInterface');
40
41
        $this->message = m::mock('Graze\Queue\Message\MessageInterface');
42
        $this->messages = new ArrayIterator([$this->message]);
43
44
        $this->handler = new EagerAcknowledgementHandler();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Graze\Queue\Handler...cknowledgementHandler() of type object<Graze\Queue\Handl...AcknowledgementHandler> is incompatible with the declared type object<Graze\Queue\Handl...AcknowledgementHandler> of property $handler.

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...
45
    }
46
47
    public function testHandleTrueResult()
48
    {
49
        $handler = new ResultAcknowledgementHandler(function ($result) {
50
            return $result === true;
51
        }, $this->handler);
52
53
        $this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true);
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Graze\Queue\Message\MessageInterface.

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...
54
        $this->adapter->shouldReceive('acknowledge')->once()->with(m::mustBe([$this->message]));
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Graze\Queue\Adapter\AdapterInterface.

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...
55
56
        $msgs = [];
57
        $handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) {
0 ignored issues
show
Unused Code introduced by
The parameter $done is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
            $msgs[] = $msg;
59
            return true;
60
        });
61
62
        assertThat($msgs, is(identicalTo(iterator_to_array($this->messages))));
63
    }
64
65
    public function testHandleNonTrueResponse()
66
    {
67
        $handler = new ResultAcknowledgementHandler(function ($result) {
68
            return $result === true;
69
        }, $this->handler);
70
71
        $this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true);
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Graze\Queue\Message\MessageInterface.

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
73
        $handler($this->messages, $this->adapter, function ($msg, Closure $done) use (&$msgs) {
0 ignored issues
show
Unused Code introduced by
The parameter $msg is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $done is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
            return false;
75
        });
76
    }
77
78
    public function testCustomResultAcknowledgementHandler()
79
    {
80
        $handler = new ResultAcknowledgementHandler(function ($result) {
81
            return $result === false;
82
        }, $this->handler);
83
84
        $this->message->shouldReceive('isValid')->once()->withNoArgs()->andReturn(true);
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Graze\Queue\Message\MessageInterface.

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...
85
        $this->adapter->shouldReceive('acknowledge')->once()->with(m::mustBe([$this->message]));
0 ignored issues
show
Bug introduced by
The method shouldReceive does only exist in Mockery\MockInterface, but not in Graze\Queue\Adapter\AdapterInterface.

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...
86
87
        $handler($this->messages, $this->adapter, function ($msg) {
0 ignored issues
show
Unused Code introduced by
The parameter $msg is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
            return false;
89
        });
90
    }
91
}
92