Passed
Pull Request — master (#11)
by Michel
02:36
created

HandshakeTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TBolier\RethinkQL\UnitTest\Connection\Socket;
5
6
use PHPUnit\Framework\TestCase;
7
use TBolier\RethinkQL\Connection\Socket\Handshake;
8
9
class HandshakeTest extends TestCase
10
{
11
    /**
12
     * @var Handshake
13
     */
14
    private $handshake;
15
16
    /**
17
     * @return void
18
     */
19
    public function setUp(): void
20
    {
21
        $this->handshake = new Handshake('foo', 'bar', 42);
22
    }
23
24
    /**
25
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
26
     * @expectedExceptionMessage Not connected
27
     * @return void
28
     */
29
    public function testExceptionThrownOnStreamNotWritable(): void
30
    {
31
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
32
        $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...
33
        $stream->shouldReceive('close');
34
35
        $this->handshake->hello($stream);
36
    }
37
38
    /**
39
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
40
     * @expectedExceptionMessage Foobar
41
     * @return void
42
     */
43
    public function testExceptionThrownOnError(): void
44
    {
45
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
46
        $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...
47
        $stream->shouldReceive('close');
48
        $stream->shouldReceive('write');
49
        $stream->shouldReceive('getContents')->andReturn('ERROR: Foobar');
50
51
        $this->handshake->hello($stream);
52
    }
53
54
    /**
55
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
56
     * @expectedExceptionMessage Foobar
57
     * @return void
58
     */
59
    public function testExceptionThrownOnVerifyProtocolWithError(): void
60
    {
61
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
62
        $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...
63
        $stream->shouldReceive('close');
64
        $stream->shouldReceive('write');
65
        $stream->shouldReceive('getContents')->andReturn('{"success":false, "error": "Foobar"}');
66
67
        $this->handshake->hello($stream);
68
    }
69
70
    /**
71
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
72
     * @expectedExceptionMessage Unsupported protocol version.
73
     * @return void
74
     */
75
    public function testExceptionThrownOnInvalidProtocolVersion(): void
76
    {
77
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
78
        $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...
79
        $stream->shouldReceive('close');
80
        $stream->shouldReceive('write');
81
        $stream->shouldReceive('getContents')->andReturn('{"success":true, "max_protocol_version": 1, "min_protocol_version": 1}');
82
83
        $this->handshake->hello($stream);
84
    }
85
86
87
    /**
88
     * @expectedException \TBolier\RethinkQL\Connection\Socket\Exception
89
     * @expectedExceptionMessage Woops!
90
     * @return void
91
     */
92
    public function testExceptionThrownOnProtocolError(): void
93
    {
94
        $stream = \Mockery::mock('\Psr\Http\Message\StreamInterface');
95
        $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...
96
        $stream->shouldReceive('close');
97
        $stream->shouldReceive('write');
98
        $stream->shouldReceive('getContents')->andReturn('ERROR: Woops!');
99
100
        $this->handshake->hello($stream);
101
    }
102
}
103