-
Notifications
You must be signed in to change notification settings - Fork 0
Implemented driver for Pheanstalk 4 #2
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d13b5a
Implemented driver for Pheanstalk 4
SamMousa bb0662e
Use interface_exists to check for pheanstalk 4
SamMousa ebf0c02
Prepared test structure to test other drivers as well
SamMousa 3f7640e
Fixed tests for php 5.6
SamMousa 611cb3e
Enable code coverage
SamMousa 7ab263d
Install beanstalkd
SamMousa 7c93572
Store totalcount before test
SamMousa af103b3
Grab the total count instead of current
SamMousa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| tools: | ||
| external_code_coverage: true | ||
| build: | ||
| nodes: | ||
| analysis: | ||
| tests: | ||
| override: | ||
| - php-scrutinizer-run | ||
| filter: | ||
| excluded_paths: | ||
| - "tests/_support/_generated" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| namespace Codeception\Lib\Driver; | ||
|
|
||
|
|
||
| use Codeception\Lib\Interfaces\Queue; | ||
| use Pheanstalk\Contract\ResponseInterface; | ||
| use Pheanstalk\Pheanstalk; | ||
|
|
||
| class Pheanstalk4 implements Queue | ||
| { | ||
| /** | ||
| * @var Pheanstalk | ||
| */ | ||
| private $queue; | ||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function openConnection($config) | ||
| { | ||
| $this->queue = Pheanstalk::create($config['host'], $config['port'], $config['timeout']); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function addMessageToQueue($message, $queue) | ||
| { | ||
| $this->queue->useTube($queue); | ||
| $this->queue->put($message); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function getQueues() | ||
| { | ||
| return $this->queue->listTubes(); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function getMessagesCurrentCountOnQueue($queue) | ||
| { | ||
| $response = $this->queue->statsTube($queue); | ||
| return $response->getResponseName() !== ResponseInterface::RESPONSE_NOT_FOUND | ||
| ? $response['current-jobs-ready'] | ||
| : 0; | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function getMessagesTotalCountOnQueue($queue) | ||
| { | ||
| $response = $this->queue->statsTube($queue); | ||
| return $response->getResponseName() !== ResponseInterface::RESPONSE_NOT_FOUND | ||
| ? $response['total-jobs'] | ||
| : 0; | ||
| } | ||
|
|
||
| public function clearQueue($queue) | ||
| { | ||
| $this->queue->useTube($queue); | ||
| while (null !== $job = $this->queue->peekBuried()) { | ||
| $this->queue->delete($job); | ||
| } | ||
| while (null !== $job = $this->queue->peekDelayed()) { | ||
| $this->queue->delete($job); | ||
| } | ||
| while (null !== $job = $this->queue->peekReady()) { | ||
| $this->queue->delete($job); | ||
| } | ||
| } | ||
|
|
||
| public function getRequiredConfig() | ||
| { | ||
| return []; | ||
| } | ||
|
|
||
| public function getDefaultConfig() | ||
| { | ||
| return ['port' => 11300, 'timeout' => 90, 'host' => 'localhost']; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,14 @@ | ||
| <?php | ||
|
|
||
| use Codeception\Util\Stub; | ||
| use Pheanstalk\Exception\ConnectionException; | ||
|
|
||
| class BeanstalkdTest extends \Codeception\PHPUnit\TestCase | ||
| class BeanstalkdTest extends QueueTest | ||
| { | ||
| protected $config = array( | ||
| 'type' => 'beanstalkq', | ||
| 'host' => 'localhost' | ||
| ); | ||
|
|
||
| /** | ||
| * @var \Codeception\Module\Queue | ||
| */ | ||
| protected $module = null; | ||
|
|
||
| public function _setUp() | ||
| { | ||
| $container = \Codeception\Util\Stub::make('Codeception\Lib\ModuleContainer'); | ||
| $this->module = new \Codeception\Module\Queue($container); | ||
| $this->module->_setConfig($this->config); | ||
| $this->module->_before(Stub::makeEmpty('\Codeception\TestInterface')); | ||
| try { | ||
| $this->module->clearQueue('default'); | ||
| } catch (ConnectionException $e) { | ||
| $this->markTestSkipped("Beanstalk is not running"); | ||
| } | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function flow() | ||
| public function configProvider() | ||
| { | ||
| $this->module->addMessageToQueue('hello world - ' . date('d-m-y'), 'default'); | ||
| $this->module->clearQueue('default'); | ||
|
|
||
| $this->module->seeQueueExists('default'); | ||
| $this->module->dontSeeQueueExists('fake_queue'); | ||
|
|
||
| $this->module->seeEmptyQueue('default'); | ||
| $this->module->addMessageToQueue('hello world - ' . date('d-m-y'), 'default'); | ||
| $this->module->dontSeeEmptyQueue('default'); | ||
|
|
||
| $this->module->seeQueueHasTotalCount('default', 2); | ||
|
|
||
| $this->module->seeQueueHasCurrentCount('default', 1); | ||
| $this->module->dontSeeQueueHasCurrentCount('default', 9999); | ||
|
|
||
| $this->module->grabQueues(); | ||
| return [ | ||
| [[ | ||
| 'type' => 'beanstalkd', | ||
| 'host' => 'localhost' | ||
| ]] | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| use Codeception\Lib\ModuleContainer; | ||
| use Codeception\Module\Queue; | ||
| use \Codeception\PHPUnit\TestCase; | ||
| use Codeception\TestInterface; | ||
| use Codeception\Util\Stub; | ||
|
|
||
| abstract class QueueTest extends TestCase | ||
| { | ||
|
|
||
| abstract public function configProvider(); | ||
|
|
||
| /** | ||
| * @dataProvider configProvider | ||
| */ | ||
| public function testFlow($config) | ||
| { | ||
| /** @var ModuleContainer $container */ | ||
| $container = Stub::make(ModuleContainer::class); | ||
| $module = new Queue($container); | ||
| $module->_setConfig($config); | ||
| $module->_before(Stub::makeEmpty(TestInterface::class)); | ||
| try { | ||
| $module->clearQueue('default'); | ||
| } catch (\Throwable $t) { | ||
| $this->markTestSkipped("Connection failed for: " . print_r($config, true)); | ||
| } | ||
| $initialCount = $module->grabQueueTotalCount('default'); | ||
| $module->addMessageToQueue('hello world - ' . date('d-m-y'), 'default'); | ||
| $module->clearQueue('default'); | ||
|
|
||
| $module->seeQueueExists('default'); | ||
| $module->dontSeeQueueExists('fake_queue'); | ||
|
|
||
| $module->seeEmptyQueue('default'); | ||
| $module->addMessageToQueue('hello world - ' . date('d-m-y'), 'default'); | ||
| $module->dontSeeEmptyQueue('default'); | ||
|
|
||
| $module->seeQueueHasTotalCount('default', $initialCount + 2); | ||
|
|
||
| $module->seeQueueHasCurrentCount('default', 1); | ||
| $module->dontSeeQueueHasCurrentCount('default', 9999); | ||
|
|
||
| $module->grabQueues(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.