ConnectionFactoryTest::getMockedFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of Laravel SMSFactor.
5
 *
6
 * (c) Filippo Galante <[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 IlGala\Tests\SMSFactor\Adapters;
13
14
use IlGala\SMSFactor\Adapters\AdapterInterface;
15
use IlGala\SMSFactor\Adapters\BuzzAdapter;
16
use IlGala\SMSFactor\Connectors\BuzzConnector;
17
use IlGala\SMSFactor\Connectors\ConnectionFactory;
18
use IlGala\SMSFactor\Connectors\GuzzleConnector;
19
use IlGala\SMSFactor\Connectors\GuzzleHttpConnector;
20
use IlGala\SMSFactor\Connectors\LocalConnector;
21
use GrahamCampbell\TestBench\AbstractTestCase;
22
use Mockery;
23
24
/**
25
 * This is the adapter connection factory test class.
26
 *
27
 * @author Filippo Galante <[email protected]>
28
 */
29
class ConnectionFactoryTest extends AbstractTestCase
30
{
31 View Code Duplication
    public function testMake()
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...
32
    {
33
        $factory = $this->getMockedFactory();
34
35
        $return = $factory->make(['driver' => 'guzzlehttp', 'username' => 'your-username', 'password' => 'your-password', 'accept' => 'application/json']);
0 ignored issues
show
Bug introduced by
The method make() does not seem to exist on object<Mockery\MockInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
37
        $this->assertInstanceOf(AdapterInterface::class, $return);
38
    }
39
40
    public function createDataProvider()
41
    {
42
        return [
43
            ['buzz', BuzzConnector::class],
44
            ['guzzle', GuzzleConnector::class],
45
            ['guzzlehttp', GuzzleHttpConnector::class],
46
        ];
47
    }
48
49
    /**
50
     * @dataProvider createDataProvider
51
     */
52
    public function testCreateWorkingDriver($driver, $class)
53
    {
54
        $factory = $this->getConnectionFactory();
55
56
        $return = $factory->createConnector(['driver' => $driver]);
57
58
        $this->assertInstanceOf($class, $return);
59
    }
60
61
    /**
62
     * @expectedException \InvalidArgumentException
63
     * @expectedExceptionMessage A driver must be specified.
64
     */
65
    public function testCreateEmptyDriverConnector()
66
    {
67
        $factory = $this->getConnectionFactory();
68
69
        $factory->createConnector([]);
70
    }
71
72
    /**
73
     * @expectedException \InvalidArgumentException
74
     * @expectedExceptionMessage Unsupported driver [unsupported].
75
     */
76
    public function testCreateUnsupportedDriverConnector()
77
    {
78
        $factory = $this->getConnectionFactory();
79
80
        $factory->createConnector(['driver' => 'unsupported']);
81
    }
82
83
    protected function getConnectionFactory()
84
    {
85
        return new ConnectionFactory();
86
    }
87
88
    protected function getMockedFactory()
89
    {
90
        $mock = Mockery::mock(ConnectionFactory::class . '[createConnector]');
91
92
        $connector = Mockery::mock(LocalConnector::class);
93
94
        $connector->shouldReceive('connect')->once()
95
                ->with(['driver' => 'guzzlehttp', 'username' => 'your-username', 'password' => 'your-password', 'accept' => 'application/json'])
96
                ->andReturn(Mockery::mock(BuzzAdapter::class));
97
98
        $mock->shouldReceive('createConnector')->once()
99
                ->with(['driver' => 'guzzlehttp', 'username' => 'your-username', 'password' => 'your-password', 'accept' => 'application/json'])
100
                ->andReturn($connector);
101
102
        return $mock;
103
    }
104
}
105