DbTest.php 1.0 KB

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