ConfigFileTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 61
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A creation() 0 8 1
A applyVariables() 0 8 1
A mergeArray() 0 8 1
A parseEmptyFile() 0 8 1
A invalidFileThrowsException() 0 4 1
1
<?php
2
/*
3
 * this file is part of magerun
4
 *
5
 * @author Tom Klingenberg <https://github.com/ktomk>
6
 */
7
8
namespace N98\Magento\Application;
9
10
use InvalidArgumentException;
11
use MongoDB\Driver\Exception\RuntimeException;
12
use N98\Magento\Command\PHPUnit\TestCase;
13
14
/**
15
 * Class ConfigFileTest
16
 *
17
 * @covers  N98\Magento\Application\ConfigFile
18
 * @package N98\Magento\Application
19
 */
20
class ConfigFileTest extends TestCase
21
{
22
    /**
23
     * @test
24
     */
25
    public function creation()
26
    {
27
        $configFile = new ConfigFile();
28
        $this->assertInstanceOf('\N98\Magento\Application\ConfigFile', $configFile);
29
30
        $configFile = ConfigFile::createFromFile(__FILE__);
31
        $this->assertInstanceOf('\N98\Magento\Application\ConfigFile', $configFile);
32
    }
33
34
    /**
35
     * @test
36
     */
37
    public function applyVariables()
38
    {
39
        $configFile = new ConfigFile();
40
        $configFile->loadFile('data://,- %root%');
41
        $configFile->applyVariables("root-folder");
42
43
        $this->assertSame(['root-folder'], $configFile->toArray());
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function mergeArray()
50
    {
51
        $configFile = new ConfigFile();
52
        $configFile->loadFile('data://,- bar');
53
        $result = $configFile->mergeArray(['foo']);
54
55
        $this->assertSame(['foo', 'bar'], $result);
56
    }
57
58
    /**
59
     * @test
60
     * @expectedException RuntimeException
61
     * @expectedExceptionMessage Failed to parse config-file 'data://,'
62
     */
63
    public function parseEmptyFile()
64
    {
65
        $configFile = new ConfigFile();
66
        $configFile->loadFile('data://,');
67
        $this->addToAssertionCount(1);
68
        $configFile->toArray();
69
        $this->fail('An expected exception has not been thrown.');
70
    }
71
72
    /**
73
     * @test
74
     * @expectedException InvalidArgumentException
75
     */
76
    public function invalidFileThrowsException()
77
    {
78
        @ConfigFile::createFromFile(":");
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
79
    }
80
}
81