Test Failed
Push — master ( 90f1e5...8cd561 )
by Jim
02:25
created

SampleServiceProvider   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 10
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 8 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/13/2018
6
 * Time: 8:02 PM
7
 */
8
9
namespace TimSDK\Tests\Foundation;
10
11
use Monolog\Logger;
12
use Pimple\Container;
13
use TimSDK\Container\ServiceContainer;
14
use TimSDK\Foundation\Application;
15
use TimSDK\Foundation\ServiceProviders\ServiceProvider;
16
use TimSDK\Tests\TestCase;
17
18
class ApplicationTest extends TestCase
19
{
20
    public function testContainerBinding()
21
    {
22
        $app = new Application([
23
            'foo' => 'bar',
24
        ], [
25
            'bar' => function () {
26
                return new \stdClass();
27
            },
28
            'name' => 'TimSDK',
29
            'foo'  => 'Jim'
30
        ]);
31
32
        $app['foo'] = function () {
33
            return 'bar';
34
        };
35
36
        $this->assertEquals('bar', $app['foo']);
37
        $this->assertEquals('TimSDK', $app['name']);
38
        $this->assertInstanceOf(\stdClass::class, $app['bar']);
39
        $this->assertSame($app['bar'], $app['bar']);
40
    }
41
42
    public function testContainerServiceProvider()
43
    {
44
        $app = new SampleApplication();
45
46
        $this->assertEquals('foo', $app['bar']);
47
        $this->assertInstanceOf(\stdClass::class, $app['foo']);
48
        $this->assertSame($app['foo'], $app['foo']);
49
    }
50
51
    public function testContainerConfig()
52
    {
53
        $app = new Application([
54
            'foo' => 'bar',
55
        ]);
56
57
        $this->assertEquals('bar', $app['config']->get('foo'));
58
    }
59
60
    public function testGetContainerSelf()
61
    {
62
        $app = new Application();
63
64
        $this->assertInstanceOf(ServiceContainer::class, $app['app']);
65
        $this->assertInstanceOf(ServiceContainer::class, $app[ServiceContainer::class]);
66
    }
67
68
    public function testGetLogService()
69
    {
70
        $app = new Application();
71
72
        $this->assertInstanceOf(Logger::class, $app['log']);
73
        $this->assertInstanceOf(Logger::class, $app['logger']);
74
    }
75
}
76
77
class SampleApplication extends Application
78
{
79
    protected $providers = [
80
        SampleServiceProvider::class
81
    ];
82
}
83
84
class SampleServiceProvider extends ServiceProvider
85
{
86
    public function register(Container $pimple)
87
    {
88
        $pimple['bar'] = function () {
89
            return 'foo';
90
        };
91
92
        $pimple['foo'] = function () {
93
            return new \stdClass();
94
        };
95
    }
96
}
97