Completed
Branch 6.0 (d30585)
by yun
04:17
created

DbTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 2
1
<?php
2
3
namespace think\tests;
4
5
use Mockery as m;
6
use PHPUnit\Framework\TestCase;
7
use think\Cache;
8
use think\Config;
9
use think\Db;
10
use think\Event;
11
use think\Log;
12
13
class DbTest extends TestCase
14
{
15
    protected function tearDown(): void
16
    {
17
        m::close();
18
    }
19
20
    public function testMake()
21
    {
22
        $event  = m::mock(Event::class);
23
        $config = m::mock(Config::class);
24
        $log    = m::mock(Log::class);
25
        $cache  = m::mock(Cache::class);
26
27
        $db = Db::__make($event, $config, $log, $cache);
28
29
        $config->shouldReceive('get')->with('database.foo', null)->andReturn('foo');
30
        $this->assertEquals('foo', $db->getConfig('foo'));
31
32
        $config->shouldReceive('get')->with('database', [])->andReturn([]);
33
        $this->assertEquals([], $db->getConfig());
34
35
        $callback = function () {
36
        };
37
        $event->shouldReceive('listen')->with('db.some', $callback);
38
        $db->event('some', $callback);
39
40
        $event->shouldReceive('trigger')->with('db.some', null, false);
41
        $db->trigger('some');
42
    }
43
44
}
45