Passed
Branch master (e8fd46)
by Alexey
03:15
created

ConfigFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use Venta\Config\ConfigFactory;
5
use Venta\Contracts\Config\Config;
6
7
class ConfigFactoryTest extends TestCase
8
{
9
10
    /**
11
     * @test
12
     */
13
    public function canCreateFromJson()
14
    {
15
        $factory = new ConfigFactory();
16
        $config = $factory->createFromFile(__DIR__ . '/config.json');
17
18
        $this->assertInstanceOf(Config::class, $config);
19
        $this->assertSame('value', $config->get('key'));
20
    }
21
22
    /**
23
     * @test
24
     */
25
    public function canIncludePhpFile()
26
    {
27
        $factory = new ConfigFactory();
28
        $config = $factory->createFromFile(__DIR__ . '/config.php');
29
30
        $this->assertInstanceOf(Config::class, $config);
31
        $this->assertSame('value', $config->get('key'));
32
    }
33
34
    /**
35
     * @test
36
     * @expectedException InvalidArgumentException
37
     */
38
    public function throwsExceptionOnInvalidFile()
39
    {
40
        $factory = new ConfigFactory();
41
        $config = $factory->createFromFile(__DIR__ . '/non_existing_file');
42
    }
43
44
    /**
45
     * @test
46
     * @expectedException RuntimeException
47
     */
48
    public function throwsExceptionOnUnknownConfigFormat()
49
    {
50
        $factory = new ConfigFactory();
51
        $config = $factory->createFromFile(__DIR__ . '/stub.qwerty');
52
    }
53
54
}
55