-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,64 @@ | ||
<?php | ||
namespace Tavii\SQSJobQueueBundle; | ||
|
||
use Aws\Sqs\SqsClient; | ||
use Tavii\SQSJobQueue\Job\JobInterface; | ||
use Tavii\SQSJobQueue\Message\MessageInterface; | ||
use Tavii\SQSJobQueue\Queue\Queue as BaseQueue; | ||
use Tavii\SQSJobQueue\Queue\QueueInterface; | ||
|
||
class Queue implements QueueInterface | ||
{ | ||
|
||
/** | ||
* Aamazon SQS Client | ||
* @var SqsClient | ||
*/ | ||
private $baseQueue; | ||
|
||
|
||
/** | ||
* @param SqsClient $client | ||
*/ | ||
public function __construct(BaseQueue $baseQueue, array $kernelOptions) | ||
{ | ||
$this->baseQueue = $baseQueue; | ||
$this->kernelOptions = $kernelOptions; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function pull($name) | ||
{ | ||
$message = $this->baseQueue->pull($name); | ||
$job = $message->getJob(); | ||
if ($job instanceof ContainerAwareJob) { | ||
$job->setKernelOptions($this->kernelOptions); | ||
} | ||
return $message; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function push(JobInterface $job) | ||
{ | ||
return $this->baseQueue->push($job); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function delete(MessageInterface $message) | ||
{ | ||
if ($this->baseQueue->delete($message)) { | ||
$job = $message->getJob(); | ||
unset($job); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
} |
This file contains 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,59 @@ | ||
<?php | ||
namespace Tavii\SQSJobQueueBundle; | ||
|
||
use Phake; | ||
use Tavii\SQSJobQueue\Job\booelan; | ||
use Tavii\SQSJobQueue\Message\Message; | ||
|
||
class QueueTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function pullする際にKernelOptionを渡すことができる() | ||
{ | ||
$name = "test_queue"; | ||
$kernelOptions = array( | ||
'kernel.root_dir' => '.', | ||
'kernel.environment' => 'test', | ||
'kernel.debug' => true, | ||
); | ||
|
||
$job = Phake::mock('Tavii\SQSJobQueueBundle\ContainerAwareJob'); | ||
$message = Phake::mock('Tavii\SQSJobQueue\Message\Message'); | ||
$baseQueue = Phake::mock('Tavii\SQSJobQueue\Queue\Queue'); | ||
|
||
Phake::when($baseQueue)->pull($name) | ||
->thenReturn($message); | ||
Phake::when($message)->getJob() | ||
->thenReturn($job); | ||
|
||
$queue = new Queue($baseQueue, $kernelOptions); | ||
$queue->pull($name); | ||
|
||
Phake::verify($baseQueue)->pull($name); | ||
Phake::verify($message)->getJob(); | ||
Phake::verify($job)->setKernelOptions($kernelOptions); | ||
|
||
} | ||
} | ||
|
||
class DummyContainerAwareJob extends ContainerAwareJob | ||
{ | ||
/** | ||
* @return booelan | ||
*/ | ||
public function run() | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return 'dummy_container_aware_job'; | ||
} | ||
|
||
} |