|
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); |
|
|
|
|
|
|
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') |
|
|
|
|
|
|
36
|
|
|
->with('foo') |
|
37
|
|
|
->andReturn('fooescaped') |
|
38
|
|
|
->once() |
|
39
|
|
|
->shouldReceive('escape') |
|
|
|
|
|
|
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
|
|
|
|