Passed
Push — master ( 6ae56f...fedcd1 )
by Phillip
01:31
created

ContainerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetGet() 0 8 1
A testSetFail() 0 6 1
A testExtend() 0 8 1
A testGetFail() 0 5 1
1
<?php
2
3
4
namespace Deployee\Components\Container;
5
6
7
use PHPUnit\Framework\TestCase;
8
9
class ContainerTest extends TestCase
10
{
11
    public function testSetGet()
12
    {
13
        $container = new Container(['foo' => 1, 'bar' => function(){return 'foobar';}]);
14
        $container->set('barfoo', new \stdClass());
15
16
        $this->assertSame(1, $container->get('foo'));
17
        $this->assertSame('foobar', $container->get('bar'));
18
        $this->assertInstanceOf(\stdClass::class, $container->get('barfoo'));
19
    }
20
21
    public function testSetFail()
22
    {
23
        $container = new Container(['foo' => 1]);
24
25
        $this->expectException(ContainerException::class);
26
        $container->set('foo', 2);
27
    }
28
29
    public function testGetFail()
30
    {
31
        $container = new Container();
32
        $this->expectException(ContainerException::class);
33
        $container->get('foo');
34
    }
35
36
    public function testExtend()
37
    {
38
        $container = new Container(['foo' => 1, 'addtofoo' => 5]);
39
        $container->extend('foo', function($value, ContainerInterface $c){
40
            return $value + $c->get('addtofoo');
41
        });
42
43
        $this->assertSame(6, $container->get('foo'));
44
    }
45
}