From e8846954444af237e82bb4d5ab8d8becd752c010 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 29 Apr 2020 21:26:52 +0200 Subject: [PATCH] Remove apixception and upgrade ddd to 2.0 --- composer.json | 3 +-- src/DomainTrace/DomainTraceProcessor.php | 4 ++-- src/DomainTrace/MessageTraceMiddleware.php | 2 +- src/DomainTrace/RequestTraceMiddleware.php | 4 ++-- src/DomainTrace/Tracker.php | 2 +- .../TraceOfExceptionProcessor.php | 10 ++++---- src/ExecutionTime/ExecutionTimeMiddleware.php | 2 +- src/ExecutionTime/ExecutionTimeProcessor.php | 2 +- src/Info/InfoProcessor.php | 2 +- src/MessageLogger/MessageLoggerMiddleware.php | 2 +- src/OccurredOn/OccurredOnProcessor.php | 2 +- .../DomainTrace/DomainTraceProcessorTest.php | 4 +++- .../MessageTraceMiddlewareTest.php | 23 ++++--------------- .../TraceOfExceptionProcessorTest.php | 6 ++--- .../ExecutionTimeMiddlewareTest.php | 4 ++-- .../ExecutionTimeProcessorTest.php | 4 ++-- tests/Info/InfoProcessorTest.php | 8 +++---- .../MessageLoggerMiddlewareTest.php | 4 ++-- tests/OccurredOn/OccurredOnProcessorTest.php | 2 +- 19 files changed, 39 insertions(+), 51 deletions(-) diff --git a/composer.json b/composer.json index 17e7c7a..1bc6afa 100644 --- a/composer.json +++ b/composer.json @@ -25,12 +25,11 @@ "php": "^7.4", "ext-json": "*", "monolog/monolog": "^1.25", - "pccomponentes/ddd": "^1.2", + "pccomponentes/ddd": "^2.0", "symfony/http-kernel": "^4.4", "symfony/messenger": "^4.4", "symfony/http-foundation": "^4.4", "symfony/stopwatch": "^4.4", - "pccomponentes/apixception-bundle": "^1.1", "guzzlehttp/guzzle": "^6.5" }, "require-dev": { diff --git a/src/DomainTrace/DomainTraceProcessor.php b/src/DomainTrace/DomainTraceProcessor.php index cbf0d00..6d85650 100644 --- a/src/DomainTrace/DomainTraceProcessor.php +++ b/src/DomainTrace/DomainTraceProcessor.php @@ -4,8 +4,8 @@ namespace PcComponentes\DddLogging\DomainTrace; use Monolog\Processor\ProcessorInterface; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\Message; final class DomainTraceProcessor implements ProcessorInterface { diff --git a/src/DomainTrace/MessageTraceMiddleware.php b/src/DomainTrace/MessageTraceMiddleware.php index 0158c7d..bd1be13 100644 --- a/src/DomainTrace/MessageTraceMiddleware.php +++ b/src/DomainTrace/MessageTraceMiddleware.php @@ -3,7 +3,7 @@ namespace PcComponentes\DddLogging\DomainTrace; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Util\Message\Message; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; diff --git a/src/DomainTrace/RequestTraceMiddleware.php b/src/DomainTrace/RequestTraceMiddleware.php index 9fead4b..41e8209 100644 --- a/src/DomainTrace/RequestTraceMiddleware.php +++ b/src/DomainTrace/RequestTraceMiddleware.php @@ -3,8 +3,8 @@ namespace PcComponentes\DddLogging\DomainTrace; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\Message; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Messenger\Envelope; diff --git a/src/DomainTrace/Tracker.php b/src/DomainTrace/Tracker.php index cdde53d..d55966e 100644 --- a/src/DomainTrace/Tracker.php +++ b/src/DomainTrace/Tracker.php @@ -3,7 +3,7 @@ namespace PcComponentes\DddLogging\DomainTrace; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; final class Tracker { diff --git a/src/ExceptionCatcher/TraceOfExceptionProcessor.php b/src/ExceptionCatcher/TraceOfExceptionProcessor.php index 91dffe6..9cfa7ba 100644 --- a/src/ExceptionCatcher/TraceOfExceptionProcessor.php +++ b/src/ExceptionCatcher/TraceOfExceptionProcessor.php @@ -4,7 +4,6 @@ namespace PcComponentes\DddLogging\ExceptionCatcher; use Monolog\Processor\ProcessorInterface; -use Pccomponentes\Apixception\Core\Exception\SerializableException; use PcComponentes\DddLogging\Util\AssocSerializer; final class TraceOfExceptionProcessor implements ProcessorInterface @@ -18,12 +17,15 @@ public function __invoke(array $record): array $exception = $record['context']['exception']; $record['context']['exception'] = AssocSerializer::from($record['context']['exception']); - if ($exception instanceof SerializableException) { - $record['context']['exception']['data'] = \json_encode($exception->serialice()); + if ($exception instanceof \JsonSerializable) { + $record['context']['exception']['data'] = \json_encode($exception, JSON_THROW_ON_ERROR); } if (true === \array_key_exists('trace', $record['context']['exception'])) { - $record['context']['exception']['trace'] = \json_encode($record['context']['exception']['trace']); + $record['context']['exception']['trace'] = \json_encode( + $record['context']['exception']['trace'], + JSON_THROW_ON_ERROR + ); } return $record; diff --git a/src/ExecutionTime/ExecutionTimeMiddleware.php b/src/ExecutionTime/ExecutionTimeMiddleware.php index d022f9b..ea589b6 100644 --- a/src/ExecutionTime/ExecutionTimeMiddleware.php +++ b/src/ExecutionTime/ExecutionTimeMiddleware.php @@ -3,7 +3,7 @@ namespace PcComponentes\DddLogging\ExecutionTime; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Util\Message\Message; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; use Symfony\Component\Messenger\Middleware\StackInterface; diff --git a/src/ExecutionTime/ExecutionTimeProcessor.php b/src/ExecutionTime/ExecutionTimeProcessor.php index 050f5d9..19d8355 100644 --- a/src/ExecutionTime/ExecutionTimeProcessor.php +++ b/src/ExecutionTime/ExecutionTimeProcessor.php @@ -4,7 +4,7 @@ namespace PcComponentes\DddLogging\ExecutionTime; use Monolog\Processor\ProcessorInterface; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Util\Message\Message; use Symfony\Component\Stopwatch\Stopwatch; final class ExecutionTimeProcessor implements ProcessorInterface diff --git a/src/Info/InfoProcessor.php b/src/Info/InfoProcessor.php index 22aea6b..72629c5 100644 --- a/src/Info/InfoProcessor.php +++ b/src/Info/InfoProcessor.php @@ -4,7 +4,7 @@ namespace PcComponentes\DddLogging\Info; use Monolog\Processor\ProcessorInterface; -use Pccomponentes\Ddd\Util\Message\AggregateMessage; +use PcComponentes\Ddd\Util\Message\AggregateMessage; use PcComponentes\Ddd\Util\Message\Message; final class InfoProcessor implements ProcessorInterface diff --git a/src/MessageLogger/MessageLoggerMiddleware.php b/src/MessageLogger/MessageLoggerMiddleware.php index 31f1c42..3ba67f5 100644 --- a/src/MessageLogger/MessageLoggerMiddleware.php +++ b/src/MessageLogger/MessageLoggerMiddleware.php @@ -3,7 +3,7 @@ namespace PcComponentes\DddLogging\MessageLogger; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Util\Message\Message; use Psr\Log\LoggerInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\MiddlewareInterface; diff --git a/src/OccurredOn/OccurredOnProcessor.php b/src/OccurredOn/OccurredOnProcessor.php index 6452b63..903d827 100644 --- a/src/OccurredOn/OccurredOnProcessor.php +++ b/src/OccurredOn/OccurredOnProcessor.php @@ -4,7 +4,7 @@ namespace PcComponentes\DddLogging\OccurredOn; use Monolog\Processor\ProcessorInterface; -use Pccomponentes\Ddd\Domain\Model\DomainEvent; +use PcComponentes\Ddd\Domain\Model\DomainEvent; final class OccurredOnProcessor implements ProcessorInterface { diff --git a/tests/DomainTrace/DomainTraceProcessorTest.php b/tests/DomainTrace/DomainTraceProcessorTest.php index 6df0c2c..4cff21e 100644 --- a/tests/DomainTrace/DomainTraceProcessorTest.php +++ b/tests/DomainTrace/DomainTraceProcessorTest.php @@ -13,7 +13,9 @@ public function testShouldAddedReplyToAndCorrelationIdToRecord() { $correlationId = "correlation_id_value"; $replyTo = "reply_to_value"; - $record = []; + $record = [ + 'context' => [], + ]; $trackerMock = $this->createMock(Tracker::class); $trackerMock diff --git a/tests/DomainTrace/MessageTraceMiddlewareTest.php b/tests/DomainTrace/MessageTraceMiddlewareTest.php index 9f4d782..a9951c3 100644 --- a/tests/DomainTrace/MessageTraceMiddlewareTest.php +++ b/tests/DomainTrace/MessageTraceMiddlewareTest.php @@ -3,8 +3,8 @@ namespace PcComponentes\DddLogging\Tests\CorrelationId; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\Message; use PcComponentes\DddLogging\DomainTrace\MessageTraceMiddleware; use PcComponentes\DddLogging\DomainTrace\Tracker; use PHPUnit\Framework\MockObject\MockObject; @@ -48,13 +48,13 @@ public function testShouldAssignFirstTimeCorrelationId() $toStringUuid = 'e62d7245-57b3-4842-9c7f-f7a89a439450'; $mockMessageId = $this->createMock(Uuid::class); $mockMessageId - ->expects($this->exactly(2)) + ->expects($this->exactly(1)) ->method('value') ->willReturn($toStringUuid); $mockMessage = $this->createMock(Message::class); $mockMessage - ->expects($this->exactly(2)) + ->expects($this->exactly(1)) ->method('messageId') ->willReturn($mockMessageId); @@ -63,16 +63,6 @@ public function testShouldAssignFirstTimeCorrelationId() ->method('getMessage') ->willReturn($mockMessage); - $this->mockTracker - ->expects($this->atLeastOnce()) - ->method('correlationId') - ->willReturn(null); - - $this->mockTracker - ->expects($this->once()) - ->method('assignCorrelationId') - ->with($toStringUuid); - $this->mockTracker ->expects($this->once()) ->method('assignReplyTo') @@ -116,11 +106,6 @@ public function testShouldReturnedExecutionNextMiddleware() ->method('getMessage') ->willReturn($mockMessage); - $this->mockTracker - ->expects($this->atLeastOnce()) - ->method('correlationId') - ->willReturn($toStringUuid); - $this->mockTracker ->expects($this->once()) ->method('assignReplyTo') diff --git a/tests/ExceptionCatcher/TraceOfExceptionProcessorTest.php b/tests/ExceptionCatcher/TraceOfExceptionProcessorTest.php index 8b29c24..6650738 100644 --- a/tests/ExceptionCatcher/TraceOfExceptionProcessorTest.php +++ b/tests/ExceptionCatcher/TraceOfExceptionProcessorTest.php @@ -22,7 +22,7 @@ public function testShouldReturnedRecordWithoutExceptionContext() public function testShouldReturnedRecordWithExceptionContext() { - $exceptionMock = $this->createMock(SerializableException::class); + $exceptionMock = $this->createMock(\JsonSerializable::class); $record = [ 'context' => [ 'exception' => $exceptionMock @@ -30,8 +30,8 @@ public function testShouldReturnedRecordWithExceptionContext() ]; $exceptionMock - ->expects($this->once()) - ->method('serialice') + ->expects($this->atLeastOnce()) + ->method('jsonSerialize') ->willReturn([]); $recordResult = (new TraceOfExceptionProcessor())($record); diff --git a/tests/ExecutionTime/ExecutionTimeMiddlewareTest.php b/tests/ExecutionTime/ExecutionTimeMiddlewareTest.php index c7ec65a..8defb87 100644 --- a/tests/ExecutionTime/ExecutionTimeMiddlewareTest.php +++ b/tests/ExecutionTime/ExecutionTimeMiddlewareTest.php @@ -3,8 +3,8 @@ namespace PcComponentes\DddLogging\Tests\ExecutionTime; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\Message; use PcComponentes\DddLogging\ExecutionTime\ExecutionTimeMiddleware; use PHPUnit\Framework\TestCase; use Symfony\Component\Messenger\Envelope; diff --git a/tests/ExecutionTime/ExecutionTimeProcessorTest.php b/tests/ExecutionTime/ExecutionTimeProcessorTest.php index 59b635a..10153e6 100644 --- a/tests/ExecutionTime/ExecutionTimeProcessorTest.php +++ b/tests/ExecutionTime/ExecutionTimeProcessorTest.php @@ -3,8 +3,8 @@ namespace PcComponentes\DddLogging\Tests\ExecutionTime; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\Message; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\Message; use PcComponentes\DddLogging\ExecutionTime\ExecutionTimeProcessor; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Info/InfoProcessorTest.php b/tests/Info/InfoProcessorTest.php index ecfbf5a..fcd790a 100644 --- a/tests/Info/InfoProcessorTest.php +++ b/tests/Info/InfoProcessorTest.php @@ -3,10 +3,10 @@ namespace PcComponentes\DddLogging\Tests\Info; -use Pccomponentes\Ddd\Domain\Model\ValueObject\DateTimeValueObject; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\AggregateMessage; -use Pccomponentes\Ddd\Util\Message\SimpleMessage; +use PcComponentes\Ddd\Domain\Model\ValueObject\DateTimeValueObject; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\AggregateMessage; +use PcComponentes\Ddd\Util\Message\SimpleMessage; use PcComponentes\DddLogging\Info\InfoProcessor; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/MessageLogger/MessageLoggerMiddlewareTest.php b/tests/MessageLogger/MessageLoggerMiddlewareTest.php index d51e094..127eb1f 100644 --- a/tests/MessageLogger/MessageLoggerMiddlewareTest.php +++ b/tests/MessageLogger/MessageLoggerMiddlewareTest.php @@ -3,8 +3,8 @@ namespace PcComponentes\DddLogging\Tests\MessageLogger; -use Pccomponentes\Ddd\Domain\Model\ValueObject\Uuid; -use Pccomponentes\Ddd\Util\Message\SimpleMessage; +use PcComponentes\Ddd\Domain\Model\ValueObject\Uuid; +use PcComponentes\Ddd\Util\Message\SimpleMessage; use PcComponentes\DddLogging\MessageLogger\Action; use PcComponentes\DddLogging\MessageLogger\MessageLoggerMiddleware; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/OccurredOn/OccurredOnProcessorTest.php b/tests/OccurredOn/OccurredOnProcessorTest.php index 4b22c97..048a5c8 100644 --- a/tests/OccurredOn/OccurredOnProcessorTest.php +++ b/tests/OccurredOn/OccurredOnProcessorTest.php @@ -3,7 +3,7 @@ namespace PcComponentes\DddLogging\Tests\OccurredOn; -use Pccomponentes\Ddd\Domain\Model\DomainEvent; +use PcComponentes\Ddd\Domain\Model\DomainEvent; use PcComponentes\DddLogging\OccurredOn\OccurredOnProcessor; use PHPUnit\Framework\TestCase;