Passed
Branch master (69e5ee)
by Timon
05:22
created

testExceptionThrownOnInvalidProtocolVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\UnitTest\Connection\Socket;
5
6
use Mockery\MockInterface;
7
use PHPUnit\Framework\TestCase;
8
use TBolier\RethinkQL\Connection\Socket\Handshake;
9
10
class HandshakeTest extends TestCase
11
{
12
    /**
13
     * @var Handshake
14
     */
15
    private $handshake;
16
17
    /**
18
     * @return void
19
     */
20
    public function setUp(): void
21
    {
22
        $this->handshake = new Handshake('foo', 'bar', 42);
23
    }
24
25
    /**
26
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
27
     * @expectedExceptionMessage Not connected
28
     * @return void
29
     */
30
    public function testExceptionThrownOnStreamNotWritable(): void
31
    {
32
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
33
        $stream->shouldReceive('isWritable')->andReturn(false);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
34
        $stream->shouldReceive('close');
35
36
        $this->handshake->hello($stream);
37
    }
38
39
    /**
40
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
41
     * @expectedExceptionMessage Foobar
42
     * @return void
43
     */
44
    public function testExceptionThrownOnError(): void
45
    {
46
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
47
        $stream->shouldReceive('isWritable')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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
        $stream->shouldReceive('close');
49
        $stream->shouldReceive('write');
50
        $stream->shouldReceive('getContents')->andReturn('ERROR: Foobar');
51
52
        $this->handshake->hello($stream);
53
    }
54
55
    /**
56
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
57
     * @expectedExceptionMessage Foobar
58
     * @return void
59
     */
60
    public function testExceptionThrownOnVerifyProtocolWithError(): void
61
    {
62
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
63
        $stream->shouldReceive('isWritable')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
64
        $stream->shouldReceive('close');
65
        $stream->shouldReceive('write');
66
        $stream->shouldReceive('getContents')->andReturn('{"success":false, "error": "Foobar"}');
67
68
        $this->handshake->hello($stream);
69
    }
70
71
    /**
72
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
73
     * @expectedExceptionMessage Unsupported protocol version.
74
     * @return void
75
     */
76
    public function testExceptionThrownOnInvalidProtocolVersion(): void
77
    {
78
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
79
        $stream->shouldReceive('isWritable')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
80
        $stream->shouldReceive('close');
81
        $stream->shouldReceive('write');
82
        $stream->shouldReceive('getContents')->andReturn('{"success":true, "max_protocol_version": 1, "min_protocol_version": 1}');
83
84
        $this->handshake->hello($stream);
85
    }
86
87
88
    /**
89
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
90
     * @expectedExceptionMessage Woops!
91
     * @return void
92
     */
93
    public function testExceptionThrownOnProtocolError(): void
94
    {
95
        /** @var MockInterface $stream */
96
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
97
        $stream->shouldReceive('isWritable')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

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...
98
        $stream->shouldReceive('close');
99
        $stream->shouldReceive('write');
100
        $stream->shouldReceive('getContents')->andReturn('ERROR: Woops!');
101
102
        $this->handshake->hello($stream);
103
    }
104
}
105