-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitAuto: [FEATURE] Implement Queue
wrapper
#238
Changes from 40 commits
01b1c4b
f098462
0d63a91
b418af9
6d1acda
f9cd673
496a08e
990d820
ab3ac1e
df03a47
529f408
bf044e7
fb1b224
ce4ea94
5058da3
7195480
697e074
24dfd99
9cc9d43
b97a66f
f2828e0
ab9d590
84e540f
a686472
0bf3e60
2b30db6
1aa0f5f
6a8800f
d188175
2e1870a
0769a13
2538bad
31fe228
e26b29b
a6bb47c
d6a90eb
0066981
d59a930
ead501d
d68f670
f465f49
1598039
09d03b4
494beed
3645bf1
f8b5585
9d442ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
class Queue | ||
{ | ||
private $connectionStrings; | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line(s) before first member var; 0 found Warning
Expected 1 blank line(s) before first member var; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Missing member variable doc comment Warning
Missing member variable doc comment
|
||
|
||
public function __construct(array $servers) | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function __construct() Warning
Missing doc comment for function __construct()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines before function; 1 found Warning
Expected 2 blank lines before function; 1 found
|
||
{ | ||
$this->connectionStrings = $servers; | ||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end __construct() Warning
Expected //end __construct()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
|
||
|
||
private function declareQueueWithDLX($channel, $queueName) | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function declareQueueWithDLX() Warning
Missing doc comment for function declareQueueWithDLX()
|
||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$channel'.
|
||
{ | ||
// Existing implementation for declaring a queue with DLX | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end declareQueueWithDLX() Warning
Expected //end declareQueueWithDLX()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
|
||
|
||
private function declareQueueWithoutDLX($channel, $queueName) | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function declareQueueWithoutDLX() Warning
Missing doc comment for function declareQueueWithoutDLX()
|
||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$queueName'.
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$channel'.
|
||
{ | ||
// Implement declaration without DLX | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end declareQueueWithoutDLX() Warning
Expected //end declareQueueWithoutDLX()
|
||
|
||
public function publish($queueName, $message, $useDLX = true) | ||
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between argument "$useDLX" and equals sign; expected 0 but found 1 Warning
Incorrect spacing between argument "$useDLX" and equals sign; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between default value and equals sign for argument "$useDLX"; expected 0 but found 1 Warning
Incorrect spacing between default value and equals sign for argument "$useDLX"; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function publish() Warning
Missing doc comment for function publish()
|
||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$message'.
|
||
{ | ||
$connection = $this->getRandomConnection(); | ||
$channel = $connection->channel(); | ||
|
||
if ($useDLX) { | ||
Check warning Code scanning / Phpcs (reported by Codacy) Implicit true comparisons prohibited; use === TRUE instead Warning
Implicit true comparisons prohibited; use === TRUE instead
|
||
$this->declareQueueWithDLX($channel, $queueName); | ||
} else { | ||
Check warning Code scanning / Phpmd (reported by Codacy) Use return statements instead of else expression Warning
The method publish uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
|
||
$this->declareQueueWithoutDLX($channel, $queueName); | ||
} | ||
|
||
// Code to publish the message | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end publish() Warning
Expected //end publish()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
|
||
|
||
public function consume($timeout, $queueName, $callback, $resetTimeoutOnReceive = false, $prefetchCount = 10, $useDLX = true) | ||
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between default value and equals sign for argument "$useDLX"; expected 0 but found 1 Warning
Incorrect spacing between default value and equals sign for argument "$useDLX"; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between argument "$resetTimeoutOnReceive" and equals sign; expected 0 but found 1 Warning
Incorrect spacing between argument "$resetTimeoutOnReceive" and equals sign; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between argument "$prefetchCount" and equals sign; expected 0 but found 1 Warning
Incorrect spacing between argument "$prefetchCount" and equals sign; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between default value and equals sign for argument "$resetTimeoutOnReceive"; expected 0 but found 1 Warning
Incorrect spacing between default value and equals sign for argument "$resetTimeoutOnReceive"; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function consume() Warning
Missing doc comment for function consume()
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between argument "$useDLX" and equals sign; expected 0 but found 1 Warning
Incorrect spacing between argument "$useDLX" and equals sign; expected 0 but found 1
Check warning Code scanning / Phpcs (reported by Codacy) Incorrect spacing between default value and equals sign for argument "$prefetchCount"; expected 0 but found 1 Warning
Incorrect spacing between default value and equals sign for argument "$prefetchCount"; expected 0 but found 1
|
||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$timeout'.
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$resetTimeoutOnReceive'.
Check warning Code scanning / Phpmd (reported by Codacy) Detects when a field, local, or parameter has a very long name. Warning
Avoid excessively long variable names like $resetTimeoutOnReceive. Keep variable name length under 20.
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note
Avoid unused parameters such as '$callback'.
|
||
{ | ||
foreach ($this->connectionStrings as $server) { | ||
$connection = $this->getConnection($server); | ||
$channel = $connection->channel(); | ||
|
||
if ($useDLX) { | ||
Check warning Code scanning / Phpcs (reported by Codacy) Implicit true comparisons prohibited; use === TRUE instead Warning
Implicit true comparisons prohibited; use === TRUE instead
|
||
$this->declareQueueWithDLX($channel, $queueName); | ||
} else { | ||
Check warning Code scanning / Phpmd (reported by Codacy) Use return statements instead of else expression Warning
The method consume uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
|
||
$this->declareQueueWithoutDLX($channel, $queueName); | ||
} | ||
|
||
$channel->basic_qos(null, $prefetchCount, null); | ||
|
||
// Code to consume messages | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end consume() Warning
Expected //end consume()
|
||
|
||
private function getRandomConnection() | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function getRandomConnection() Warning
Missing doc comment for function getRandomConnection()
|
||
{ | ||
$randomServer = $this->connectionStrings[array_rand($this->connectionStrings)]; | ||
return $this->getConnection($randomServer); | ||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end getRandomConnection() Warning
Expected //end getRandomConnection()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
|
||
|
||
private function getConnection($server) | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function getConnection() Warning
Missing doc comment for function getConnection()
|
||
{ | ||
$options = ['connection_timeout' => 10.0, 'read_write_timeout' => 10.0]; | ||
Check warning Code scanning / Phpcs (reported by Codacy) Array with multiple values cannot be declared on a single line Warning
Array with multiple values cannot be declared on a single line
|
||
return AMQPStreamConnection::create_connection([$server], $options); | ||
Check warning Code scanning / Phpmd (reported by Codacy) Static access leads to hard to test code Warning
Avoid using static access to class 'AMQPStreamConnection' in method 'getConnection'.
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end getConnection() Warning
Expected //end getConnection()
|
||
|
||
// Additional methods and logic for the Queue class | ||
Check warning Code scanning / Phpcs (reported by Codacy) There must be no blank line following an inline comment Warning
There must be no blank line following an inline comment
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end class Warning
Expected //end class
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class QueueTest extends TestCase | ||
{ | ||
private $queue; | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line(s) before first member var; 0 found Warning test
Expected 1 blank line(s) before first member var; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Missing member variable doc comment Warning test
Missing member variable doc comment
|
||
|
||
protected function setUp(): void | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines before function; 1 found Warning test
Expected 2 blank lines before function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function setUp() Warning test
Missing doc comment for function setUp()
|
||
{ | ||
$servers = [ | ||
['host' => 'server1', 'port' => 5672, 'user' => 'guest', 'password' => 'guest'], | ||
Check warning Code scanning / Phpcs (reported by Codacy) Array value not aligned correctly; expected 20 spaces but found 12 Warning test
Array value not aligned correctly; expected 20 spaces but found 12
Check warning Code scanning / Phpcs (reported by Codacy) Array with multiple values cannot be declared on a single line Warning test
Array with multiple values cannot be declared on a single line
|
||
['host' => 'server2', 'port' => 5672, 'user' => 'guest', 'password' => 'guest'] | ||
Check warning Code scanning / Phpcs (reported by Codacy) Comma required after last value in array declaration Warning test
Comma required after last value in array declaration
Check warning Code scanning / Phpcs (reported by Codacy) Array with multiple values cannot be declared on a single line Warning test
Array with multiple values cannot be declared on a single line
Check warning Code scanning / Phpcs (reported by Codacy) Array value not aligned correctly; expected 20 spaces but found 12 Warning test
Array value not aligned correctly; expected 20 spaces but found 12
|
||
]; | ||
Check warning Code scanning / Phpcs (reported by Codacy) Closing parenthesis not aligned correctly; expected 19 spaces but found 8 Warning test
Closing parenthesis not aligned correctly; expected 19 spaces but found 8
|
||
$this->queue = new Queue($servers); | ||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning test
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end setUp() Warning test
Expected //end setUp()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning test
Expected 1 blank line before closing function brace; 0 found
|
||
|
||
public function testPublishWithDLX() | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function testPublishWithDLX() Warning test
Missing doc comment for function testPublishWithDLX()
|
||
{ | ||
$this->queue->publish('testQueue', 'testMessage', true); | ||
// Assertions to verify message was published with DLX | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end testPublishWithDLX() Warning test
Expected //end testPublishWithDLX()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning test
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning test
Expected 1 blank line before closing function brace; 0 found
|
||
|
||
public function testPublishWithoutDLX() | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function testPublishWithoutDLX() Warning test
Missing doc comment for function testPublishWithoutDLX()
|
||
{ | ||
$this->queue->publish('testQueue', 'testMessage', false); | ||
// Assertions to verify message was published without DLX | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning test
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning test
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end testPublishWithoutDLX() Warning test
Expected //end testPublishWithoutDLX()
|
||
|
||
public function testConsumeWithDLX() | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function testConsumeWithDLX() Warning test
Missing doc comment for function testConsumeWithDLX()
|
||
{ | ||
$callback = function ($msg) { | ||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note test
Avoid unused parameters such as '$msg'.
|
||
// Process message | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
}; | ||
$this->queue->consume(30, 'testQueue', $callback, false, 10, true); | ||
// Assertions to verify messages are consumed with DLX | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning test
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end testConsumeWithDLX() Warning test
Expected //end testConsumeWithDLX()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning test
Expected 2 blank lines after function; 1 found
|
||
|
||
public function testConsumeWithoutDLX() | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function testConsumeWithoutDLX() Warning test
Missing doc comment for function testConsumeWithoutDLX()
|
||
{ | ||
$callback = function ($msg) { | ||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note test
Avoid unused parameters such as '$msg'.
|
||
// Process message | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
}; | ||
$this->queue->consume(30, 'testQueue', $callback, false, 10, false); | ||
// Assertions to verify messages are consumed without DLX | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning test
Expected 1 blank line before closing function brace; 0 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end testConsumeWithoutDLX() Warning test
Expected //end testConsumeWithoutDLX()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning test
Expected 2 blank lines after function; 1 found
|
||
|
||
public function testConsumeWithDifferentQoS() | ||
Check warning Code scanning / Phpcs (reported by Codacy) Missing doc comment for function testConsumeWithDifferentQoS() Warning test
Missing doc comment for function testConsumeWithDifferentQoS()
|
||
{ | ||
$callback = function ($msg) { | ||
Check notice Code scanning / Phpmd (reported by Codacy) Prohibit the definition of unused parameters on methods or constructors Note test
Avoid unused parameters such as '$msg'.
|
||
// Process message | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
}; | ||
$this->queue->consume(30, 'testQueue', $callback, false, 5, true); | ||
// Assertions to verify messages are consumed with different QoS settings | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected 2 blank lines after function; 1 found Warning test
Expected 2 blank lines after function; 1 found
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end testConsumeWithDifferentQoS() Warning test
Expected //end testConsumeWithDifferentQoS()
Check warning Code scanning / Phpcs (reported by Codacy) Expected 1 blank line before closing function brace; 0 found Warning test
Expected 1 blank line before closing function brace; 0 found
|
||
|
||
// Additional test cases | ||
Check warning Code scanning / Phpcs (reported by Codacy) Inline comments must end in full-stops, exclamation marks, or question marks Warning test
Inline comments must end in full-stops, exclamation marks, or question marks
Check warning Code scanning / Phpcs (reported by Codacy) There must be no blank line following an inline comment Warning test
There must be no blank line following an inline comment
|
||
|
||
} | ||
Check warning Code scanning / Phpcs (reported by Codacy) Expected //end class Warning test
Expected //end class
|
Check notice
Code scanning / Phpmd (reported by Codacy)
Prohibit the definition of unused parameters on methods or constructors Note