test_createDefaultConnection_called_setADefaultConnectionKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 21
loc 21
rs 9.3143
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the NatsBundle package.
5
 *
6
 * (c) Issel Guberna <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Octante\NatsBundle\Tests\Unit\Connection;
13
14
use Octante\NatsBundle\Services\ConnectionFactory;
15
16
class ConnectionFactoryTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * method: createConnection
20
     * when: calledWithAValidConfigurationKey
21
     * will:  returnAValidConnection.
22
     */
23 View Code Duplication
    public function test_createConnection_calledWithAValidConfigurationKey_returnAValidConnection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $conf = [
26
            'test_connection' => [
27
                'host' => 'localhost',
28
                'port' => 4222,
29
                'user' => 'user',
30
                'password' => 'password',
31
                'verbose' => true,
32
                'reconnect' => true,
33
                'version' => '0.0.5',
34
                'pedantic' => true,
35
                'lang' => 'php',
36
            ],
37
        ];
38
39
        $logMock = $this->getMock('Octante\NatsBundle\Logger\NatsLogger');
40
41
        $sut = new ConnectionFactory($conf, $logMock);
42
        $connection = $sut->createConnection('test_connection');
43
        $this->assertInstanceOf('Octante\NatsBundle\Connection\ConnectionWrapper', $connection);
44
    }
45
46
    /**
47
     * method: createConnection
48
     * when: calledWithAnInvalidConfigurationKey
49
     * will:  throwAnException.
50
     *
51
     * @expectedException \Octante\NatsBundle\Exceptions\ConnectionNameNotFound
52
     */
53
    public function test_createConnection_calledWithAnInvalidConfigurationKey_throwAnException()
54
    {
55
        $conf = [
56
            'dummy_connection' => [
57
            ],
58
        ];
59
60
        $logMock = $this->getMock('Octante\NatsBundle\Logger\NatsLogger');
61
        $sut = new ConnectionFactory($conf, $logMock);
62
        $sut->createConnection('test_connection');
63
    }
64
65
    /**
66
     * method: createDefaultConnection
67
     * when: called
68
     * will:  setADefaultConnectionKey.
69
     */
70 View Code Duplication
    public function test_createDefaultConnection_called_setADefaultConnectionKey()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $conf = [
73
            'default_connection' => [
74
                'host' => 'localhost',
75
                'port' => 4222,
76
                'user' => 'user',
77
                'password' => 'password',
78
                'verbose' => true,
79
                'reconnect' => true,
80
                'version' => '0.0.5',
81
                'pedantic' => true,
82
                'lang' => 'php',
83
            ],
84
        ];
85
86
        $logMock = $this->getMock('Octante\NatsBundle\Logger\NatsLogger');
87
        $sut = new ConnectionFactory($conf, $logMock);
88
        $connection = $sut->createDefaultConnection();
89
        $this->assertInstanceOf('Nats\Connection', $connection);
90
    }
91
}
92