Completed
Push — master ( d055c4...9f7aba )
by timegryd
04:27
created

ConfigurationTest::testEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Timegryd\OpcacheResetBundle\Tests\DependencyInjection;
4
5
use Symfony\Component\Config\Definition\Processor;
6
use Timegryd\OpcacheResetBundle\DependencyInjection\Configuration;
7
8
class ConfigurationTest extends \PHPUnit\Framework\TestCase
9
{
10
    protected function setUp()
11
    {
12
        $this->configuration = new Configuration();
0 ignored issues
show
Bug introduced by
The property configuration does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
        $this->processor = new Processor();
0 ignored issues
show
Bug introduced by
The property processor does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
14
    }
15
16
    /**
17
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
18
     */
19
    public function testEmpty()
20
    {
21
        $this->processor->processConfiguration($this->configuration, []);
22
    }
23
24
    /**
25
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
26
     */
27
    public function testHostRequired()
28
    {
29
        $this->processor->processConfiguration($this->configuration, [
30
            'timegryd-opcache-reset' => [],
31
        ]);
32
    }
33
34
    /**
35
     * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
36
     */
37
    public function testDirRequired()
38
    {
39
        $this->processor->processConfiguration($this->configuration, [
40
            'timegryd-opcache-reset' => [
41
                'host' => 'example.com',
42
            ],
43
        ]);
44
    }
45
46
    public function testSuccess()
47
    {
48
        $actual = $this->processor->processConfiguration($this->configuration, [
49
            'timegryd_opcache_reset' => [
50
                'host' => 'example.com',
51
                'dir' => 'web-dir',
52
            ],
53
        ]);
54
55
        $expected = [
56
            'host' => 'example.com',
57
            'dir' => 'web-dir',
58
        ];
59
60
        $this->assertEquals($expected, $actual);
61
    }
62
}
63