Completed
Push — master ( e02e4d...5773dd )
by
unknown
02:54 queued 11s
created

DelayServiceTest.php$0 ➔ getInterval()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\QueueBundle\Tests\Unit\Service;
6
7
use DateInterval;
8
use DateTime;
9
use Lamoda\QueueBundle\Entity\QueueEntityInterface;
10
use Lamoda\QueueBundle\Service\DelayService;
11
use Lamoda\QueueBundle\Service\DelayStrategyResolver;
12
use Lamoda\QueueBundle\Tests\Unit\QueueEntity;
13
use Lamoda\QueueBundle\Tests\Unit\SymfonyMockTrait;
14
use PHPUnit_Framework_TestCase;
15
use Psr\Log\LoggerInterface;
16
17
class DelayServiceTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Bug introduced by
There is one abstract method getMockBuilder in this class; you could implement it, or declare this class as abstract.
Loading history...
18
{
19
    use SymfonyMockTrait, DelayStrategyResolverTrait;
20
21
    /**
22
     * @param QueueEntityInterface $queue
23
     * @param QueueEntityInterface $expectedQueue
24
     * @param DateTime             $dateTime
25
     *
26
     * @dataProvider dataDelayQueue
27
     */
28
    public function testDelayQueue(
29
        QueueEntityInterface $queue,
30
        QueueEntityInterface $expectedQueue,
31
        DateTime $dateTime,
32
        DelayStrategyResolver $strategyService,
33
        LoggerInterface $logger
34
    ): void {
35
        /** @var DelayService | \PHPUnit_Framework_MockObject_MockObject $delayService */
36
        $delayService = $this->getMockBuilder(DelayService::class)
37
            ->setConstructorArgs([$strategyService, $logger])
38
            ->setMethods(['getStartDateTime'])
39
            ->getMock();
40
        $delayService->method('getStartDateTime')
41
            ->willReturn($dateTime);
42
43
        $actualQueue = $delayService->delayQueue($queue);
44
        $this->assertEquals($expectedQueue, $actualQueue);
45
    }
46
47
    /**
48
     * @return array
49
     * @throws \Exception
50
     *
51
     */
52
    public function dataDelayQueue(): \Generator
53
    {
54
        $strategyService = $this->createDelayStrategyResolver([]);
55
        $logger          = $this->getMockLogger();
56
        $dateTime        = new DateTime();
57
        $queue           = $this->createQueue();
58
        $expected        = clone $queue;
59
        $expected->setWaiting($dateTime->add(new DateInterval('PT60S')));
60
61
        yield 'With valid strategy key' => [
62
            $queue,
63
            $expected,
64
            $dateTime,
65
            $strategyService,
66
            $logger,
67
        ];
68
69
        $strategyService = $this->createDelayStrategyResolver([$queue->getName() => 'unknown_strategy_key']);
70
        $logger          = $this->getMockLogger(['warning']);
71
        $logger->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Psr\Log\LoggerInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
            ->method('warning')
73
            ->with(
74
                'Delay strategy with key: unknown_strategy_key doesn\'t exist', [
75
                'queue_name' => $queue->getName(),
76
            ]
77
            );
78
        $dateTime = new DateTime();
79
        $queue    = $this->createQueue();
80
        $expected = clone $queue;
81
        $expected->setWaiting($dateTime->add(new DateInterval('PT60S')));
82
83
        yield 'With invalid strategy key warning' => [
84
            $queue,
85
            $expected,
86
            $dateTime,
87
            $strategyService,
88
            $logger,
89
        ];
90
    }
91
92
    private function createQueue(): QueueEntity
93
    {
94
        return new QueueEntity('queue', 'exchange', 'ClassJob', []);
95
    }
96
97
}
98