-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsumeCommandTest.php
More file actions
96 lines (76 loc) · 2.99 KB
/
Copy pathConsumeCommandTest.php
File metadata and controls
96 lines (76 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Tests\Integration;
use ADT\BackgroundQueue\Broker\PhpAmqpLib\Consumer;
use ADT\BackgroundQueue\Broker\PhpAmqpLib\Manager;
use ADT\BackgroundQueue\Console\ConsumeCommand;
use Codeception\AssertThrows;
use ADT\BackgroundQueue\BackgroundQueue;
use Codeception\Test\Unit;
use Doctrine\DBAL\DriverManager;
use Tests\Support\Helper\Producer;
use Tests\Support\IntegrationTester;
class ConsumeCommandTest extends Unit
{
use AssertThrows;
protected IntegrationTester $tester;
private static ?Producer $producer = null;
public function providerGetPrioritiesListBasedConfig_ok() {
return [
[[10, 15, 20, 25, 30, 35, 40], '20-30', [20, 25, 30]],
[[10, 15, 20, 25, 30, 35, 40], '-30', [10, 15, 20, 25, 30]],
[[10, 15, 20, 25, 30, 35, 40], '20-', [20, 25, 30, 35, 40]],
[[10, 15, 20, 25, 30, 35, 40], null, [10, 15, 20, 25, 30, 35, 40]],
];
}
/**
* @dataProvider providerGetPrioritiesListBasedConfig_ok
*/
public function testGetPrioritiesListBasedConfig_ok(array $prioritiesAll, ?string $priorityParameter, array $prioritiesExpected) {
$consumeCommand = $this->getConsumeCommand($prioritiesAll);
$reflector = new \ReflectionObject($consumeCommand);
$method = $reflector->getMethod('getPrioritiesListBasedConfig');
$method->setAccessible(true);
$priorities = $method->invoke($consumeCommand, $priorityParameter);
$this->tester->assertEquals($prioritiesExpected, $priorities);
}
public function providerGetPrioritiesListBasedConfig_error() {
return [
[[10, 15, 20, 25, 30, 35, 40], '5', 'Priority 5 is not in available priorities [10,15,20,25,30,35,40]'],
[[10, 30, 35, 40], '20-25', 'Priority 20-25 has not intersections with availables priorities [10,30,35,40]'],
];
}
/**
* @dataProvider providerGetPrioritiesListBasedConfig_error
*/
public function testGetPrioritiesListBasedConfig_error(array $prioritiesAll, ?string $priorityParameter, string $exceptionExpected) {
$consumeCommand = $this->getConsumeCommand($prioritiesAll);
$reflector = new \ReflectionObject($consumeCommand);
$method = $reflector->getMethod('getPrioritiesListBasedConfig');
$method->setAccessible(true);
try {
$method->invoke($consumeCommand, $priorityParameter);
} catch (\Exception $e) {
$this->tester->assertEquals($exceptionExpected, $e->getMessage());
return;
}
$this->tester->fail('...');
}
private function getConsumeCommand(array $prioritiesAll): ConsumeCommand {
$backgroundQueue = new BackgroundQueue([
'queue' => 'general',
'priorities' => $prioritiesAll,
'connection' => DriverManager::getConnection(BackgroundQueue::parseDsn(self::getDsn())),
'logger' => null,
'producer' => null
]);
$consumer = new Consumer(
new Manager([], []),
$backgroundQueue
);
return new ConsumeCommand($consumer, $backgroundQueue);
}
private static function getDsn()
{
return 'mysql://' . $_ENV['PROJECT_DB_USER'] . ':' . $_ENV['PROJECT_DB_PASSWORD'] . '@' . $_ENV['PROJECT_DB_HOST'] . ':' . $_ENV['PROJECT_DB_PORT'] . '/' . $_ENV['PROJECT_DB_DBNAME'];
}
}