Skip to content

Commit

Permalink
Refactor tests to support additional properties added in Laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
squigg committed Jun 4, 2020
1 parent f1b20ce commit 3738400
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions tests/AzureQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class AzureQueueTest extends TestCase
{

/**
* @var \Mockery\Mock
*/
Expand Down Expand Up @@ -39,11 +40,11 @@ protected function setListMessagesReturnExpectation($mock, $count = 1)
/** @test */
public function it_can_push_message_to_queue()
{
$this->azure->shouldReceive('createMessage')->once()->withArgs([
"myqueue",
'{"displayName":"job","job":"job","maxTries":null,"delay":null,"timeout":null,"data":"data"}'
]);
$this->queue->push('job', 'data');
$this->azure->shouldReceive('createMessage')->once()->withArgs(function ($queue, $payload) {
$payload = json_decode($payload, true);
return $queue == "myqueue" && $payload['displayName'] == 'foojob' && $payload['job'] == 'foojob' && $payload['data'] == 'bardata';
});
$this->queue->push('foojob', 'bardata');
}

/** @test */
Expand Down Expand Up @@ -77,28 +78,23 @@ public function it_returns_null_if_no_messages_to_pop()
/** @test */
public function it_passes_visibility_timeout_set_in_config()
{
$this->setListMessagesReturnExpectation(
$this->azure->shouldReceive('listMessages')->once()->withArgs(
function ($queue, ListMessagesOptions $options) {
return $queue == 'myqueue' && $options->getVisibilityTimeoutInSeconds() == 5;
}
)
);
$mockClient = $this->azure->shouldReceive('listMessages')->once()->withArgs(function ($queue,
ListMessagesOptions $options) {
return $queue == 'myqueue' && $options->getVisibilityTimeoutInSeconds() == 5;
});
$this->setListMessagesReturnExpectation($mockClient);

$this->queue->pop('myqueue');
}

/** @test */
public function it_only_fetches_first_message()
{
$this->setListMessagesReturnExpectation(
$this->azure->shouldReceive('listMessages')->once()->withArgs(
function ($queue, ListMessagesOptions $options) {
return $queue == 'myqueue' && $options->getNumberOfMessages() == 1;
}
)
);

$mockClient = $this->azure->shouldReceive('listMessages')->once()->withArgs(function ($queue,
ListMessagesOptions $options) {
return $queue == 'myqueue' && $options->getNumberOfMessages() == 1;
});
$this->setListMessagesReturnExpectation($mockClient);
$this->queue->pop('myqueue');
}

Expand All @@ -111,13 +107,14 @@ public function it_can_get_visibility_timeout()
/** @test */
public function it_can_queue_a_job_for_later()
{
$this->azure->shouldReceive('createMessage')->once()->withArgs(
function ($queue, $payload, CreateMessageOptions $options) {
return $queue == 'myqueue' && $payload == '{"displayName":"job","job":"job","maxTries":null,"delay":null,"timeout":null,"data":"data"}' && $options->getVisibilityTimeoutInSeconds() == 10;
}
);

$this->queue->later(10, 'job', 'data', 'myqueue');
$this->azure->shouldReceive('createMessage')->once()->withArgs(function ($queue,
$payload,
CreateMessageOptions $options) {
$payload = json_decode($payload, true);
return $queue == "myqueue" && $payload['displayName'] == 'foojob' && $payload['job'] == 'foojob' && $payload['data'] == 'bardata' && $options->getVisibilityTimeoutInSeconds() == 10;
});

$this->queue->later(10, 'foojob', 'bardata', 'myqueue');
}

/** @test */
Expand Down

0 comments on commit 3738400

Please sign in to comment.