|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of graze/dynamark3-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/dynamark3-client/blob/master/LICENSE.md |
|
12
|
|
|
* @link https://github.com/graze/dynamark3-client |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Graze\Dynamark3Client\Test\Unit; |
|
16
|
|
|
|
|
17
|
|
|
use Graze\TelnetClient\TelnetResponseInterface; |
|
18
|
|
|
use Graze\Dynamark3Client\Command\CommandInterface; |
|
19
|
|
|
use Graze\TelnetClient\TelnetClientInterface; |
|
20
|
|
|
use Graze\Dynamark3Client\CommandResolver; |
|
21
|
|
|
use Graze\Dynamark3Client\Dynamark3Client; |
|
22
|
|
|
use Mockery as m; |
|
23
|
|
|
|
|
24
|
|
|
class Dynamark3ClientTest extends \PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @dataProvider dataProviderSend |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $expectedCommand |
|
30
|
|
|
* @param string $commandText |
|
31
|
|
|
* @param array $args |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testSend($expectedCommand, $commandText, array $args) |
|
36
|
|
|
{ |
|
37
|
|
|
$telnetResponse = m::mock(TelnetResponseInterface::class); |
|
38
|
|
|
$telnet = m::mock(TelnetClientInterface::class) |
|
39
|
|
|
->shouldReceive('execute') |
|
40
|
|
|
->with($expectedCommand, null) |
|
41
|
|
|
->andReturn($telnetResponse) |
|
42
|
|
|
->once() |
|
43
|
|
|
->getMock(); |
|
44
|
|
|
|
|
45
|
|
|
$command = m::mock(CommandInterface::class) |
|
46
|
|
|
->shouldReceive('getCommandText') |
|
47
|
|
|
->andReturn($commandText) |
|
48
|
|
|
->once() |
|
49
|
|
|
->shouldReceive('getPrompt') |
|
50
|
|
|
->andReturn(null) |
|
51
|
|
|
->once() |
|
52
|
|
|
->shouldReceive('parseResponse') |
|
53
|
|
|
->with($telnetResponse) |
|
54
|
|
|
->once() |
|
55
|
|
|
->getMock(); |
|
56
|
|
|
$commandResolver = m::mock(CommandResolver::class) |
|
57
|
|
|
->shouldReceive('resolve') |
|
58
|
|
|
->with($commandText) |
|
59
|
|
|
->andReturn($command) |
|
60
|
|
|
->getMock(); |
|
61
|
|
|
|
|
62
|
|
|
$client = new Dynamark3Client($telnet, $commandResolver); |
|
63
|
|
|
call_user_func_array([$client, $commandText], $args); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return array |
|
68
|
|
|
*/ |
|
69
|
|
|
public function dataProviderSend() |
|
70
|
|
|
{ |
|
71
|
|
|
return [ |
|
72
|
|
|
['aCommandYeah "arg1" "arg2"', 'aCommandYeah', ['arg1', 'arg2']], |
|
73
|
|
|
['sweetCommandBro', 'sweetCommandBro', []], |
|
74
|
|
|
]; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|