DbTest.php 1.3 KB

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