-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalized use and covered with tests
- Loading branch information
Showing
8 changed files
with
158 additions
and
79 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 |
---|---|---|
|
@@ -17,3 +17,4 @@ Thumbs.db | |
|
||
/vendor/ | ||
composer.lock | ||
.phpunit.result.cache |
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="tests/bootstrap.php" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
<server name="APP_ENV" value="test" force="true" /> | ||
<server name="SHELL_VERBOSITY" value="-1" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
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 was deleted.
Oops, something went wrong.
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,110 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace PcComponentes\Transaction\Tests\SymfonyMessenger; | ||
|
||
use PcComponentes\Transaction\Driver\TransactionalConnection; | ||
use PcComponentes\Transaction\SymfonyMessenger\TransactionMiddleware; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Middleware\MiddlewareInterface; | ||
use Symfony\Component\Messenger\Middleware\StackInterface; | ||
|
||
final class TransactionMiddlewareTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function given_transactional_connection_when_handle_then_begin_transaction_and_commit() | ||
{ | ||
$transactionalConnection = $this->createMock(TransactionalConnection::class); | ||
|
||
$transactionalConnection | ||
->expects($this->once()) | ||
->method('beginTransaction') | ||
; | ||
$transactionalConnection | ||
->expects($this->once()) | ||
->method('commit') | ||
; | ||
|
||
$transactionMiddleware = new TransactionMiddleware($transactionalConnection); | ||
$transactionMiddleware->handle( | ||
$this->createMock(Envelope::class), | ||
$this->createMock(StackInterface::class) | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function given_envelope_and_stack_with_next_middleware_when_handle_then_go_forward_to_next_middleware_and_execute_it() | ||
{ | ||
$envelope = $this->createMock(Envelope::class); | ||
$nextMiddleware = $this->createMock(MiddlewareInterface::class); | ||
$stack = $this->createMock(StackInterface::class); | ||
|
||
$stack | ||
->expects($this->once()) | ||
->method('next') | ||
->willReturn($nextMiddleware) | ||
; | ||
$nextMiddleware | ||
->expects($this->once()) | ||
->method('handle') | ||
->with($envelope, $stack) | ||
->willReturn($envelope) | ||
; | ||
|
||
$transactionMiddleware = new TransactionMiddleware( | ||
$this->createMock(TransactionalConnection::class) | ||
); | ||
$transactionMiddleware->handle( | ||
$envelope, | ||
$stack | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function given_next_middleware_throwing_exception_when_handle_then_rollback_transaction_and_throw_catch_exception() | ||
{ | ||
$transactionalConnection = $this->createMock(TransactionalConnection::class); | ||
$nextMiddleware = $this->createMock(MiddlewareInterface::class); | ||
$stack = $this->createMock(StackInterface::class); | ||
$exception = new class extends \Exception {}; | ||
|
||
$transactionalConnection | ||
->expects($this->once()) | ||
->method('beginTransaction') | ||
; | ||
$stack | ||
->expects($this->once()) | ||
->method('next') | ||
->willReturn($nextMiddleware) | ||
; | ||
$nextMiddleware | ||
->expects($this->once()) | ||
->method('handle') | ||
->willThrowException($exception) | ||
; | ||
$transactionalConnection | ||
->expects($this->never()) | ||
->method('commit') | ||
; | ||
$transactionalConnection | ||
->expects($this->once()) | ||
->method('rollback') | ||
; | ||
$this->expectException( | ||
\get_class($exception) | ||
); | ||
|
||
$transactionMiddleware = new TransactionMiddleware($transactionalConnection); | ||
$transactionMiddleware->handle( | ||
$this->createMock(Envelope::class), | ||
$stack | ||
); | ||
} | ||
} |
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,6 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
require dirname(__DIR__).'/vendor/autoload.php'; | ||
|
||
\DG\BypassFinals::enable(); |