QueueTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace think\test\queue;
  3. use InvalidArgumentException;
  4. use Mockery as m;
  5. use think\Config;
  6. use think\Queue;
  7. use think\queue\connector\Sync;
  8. class QueueTest extends TestCase
  9. {
  10. /** @var Queue */
  11. protected $queue;
  12. protected function setUp()
  13. {
  14. parent::setUp();
  15. $this->queue = new Queue($this->app);
  16. }
  17. public function testDefaultConnectionCanBeResolved()
  18. {
  19. $sync = new Sync();
  20. $this->app->shouldReceive('invokeClass')->once()->with('\think\queue\connector\Sync', [['driver' => 'sync']])->andReturn($sync);
  21. $config = m::mock(Config::class);
  22. $config->shouldReceive('get')->twice()->with('queue.connectors.sync', ['driver' => 'sync'])->andReturn(['driver' => 'sync']);
  23. $config->shouldReceive('get')->once()->with('queue.default', 'sync')->andReturn('sync');
  24. $this->app->shouldReceive('get')->times(3)->with('config')->andReturn($config);
  25. $this->assertSame($sync, $this->queue->driver('sync'));
  26. $this->assertSame($sync, $this->queue->driver());
  27. }
  28. public function testNotSupportDriver()
  29. {
  30. $config = m::mock(Config::class);
  31. $config->shouldReceive('get')->once()->with('queue.connectors.hello', ['driver' => 'sync'])->andReturn(['driver' => 'hello']);
  32. $this->app->shouldReceive('get')->once()->with('config')->andReturn($config);
  33. $this->expectException(InvalidArgumentException::class);
  34. $this->queue->driver('hello');
  35. }
  36. }