Issues (283)

tests/unit/SocketReaderTest.php (2 issues)

1
<?php
2
3
/**
4
 * This file is part of graze/unicontroller-client.
5
 *
6
 * Copyright (c) 2016 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/unicontroller-client/blob/master/LICENSE.md
12
 * @link https://github.com/graze/unicontroller-client
13
 */
14
15
namespace Graze\UniControllerClient\Test\Unit;
16
17
use Mockery as m;
18
use Socket\Raw\Socket;
19
use Graze\UnicontrollerClient\SocketReader;
20
21
class SocketReaderTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @dataProvider readDataProvider
25
     *
26
     * @param array $stream
27
     * @param string $expected
28
     */
29
    public function testRead(array $stream, $expected)
30
    {
31
        $socket = m::mock(Socket::class)
32
            ->shouldReceive('read')
0 ignored issues
show
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'read'. ( Ignorable by Annotation )

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

32
            ->/** @scrutinizer ignore-call */ shouldReceive('read')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
33
            ->times(count($stream));
34
35
        call_user_func_array([$socket, 'andReturn'], $stream);
36
        $socket = $socket->getMock();
37
38
        $socketReader = new SocketReader();
39
        $response = $socketReader->read($socket);
0 ignored issues
show
$socket of type Mockery\MockInterface is incompatible with the type Socket\Raw\Socket expected by parameter $socket of Graze\UnicontrollerClient\SocketReader::read(). ( Ignorable by Annotation )

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

39
        $response = $socketReader->read(/** @scrutinizer ignore-type */ $socket);
Loading history...
40
41
        $this->assertEquals($expected, $response);
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function readDataProvider()
48
    {
49
        return [
50
            [
51
                ["\x01", 't', 'e', 's', 't', 'i', 'n', 'g', ' ', '1', "\x17"],
52
                'testing 1'
53
            ],
54
            [
55
                ['t', 'e', 's', 't', 'i', 'n', 'g', ' ', '2', "\n"],
56
                "testing 2\n"
57
            ]
58
        ];
59
    }
60
}
61