Passed
Push — master ( 0c3f71...c8d0a7 )
by Phillip
02:28
created

ContainerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetGet() 0 8 1
A testExtend() 0 8 1
A testSetFail() 0 6 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 testExtend()
30
    {
31
        $container = new Container(['foo' => 1, 'addtofoo' => 5]);
32
        $container->extend('foo', function($value, ContainerInterface $c){
33
            return $value + $c->get('addtofoo');
34
        });
35
36
        $this->assertSame(6, $container->get('foo'));
37
    }
38
}