Skip to content

Commit

Permalink
Merge pull request #7 from SykesCottages/add-extra-option
Browse files Browse the repository at this point in the history
Increase test coverage back to 100 percent
  • Loading branch information
richardhughes authored Sep 6, 2019
2 parents 4971bef + 69f8412 commit c552ec4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
coverage
.idea
vendor
build
build
.phpunit.result.cache
59 changes: 59 additions & 0 deletions tests/Functional/Connector/SQSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

namespace Tests\Functional\Connector;

use Mockery;
use SykesCottages\Qu\Connector\SQS;
use SykesCottages\Qu\Message\Contract\Message;
use SykesCottages\Qu\Message\SQSMessage;
use Tests\Functional\Connector\Stubs\SQSCallable;
use Tests\Functional\FunctionalTestCase;

class SQSTest extends FunctionalTestCase
{
private const DEFAULT_NUMBER_OF_URLS = 2;

private const MAX_NUMBER_OF_MESSAGES_PER_POLL = 10;

private const MIN_NUMBER_OF_MESSAGES_PER_POLL = 1;

private const QUEUE_NAME = 'test';

/**
Expand Down Expand Up @@ -118,6 +124,59 @@ function () {
);
}

public function retrieveMinAndMaxDataProvider() : array
{
return [
'Test if we specify more than the MAX it will cap to the MAX value allowed by SQS' => [
100,
self::MAX_NUMBER_OF_MESSAGES_PER_POLL,
],
'Test if we specify less than the MIN value it will cap to the MIN value' => [
0,
self::MIN_NUMBER_OF_MESSAGES_PER_POLL,
],
];
}

/**
* @param int $numberOfMessagesToConsumeAtATime
* @param int $expectedNumberOfCallbackCalls
*
* @dataProvider retrieveMinAndMaxDataProvider
*/
public function testWeCanOnlyRetrieveMessagesBetweenTheMaxAndMin(
int $numberOfMessagesToConsumeAtATime,
int $expectedNumberOfCallbackCalls
): void {
$this->addMultipleMessagesToQueue(100);

$this->sqs->setQueueOptions([
'maxNumberOfMessagesPerConsume' => $numberOfMessagesToConsumeAtATime,
]);

$mock = Mockery::mock(SQSCallable::class);

$mock->shouldReceive('__invoke')
->times($expectedNumberOfCallbackCalls);

$this->sqs->consume(
$this->testingQueueUrl,
$mock,
function () {
$this->assertFunctionIsNotCalled();
}
);
}

private function addMultipleMessagesToQueue(int $messagesToSend) : void
{
$countOfMessages = 0;
while ($countOfMessages < $messagesToSend) {
$this->addMessageToQueue();
$countOfMessages++;
}
}

private function addMessageToQueue(): void
{
$this->sqs->queueMessage($this->testingQueueUrl, ['example' => 'test']);
Expand Down
12 changes: 12 additions & 0 deletions tests/Functional/Connector/Stubs/SQSCallable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Tests\Functional\Connector\Stubs;

class SQSCallable
{
public function __invoke()
{
}
}
11 changes: 11 additions & 0 deletions tests/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ protected function assertFunctionHasBeenCalled(): void
{
$this->assertTrue(true);
}

public function tearDown() : void
{
$container = \Mockery::getContainer();

if ($container) {
$this->addToAssertionCount($container->mockery_getExpectationCount());
}

parent::tearDown();
}
}

0 comments on commit c552ec4

Please sign in to comment.