/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Queue/QueuePauseResumeTest.php
194 строки
6 KB
Jason McCreary
[13.x] Mockery cleanup (#61117)
10 авг 2026, 20:23
Не верифицирован
10 авг 2026, 20:23
2ee40ee
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Queue; use Illuminate\Cache\ArrayStore; use Illuminate\Cache\Repository; use Illuminate\Events\Dispatcher; use Illuminate\Queue\Console\Concerns\ParsesQueue; use Illuminate\Queue\Events\QueuePaused; use Illuminate\Queue\Events\QueueResumed; use Illuminate\Queue\QueueManager; use Illuminate\Support\Carbon; use Mockery; use PHPUnit\Framework\TestCase; class QueuePauseResumeTest extends TestCase { protected $manager; protected $cache; protected function setUp(): void { $this->cache = new Repository(new ArrayStore); // Mock the cache facade to return our cache repository $cacheMock = Mockery::mock(); $cacheMock->shouldReceive('store')->andReturn($this->cache); $app = [ 'config' => [ 'queue.default' => 'redis', 'queue.connections.redis' => ['driver' => 'redis'], 'queue.connections.database' => ['driver' => 'database'], ], 'cache' => $cacheMock, 'events' => new Dispatcher(), ]; $this->manager = new QueueManager($app); } public function testPauseQueueWithConnection() { $this->manager->pause('redis', 'default'); $this->assertTrue($this->manager->isPaused('redis', 'default')); } public function testPauseQueueWithTTL() { $this->manager->pauseFor('redis', 'default', 30); $this->assertTrue($this->manager->isPaused('redis', 'default')); Carbon::setTestNow(Carbon::now()->addMinute()); $this->assertFalse($this->manager->isPaused('redis', 'default')); } public function testPauseQueueIndefinitely() { $this->manager->pause('redis', 'default'); $this->assertTrue($this->manager->isPaused('redis', 'default')); Carbon::setTestNow(Carbon::now()->addYear()); $this->assertTrue($this->manager->isPaused('redis', 'default')); } public function testResumeQueue() { $this->manager->pause('redis', 'default'); $this->assertTrue($this->manager->isPaused('redis', 'default')); $this->manager->resume('redis', 'default'); $this->assertFalse($this->manager->isPaused('redis', 'default')); } public function testPausingQueueOnOneConnectionDoesNotAffectAnother() { $this->manager->pause('redis', 'default'); $this->assertTrue($this->manager->isPaused('redis', 'default')); $this->assertFalse($this->manager->isPaused('database', 'default')); } public function testPausingDifferentQueuesOnSameConnection() { $this->manager->pause('redis', 'emails'); $this->manager->pause('redis', 'notifications'); $this->assertTrue($this->manager->isPaused('redis', 'emails')); $this->assertTrue($this->manager->isPaused('redis', 'notifications')); $this->assertFalse($this->manager->isPaused('redis', 'default')); } public function testResumingOnlyAffectsSpecificQueue() { $this->manager->pause('redis', 'emails'); $this->manager->pause('redis', 'notifications'); $this->manager->resume('redis', 'emails'); $this->assertFalse($this->manager->isPaused('redis', 'emails')); $this->assertTrue($this->manager->isPaused('redis', 'notifications')); } public function testPauseDispatchesQueuePausedEvent() { $dispatchedEvent = null; $dispatcher = $this->manager->getApplication()['events']; $dispatcher->listen(QueuePaused::class, function ($event) use (&$dispatchedEvent) { $dispatchedEvent = $event; }); $this->manager->pause('redis', 'default'); $this->assertInstanceOf(QueuePaused::class, $dispatchedEvent); $this->assertSame('redis', $dispatchedEvent->connection); $this->assertSame('default', $dispatchedEvent->queue); $this->assertNull($dispatchedEvent->ttl); } public function testPauseForDispatchesQueuePausedEventWithTTL() { $dispatchedEvent = null; $dispatcher = $this->manager->getApplication()['events']; $dispatcher->listen(QueuePaused::class, function ($event) use (&$dispatchedEvent) { $dispatchedEvent = $event; }); $this->manager->pauseFor('redis', 'emails', 60); $this->assertInstanceOf(QueuePaused::class, $dispatchedEvent); $this->assertSame('redis', $dispatchedEvent->connection); $this->assertSame('emails', $dispatchedEvent->queue); $this->assertSame(60, $dispatchedEvent->ttl); } public function testResumeDispatchesQueueResumedEvent() { $dispatchedEvent = null; $dispatcher = $this->manager->getApplication()['events']; $dispatcher->listen(QueueResumed::class, function ($event) use (&$dispatchedEvent) { $dispatchedEvent = $event; }); $this->manager->resume('database', 'notifications'); $this->assertInstanceOf(QueueResumed::class, $dispatchedEvent); $this->assertSame('database', $dispatchedEvent->connection); $this->assertSame('notifications', $dispatchedEvent->queue); } public function testGetPausedQueues() { $this->assertSame([], $this->manager->getPausedQueues('redis', ['default', 'emails'])); $this->manager->pause('redis', 'emails'); $this->manager->pause('redis', 'notifications'); $this->assertSame( ['emails', 'notifications'], $this->manager->getPausedQueues('redis', ['default', 'emails', 'notifications']) ); } public function testParsingQueueString() { $parser = new class() { use ParsesQueue; private array $laravel = [ 'config' => ['queue.default' => 'redis'], ]; public function parse(string $queue) { return $this->parseQueue($queue); } }; $this->assertSame(['redis', 'default'], $parser->parse('')); $this->assertSame(['redis', 'emails'], $parser->parse('emails')); $this->assertSame(['database', 'notifications'], $parser->parse('database:notifications')); $this->assertSame(['redis', 'foo:bar'], $parser->parse('redis:foo:bar')); } }