Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Commit

Permalink
fix delay queue saving (#12)
Browse files Browse the repository at this point in the history
Fix delay queue saving
  • Loading branch information
medliii committed Feb 11, 2020
1 parent 51c8d98 commit 38822ba
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Service/QueueService.php
Expand Up @@ -125,7 +125,9 @@ public function getToRepublish(int $limit, ?int $offset = null): array
*/
public function createQueue(QueueInterface $queueable): QueueEntityInterface
{
return $this->entityFactory->createQueue($queueable);
$queue = $this->entityFactory->createQueue($queueable);

return $this->save($queue);
}

public function flush(QueueEntityInterface $entity = null): void
Expand Down
38 changes: 38 additions & 0 deletions tests/unit/Service/QueueServiceTest.php
Expand Up @@ -4,17 +4,22 @@

namespace Lamoda\QueueBundle\Tests\Unit\Service;

use DateTime;
use Lamoda\QueueBundle\Entity\QueueRepository;
use Lamoda\QueueBundle\Event\QueueAttemptsReachedEvent;
use Lamoda\QueueBundle\Exception\AttemptsReachedException;
use Lamoda\QueueBundle\Exception\UnexpectedValueException;
use Lamoda\QueueBundle\Factory\EntityFactory;
use Lamoda\QueueBundle\Publisher;
use Lamoda\QueueBundle\Service\DelayService;
use Lamoda\QueueBundle\Service\QueueService;
use Lamoda\QueueBundle\Tests\Unit\Job\StubJob;
use Lamoda\QueueBundle\Tests\Unit\QueueCommonServicesTrait;
use Lamoda\QueueBundle\Tests\Unit\QueueEntity;
use Lamoda\QueueBundle\Tests\Unit\SymfonyMockTrait;
use OldSound\RabbitMqBundle\RabbitMq\Producer;
use PHPUnit_Framework_TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcher;

class QueueServiceTest extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -183,6 +188,39 @@ public function testCreateQueue(): void
);
}

public function testSavingScheduledQueue(): void
{
$dateTime = new DateTime();
$job = new StubJob(1);
$queue = new QueueEntity('queue', 'exchange', StubJob::class, ['id' => 1]);
$queue->setScheduled($dateTime);

$queueRepository = $this->getQueueRepository();
$queueRepository
->expects($this->once())
->method('save')
->with($queue)
->willReturnArgument(0);

$entityFactory = $this->getEntityFactory();
$entityFactory
->expects($this->once()) #at least once
->method('createQueue')
->willReturn($queue);

$queueService = $this->createService($queueRepository, $entityFactory);
$publisher = new Publisher(
$this->createMock(Producer::class),
$queueService,
new NullLogger(),
$this->createMock(DelayService::class)
);

$createdQueue = $queueService->createQueue($job);
$publisher->prepareQueueForPublish($createdQueue);
$publisher->release();
}

public function testIsTransactionActive(): void
{
$expected = true;
Expand Down

0 comments on commit 38822ba

Please sign in to comment.