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

ContainerTest::testGetFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
}