|
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 \Graze\Dynamark3Client\Dynamark3ResponseInterface; |
|
23
|
|
|
use \Graze\Dynamark3Client\Dynamark3Constants; |
|
24
|
|
|
use \Mockery as m; |
|
25
|
|
|
|
|
26
|
|
|
class Dynamark3ClientTest extends \PHPUnit_Framework_TestCase |
|
27
|
|
|
{ |
|
28
|
|
|
public function testSend() |
|
29
|
|
|
{ |
|
30
|
|
|
$telnetResponse = m::mock(TelnetResponseInterface::class); |
|
31
|
|
|
$telnet = m::mock(TelnetClientInterface::class) |
|
32
|
|
|
->shouldReceive('execute') |
|
33
|
|
|
->with('COMMAND ARGS', null) |
|
34
|
|
|
->andReturn($telnetResponse) |
|
35
|
|
|
->once() |
|
36
|
|
|
->getMock(); |
|
37
|
|
|
|
|
38
|
|
|
$dynamark3Response = m::mock(Dynamark3ResponseInterface::class); |
|
39
|
|
|
$command = m::mock(CommandInterface::class) |
|
40
|
|
|
->shouldReceive('getCommandText') |
|
41
|
|
|
->andReturn('COMMAND') |
|
42
|
|
|
->once() |
|
43
|
|
|
->shouldReceive('getArgumentText') |
|
44
|
|
|
->andReturn(' ARGS') |
|
45
|
|
|
->once() |
|
46
|
|
|
->shouldReceive('getPrompt') |
|
47
|
|
|
->andReturn(null) |
|
48
|
|
|
->once() |
|
49
|
|
|
->shouldReceive('parseResponse') |
|
50
|
|
|
->with($telnetResponse) |
|
51
|
|
|
->andReturn($dynamark3Response) |
|
52
|
|
|
->once() |
|
53
|
|
|
->getMock(); |
|
54
|
|
|
$commandResolver = m::mock(CommandResolver::class) |
|
55
|
|
|
->shouldReceive('resolve') |
|
56
|
|
|
->with('command') |
|
57
|
|
|
->andReturn($command) |
|
58
|
|
|
->once() |
|
59
|
|
|
->getMock(); |
|
60
|
|
|
|
|
61
|
|
|
$client = new Dynamark3Client($telnet, $commandResolver); |
|
62
|
|
|
$resp = $client->command(); |
|
|
|
|
|
|
63
|
|
|
$this->assertSame($dynamark3Response, $resp); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testFactory() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->assertInstanceOf(Dynamark3Client::class, Dynamark3Client::factory()); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testConnect() |
|
72
|
|
|
{ |
|
73
|
|
|
$dsn = '127.0.0.1:23'; |
|
74
|
|
|
$telnet = m::mock(TelnetClientInterface::class) |
|
75
|
|
|
->shouldReceive('connect') |
|
76
|
|
|
->with( |
|
77
|
|
|
$dsn, |
|
78
|
|
|
Dynamark3Constants::PROMPT, |
|
79
|
|
|
Dynamark3Constants::PROMPT_ERROR, |
|
80
|
|
|
Dynamark3Constants::LINE_ENDING |
|
81
|
|
|
) |
|
82
|
|
|
->once() |
|
83
|
|
|
->getMock(); |
|
84
|
|
|
|
|
85
|
|
|
$commandResolver = m::mock(CommandResolver::class); |
|
86
|
|
|
|
|
87
|
|
|
$client = new Dynamark3Client($telnet, $commandResolver); |
|
88
|
|
|
$client->connect($dsn); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: