Completed
Pull Request — master (#7)
by John
04:58
created

Dynamark3ClientTest::testFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Dynamark3Constants;
23
use \Mockery as m;
24
25
class Dynamark3ClientTest extends \PHPUnit_Framework_TestCase
26
{
27
    /**
28
     * @dataProvider dataProviderSend
29
     *
30
     * @param string $expectedCommand
31
     * @param string $commandText
32
     * @param array $args
33
     *
34
     * @return void
35
     */
36
    public function testSend($expectedCommand, $commandText, array $args)
37
    {
38
        $telnetResponse = m::mock(TelnetResponseInterface::class);
39
        $telnet = m::mock(TelnetClientInterface::class)
40
            ->shouldReceive('execute')
41
            ->with($expectedCommand, null)
42
            ->andReturn($telnetResponse)
43
            ->once()
44
            ->getMock();
45
46
        $command = m::mock(CommandInterface::class)
47
            ->shouldReceive('getCommandText')
48
            ->andReturn($commandText)
49
            ->once()
50
            ->shouldReceive('getPrompt')
51
            ->andReturn(null)
52
            ->once()
53
            ->shouldReceive('parseResponse')
54
            ->with($telnetResponse)
55
            ->once()
56
            ->getMock();
57
        $commandResolver = m::mock(CommandResolver::class)
58
            ->shouldReceive('resolve')
59
            ->with($commandText)
60
            ->andReturn($command)
61
            ->getMock();
62
63
        $client = new Dynamark3Client($telnet, $commandResolver);
64
        call_user_func_array([$client, $commandText], $args);
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    public function dataProviderSend()
71
    {
72
        return [
73
            ['aCommandYeah "arg1" "arg2"', 'aCommandYeah', ['arg1', 'arg2']],
74
            ['sweetCommandBro', 'sweetCommandBro', []],
75
        ];
76
    }
77
78
    public function testFactory()
79
    {
80
        $this->assertInstanceOf(Dynamark3Client::class, Dynamark3Client::factory());
81
    }
82
83
    public function testConnect()
84
    {
85
        $dsn = '127.0.0.1:23';
86
        $telnet = m::mock(TelnetClientInterface::class)
87
            ->shouldReceive('connect')
88
            ->with(
89
                $dsn,
90
                Dynamark3Constants::PROMPT,
91
                Dynamark3Constants::PROMPT_ERROR,
92
                Dynamark3Constants::LINE_ENDING
93
            )
94
            ->once()
95
            ->getMock();
96
97
        $commandResolver = m::mock(CommandResolver::class);
98
99
        $client = new Dynamark3Client($telnet, $commandResolver);
100
        $client->connect($dsn);
101
    }
102
}
103