SMSFactorFactoryTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testMake() 0 12 1
A testAdapter() 0 13 1
A getSMSFactorFactory() 0 6 1
A getMockedFactory() 0 11 1
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;
13
14
use IlGala\SMSFactor\Adapters\AdapterInterface;
15
use IlGala\SMSFactor\SMSFactor;
16
use IlGala\SMSFactor\Connectors\ConnectionFactory;
17
use IlGala\SMSFactor\SMSFactorFactory;
18
use IlGala\SMSFactor\SMSFactorManager;
19
use GrahamCampbell\TestBench\AbstractTestCase as AbstractTestBenchTestCase;
20
use Mockery;
21
22
/**
23
 * This is the smsfactor factory test class.
24
 *
25
 * @author Filippo Galante <[email protected]>
26
 */
27
class SMSFactorFactoryTest extends AbstractTestBenchTestCase
28
{
29
    public function testMake()
30
    {
31
        $config = ['driver' => 'guzzlehttp', 'username' => 'your-username', 'password' => 'your-password', 'accept' => 'application/json'];
32
33
        $manager = Mockery::mock(SMSFactorManager::class);
34
35
        $factory = $this->getMockedFactory($config, $manager);
36
37
        $return = $factory->make($config, $manager);
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...
38
39
        $this->assertInstanceOf(SMSFactor::class, $return);
40
    }
41
42
    public function testAdapter()
43
    {
44
        $factory = $this->getSMSFactorFactory();
45
46
        $config = ['driver' => 'guzzlehttp', 'username' => 'your-username', 'password' => 'your-password', 'accept' => 'application/json'];
47
48
        $factory->getAdapter()->shouldReceive('make')->once()
49
                ->with($config)->andReturn(Mockery::mock(AdapterInterface::class));
50
51
        $return = $factory->createAdapter($config);
52
53
        $this->assertInstanceOf(AdapterInterface::class, $return);
54
    }
55
56
    protected function getSMSFactorFactory()
57
    {
58
        $adapter = Mockery::mock(ConnectionFactory::class);
59
60
        return new SMSFactorFactory($adapter);
61
    }
62
63
    protected function getMockedFactory($config, $manager)
0 ignored issues
show
Unused Code introduced by
The parameter $manager is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        $adapter = Mockery::mock(ConnectionFactory::class);
66
67
        $mock = Mockery::mock(SMSFactorFactory::class . '[createAdapter]', [$adapter]);
68
69
        $mock->shouldReceive('createAdapter')->once()
70
                ->with($config)->andReturn(Mockery::mock(AdapterInterface::class));
71
72
        return $mock;
73
    }
74
}
75