1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lamoda\QueueBundle\Tests\Unit\Service; |
6
|
|
|
|
7
|
|
|
use Lamoda\QueueBundle\Exception\UnknownStrategyKeyException; |
8
|
|
|
use Lamoda\QueueBundle\Strategy\Delay\ArithmeticProgressionStrategy; |
9
|
|
|
use Lamoda\QueueBundle\Strategy\Delay\GeometricProgressionStrategy; |
10
|
|
|
use PHPUnit_Framework_TestCase; |
11
|
|
|
|
12
|
|
|
class DelayStrategyResolverTest extends PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
use DelayStrategyResolverTrait; |
15
|
|
|
|
16
|
|
View Code Duplication |
public function testGetStrategy() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$checkingQueueName = 'queue'; |
19
|
|
|
$strategiesByQueues = ['queue' => 'arithmetic_strategy_key']; |
20
|
|
|
|
21
|
|
|
$resolver = $this->createDelayStrategyResolver($strategiesByQueues); |
22
|
|
|
$strategy = $resolver->getStrategy($checkingQueueName); |
23
|
|
|
$this->assertInstanceOf(ArithmeticProgressionStrategy::class, $strategy); |
24
|
|
|
$this->assertAttributeEquals(100, 'startInterval', $strategy); |
25
|
|
|
$this->assertAttributeEquals(4, 'multiplier', $strategy); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testGetDefaultStrategy() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$checkingQueueName = 'queue'; |
31
|
|
|
$strategiesByQueues = []; |
32
|
|
|
|
33
|
|
|
$resolver = $this->createDelayStrategyResolver($strategiesByQueues); |
34
|
|
|
$strategy = $resolver->getStrategy($checkingQueueName); |
35
|
|
|
$this->assertInstanceOf(GeometricProgressionStrategy::class, $strategy); |
36
|
|
|
$this->assertAttributeEquals(60, 'startInterval', $strategy); |
37
|
|
|
$this->assertAttributeEquals(3, 'multiplier', $strategy); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testFailGetDefaultStrategy() |
41
|
|
|
{ |
42
|
|
|
$this->expectException(UnknownStrategyKeyException::class); |
43
|
|
|
$checkingQueueName = 'queue'; |
44
|
|
|
$strategiesByQueues = ['queue' => 'unknown_strategy_key']; |
45
|
|
|
|
46
|
|
|
$resolver = $this->createDelayStrategyResolver($strategiesByQueues); |
47
|
|
|
$resolver->getStrategy($checkingQueueName); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.