-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathDbTest.php
49 lines (38 loc) · 1.26 KB
/
DbTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace think\tests;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use think\Cache;
use think\cache\Driver;
use think\Config;
use think\Db;
use think\Event;
use think\Log;
class DbTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function testMake()
{
$event = m::mock(Event::class);
$config = m::mock(Config::class);
$log = m::mock(Log::class);
$cache = m::mock(Cache::class);
$store = m::mock(Driver::class);
$config->shouldReceive('get')->with('database.cache_store', null)->andReturn(null);
$cache->shouldReceive('store')->with(null)->andReturn($store);
$db = Db::__make($event, $config, $log, $cache);
$config->shouldReceive('get')->with('database.foo', null)->andReturn('foo');
$this->assertEquals('foo', $db->getConfig('foo'));
$config->shouldReceive('get')->with('database', [])->andReturn([]);
$this->assertEquals([], $db->getConfig());
$callback = function () {
};
$event->shouldReceive('listen')->with('db.some', $callback);
$db->event('some', $callback);
$event->shouldReceive('trigger')->with('db.some', null, false);
$db->trigger('some');
}
}