Skip to content

Commit

Permalink
Merge pull request #12 from PcComponentes/feature/serialice-exception…
Browse files Browse the repository at this point in the history
…-from-json-serializable

Remove apixception and upgrade ddd to 2.0
  • Loading branch information
zoilomora authored Apr 30, 2020
2 parents 11a4152 + e884695 commit bdff96e
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 51 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/DomainTrace/DomainTraceProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/DomainTrace/MessageTraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/DomainTrace/RequestTraceMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/DomainTrace/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
10 changes: 6 additions & 4 deletions src/ExceptionCatcher/TraceOfExceptionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutionTime/ExecutionTimeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ExecutionTime/ExecutionTimeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Info/InfoProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/MessageLogger/MessageLoggerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/OccurredOn/OccurredOnProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 3 additions & 1 deletion tests/DomainTrace/DomainTraceProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public function testShouldAddedReplyToAndCorrelationIdToRecord()
{
$correlationId = "correlation_id_value";
$replyTo = "reply_to_value";
$record = [];
$record = [
'context' => [],
];

$trackerMock = $this->createMock(Tracker::class);
$trackerMock
Expand Down
23 changes: 4 additions & 19 deletions tests/DomainTrace/MessageTraceMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions tests/ExceptionCatcher/TraceOfExceptionProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public function testShouldReturnedRecordWithoutExceptionContext()

public function testShouldReturnedRecordWithExceptionContext()
{
$exceptionMock = $this->createMock(SerializableException::class);
$exceptionMock = $this->createMock(\JsonSerializable::class);
$record = [
'context' => [
'exception' => $exceptionMock
]
];

$exceptionMock
->expects($this->once())
->method('serialice')
->expects($this->atLeastOnce())
->method('jsonSerialize')
->willReturn([]);

$recordResult = (new TraceOfExceptionProcessor())($record);
Expand Down
4 changes: 2 additions & 2 deletions tests/ExecutionTime/ExecutionTimeMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/ExecutionTime/ExecutionTimeProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions tests/Info/InfoProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/MessageLogger/MessageLoggerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/OccurredOn/OccurredOnProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bdff96e

Please sign in to comment.