|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\TelnetClient\Test\Unit; |
|
4
|
|
|
|
|
5
|
|
|
use Graze\TelnetClient\PromptMatcher; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class PromptMatcherTest extends PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @dataProvider dataProviderIsMatch |
|
12
|
|
|
* |
|
13
|
|
|
* @param string $prompt |
|
14
|
|
|
* @param string $subject |
|
15
|
|
|
* @param string $lineEnding |
|
16
|
|
|
* @param bool $isMatch |
|
17
|
|
|
* @param array $matches |
|
18
|
|
|
* @param string $response |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testIsMatch($prompt, $subject, $lineEnding, $isMatch, array $matches = null, $response = null) |
|
23
|
|
|
{ |
|
24
|
|
|
$promptMatcher = new PromptMatcher(); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertEquals($isMatch, $promptMatcher->isMatch($prompt, $subject, $lineEnding)); |
|
27
|
|
|
|
|
28
|
|
|
if (!$isMatch) { |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->assertEquals($matches, $promptMatcher->getMatches()); |
|
33
|
|
|
$this->assertEquals($response, $promptMatcher->getResponseText()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
public function dataProviderIsMatch() |
|
40
|
|
|
{ |
|
41
|
|
|
return [ |
|
42
|
|
|
['OK', 'this is a response', "\n", false], |
|
43
|
|
|
['OK', 'this is a response', null, false], // null line ending |
|
44
|
|
|
['OK', "this is a response\nOK\n", "\n", true, ['OK'], 'this is a response'], |
|
45
|
|
|
['(ERROR) ([0-9]{1,3})', "party\r\nERROR 123\r\n", "\r\n", true, ['ERROR 123', 'ERROR', '123'], 'party'] |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|