Issues (283)

tests/unit/CommandSerialiserTest.php (3 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 Graze\UnicontrollerClient\StringEscaper;
19
use Graze\UnicontrollerClient\CommandSerialiser;
20
21
class CommandSerialiserTest extends \PHPUnit_Framework_TestCase
22
{
23
    public function testSerialiseCommand()
24
    {
25
        $stringEscaper = m::mock(StringEscaper::class);
26
        $commandSerialiser = new CommandSerialiser($stringEscaper);
0 ignored issues
show
$stringEscaper of type Mockery\MockInterface is incompatible with the type Graze\UnicontrollerClient\StringEscaper expected by parameter $stringEscaper of Graze\UnicontrollerClien...rialiser::__construct(). ( Ignorable by Annotation )

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

26
        $commandSerialiser = new CommandSerialiser(/** @scrutinizer ignore-type */ $stringEscaper);
Loading history...
27
28
        $commandSerialised = $commandSerialiser->serialiseCommand('ReadDesign', "1,2,3,\x02Test\x03");
29
        $this->assertEquals("\x01ReadDesign=1,2,3,\x02Test\x03\x17\r\n", $commandSerialised);
30
    }
31
32
    public function testSerialiseArguments()
33
    {
34
        $stringEscaper = m::mock(StringEscaper::class)
35
            ->shouldReceive('escape')
0 ignored issues
show
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'escape'. ( Ignorable by Annotation )

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

35
            ->/** @scrutinizer ignore-call */ shouldReceive('escape')

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...
36
            ->with('foo')
37
            ->andReturn('fooescaped')
38
            ->once()
39
            ->shouldReceive('escape')
0 ignored issues
show
The method shouldReceive() does not exist on Mockery\Expectation. ( Ignorable by Annotation )

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

39
            ->/** @scrutinizer ignore-call */ shouldReceive('escape')

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...
40
            ->with('bar')
41
            ->andReturn('barescaped')
42
            ->once()
43
            ->getMock();
44
        $commandSerialiser = new CommandSerialiser($stringEscaper);
45
46
        $argumentsSerialised = $commandSerialiser->serialiseArguments([
47
            12,
48
            'foo',
49
            13,
50
            'bar'
51
        ]);
52
        $this->assertEquals("12,fooescaped,13,barescaped", $argumentsSerialised);
53
    }
54
}
55