-
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.
Merge pull request #3 from ndthuan/refactor-tests
Refactor tests
- Loading branch information
Showing
12 changed files
with
202 additions
and
57 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
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,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
pecl list | grep -i xdebug > /dev/null || yes | pecl install xdebug | ||
|
||
echo 'zend_extension=xdebug.so' > /usr/local/etc/php/conf.d/xdebug.ini |
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
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,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
function cleanup() { | ||
docker-compose down | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
docker-compose up -d | ||
|
||
docker-compose exec -T composer composer install --ignore-platform-reqs --no-scripts | ||
docker-compose exec -T composer composer analyze | ||
|
||
docker-compose exec -T netcat sh wait_for.sh localstack:4576 -t 60 | ||
|
||
docker-compose exec -T awscli aws --no-sign-request --endpoint-url http://localstack:4576 --region fake sqs create-queue --queue-name test-queue | ||
docker-compose exec -T awscli aws --no-sign-request --endpoint-url http://localstack:4576 --region fake sqs purge-queue --queue-url http://localstack:4576/queue/test-queue | ||
|
||
for phpver in php70 php71 php72; do | ||
docker-compose exec -T ${phpver} sh install-xdebug.sh | ||
docker-compose exec -T ${phpver} vendor/bin/phpunit --coverage-html=tests/report/${phpver}-coverage | ||
done |
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
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
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
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
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
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
103 changes: 103 additions & 0 deletions
103
tests/unit/Subscribing/Callbacks/LoggingCallbacksTest.php
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,103 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Ndthuan\AwsSqsWrapper\Subscribing\Callbacks; | ||
|
||
use Exception; | ||
use Ndthuan\AwsSqsWrapper\Queue\ReceivedMessage; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\FatalException; | ||
use Ndthuan\AwsSqsWrapper\Subscribing\Exception\LogicException; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class LoggingCallbacksTest extends TestCase | ||
{ | ||
/** | ||
* @var LoggerInterface|MockObject | ||
*/ | ||
private $loggerMock; | ||
|
||
/** | ||
* @var LoggingCallbacks | ||
*/ | ||
private $loggingCallbacks; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->loggerMock = $this->getMockBuilder(LoggerInterface::class) | ||
->getMock(); | ||
|
||
$this->loggingCallbacks = new LoggingCallbacks($this->loggerMock); | ||
} | ||
|
||
public function testOnMessageProcessed() | ||
{ | ||
$this->loggerMock->expects($this->once()) | ||
->method('info') | ||
->with('Successfully processed SQS message', ['messageId' => 'example-id']); | ||
|
||
$this->loggingCallbacks->onMessageProcessed($this->createMessage()); | ||
} | ||
|
||
public function testOnUncaughtException() | ||
{ | ||
$thrownException = new Exception(); | ||
|
||
$this->loggerMock->expects($this->once()) | ||
->method('error') | ||
->with( | ||
'Uncaught exception when processing SQS message', | ||
['messageId' => 'example-id', 'exception' => $thrownException] | ||
); | ||
|
||
$this->loggingCallbacks->onUncaughtException($this->createMessage(), $thrownException); | ||
} | ||
|
||
public function testOnMessageReceived() | ||
{ | ||
$this->loggerMock->expects($this->once()) | ||
->method('info') | ||
->with('Received SQS message', ['messageId' => 'example-id']); | ||
|
||
$this->loggingCallbacks->onMessageReceived($this->createMessage()); | ||
} | ||
|
||
public function testOnLogicException() | ||
{ | ||
$thrownException = new LogicException(); | ||
|
||
$this->loggerMock->expects($this->once()) | ||
->method('debug') | ||
->with( | ||
'Deleted SQS message due to logical exception', | ||
['messageId' => 'example-id', 'exception' => $thrownException] | ||
); | ||
|
||
$this->loggingCallbacks->onLogicException($this->createMessage(), $thrownException); | ||
} | ||
|
||
public function testOnFatalException() | ||
{ | ||
$thrownException = new FatalException(); | ||
|
||
$this->loggerMock->expects($this->once()) | ||
->method('critical') | ||
->with( | ||
'Stopped SQS processing due to fatal exception', | ||
['messageId' => 'example-id', 'exception' => $thrownException] | ||
); | ||
|
||
$this->loggingCallbacks->onFatalException($this->createMessage(), $thrownException); | ||
} | ||
|
||
/** | ||
* @return ReceivedMessage | ||
*/ | ||
private function createMessage() | ||
{ | ||
return new ReceivedMessage('example-id', 'example-recept-handle', 'example-body-hash', 'example-body', []); | ||
} | ||
} |
Oops, something went wrong.