Passed
Pull Request — master (#14)
by
unknown
08:37
created

FactoryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testPhpLoader() 0 9 1
A testUnsupportedLoader() 0 14 1
A testYamlLoader() 0 9 1
A testInvalidLoader() 0 10 1
A testTypes() 0 13 1
1
<?php
2
3
namespace Northwoods\Config\Loader;
4
5
use Eloquent\Phony\Phpunit\Phony;
6
use PHPUnit\Framework\TestCase;
7
8
class FactoryTest extends TestCase
9
{
10
    /**
11
     * @var LoaderFactory
12
     */
13
    private $factory;
0 ignored issues
show
Coding Style introduced by
Private member variable "factory" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
14
15
    public function setUp()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
16
    {
17
        $this->factory = new LoaderFactory();
18
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
19
20
    public function testTypes()
21
    {
22
        $loader = $this->factory->forType('php');
23
24
        $this->assertInstanceOf(LoaderInterface::class, $loader);
25
        $this->assertInstanceOf(PhpLoader::class, $loader);
26
        $this->assertTrue($loader::isSupported());
27
28
        $loader = $this->factory->forType('yaml');
29
30
        $this->assertInstanceOf(LoaderInterface::class, $loader);
31
        $this->assertInstanceOf(YamlLoader::class, $loader);
32
        $this->assertTrue($loader::isSupported());
33
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
34
35
    public function testPhpLoader()
36
    {
37
        $loader = $this->factory->forType('php');
38
39
        $config = $loader->load(__DIR__ . '/../../examples/app');
40
        $this->assertArrayHasKey('timezone', $config);
41
42
        $config = $loader->load(__DIR__ . '/failure/fail');
43
        $this->assertSame([], $config);
44
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
45
46
    public function testYamlLoader()
47
    {
48
        $loader = $this->factory->forType('yaml');
49
50
        $config = $loader->load(__DIR__ . '/../../examples/users');
51
        $this->assertArrayHasKey('admins', $config);
52
53
        $config = $loader->load(__DIR__ . '/failure/fail');
54
        $this->assertSame([], $config);
55
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
56
57
    public function testInvalidLoader()
58
    {
59
        $factory = new LoaderFactory([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
60
            'test' => \stdclass::class,
61
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
62
63
        $this->expectException(LoaderException::class);
64
        $this->expectExceptionCode(LoaderException::INVALID_LOADER);
65
66
        $loader = $factory->forType('test');
0 ignored issues
show
Unused Code introduced by
The assignment to $loader is dead and can be removed.
Loading history...
67
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
68
69
    public function testUnsupportedLoader()
70
    {
71
        $loader = Phony::mock(LoaderInterface::class);
72
        $loader = Phony::onStatic($loader);
73
        $loader->isSupported->returns(false);
74
75
        $factory = new LoaderFactory([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
76
            'test' => $loader->className(),
77
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
78
79
        $this->expectException(LoaderException::class);
80
        $this->expectExceptionCode(LoaderException::UNSUPPORTED_LOADER);
81
82
        $loader = $factory->forType('test');
0 ignored issues
show
Unused Code introduced by
The assignment to $loader is dead and can be removed.
Loading history...
83
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
84
}
85