Skip to content

Commit

Permalink
Add support for Laravel 6 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea De Pirro authored and joskfg committed Oct 25, 2019
1 parent 318149b commit 5e764ac
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 105 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ sudo: false

matrix:
include:
- php: 7.1
env: STATIC_ANALYSIS=true VALIDATE_CODING_STYLE=true
- php: 7.2
env: COLLECT_COVERAGE=true VALIDATE_CODING_STYLE=true
- php: 7.3
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"require": {
"php": ">=7.2",
"bschmitt/laravel-amqp": "^2.0",
"laravel/framework": "5.8.*"
"laravel/framework": "^5.8 || ^6.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"phpunit/phpunit": "^8.0",
"friendsofphp/php-cs-fixer": "^2.15",
"mockery/mockery": "^1",
"orchestra/testbench": "^3.8",
"orchestra/database": "^3.8",
"mockery/mockery": "^1.2",
"orchestra/testbench": "^4.0",
"orchestra/database": "^4.0",
"php-mock/php-mock-mockery": "^1.3"
},
"autoload": {
Expand All @@ -32,7 +32,7 @@
}
},
"scripts": {
"test": "phpunit --coverage-text; php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
"tests": "phpunit --coverage-text; php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
"phpunit": "phpunit --coverage-text",
"phpcs": "php-cs-fixer fix -v --diff --dry-run --allow-risky=yes;",
"fix-cs": "php-cs-fixer fix -v --diff --allow-risky=yes;"
Expand Down
2 changes: 1 addition & 1 deletion database/factories/DomainEventFactory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Softonic\TransactionalEventPublisher\Model\DomainEvent;
use Softonic\TransactionalEventPublisher\CustomEventMessage;
use Softonic\TransactionalEventPublisher\Model\DomainEvent;
use Softonic\TransactionalEventPublisher\TestModel;

$factory->define(DomainEvent::class, function () {
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
volumes:
- ./:/app
image: ricc/composer-prestissimo:latest
command: composer run test
command: composer run tests

fixcs:
volumes:
Expand All @@ -28,4 +28,4 @@ services:
volumes:
- ./:/app
image: ricc/composer-prestissimo:latest
command: composer phpunit
command: composer phpunit
7 changes: 4 additions & 3 deletions src/Contracts/EventMessageContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
namespace Softonic\TransactionalEventPublisher\Contracts;

use Illuminate\Database\Eloquent\Model;
use JsonSerializable;

/**
* Interface EventMessageContract
*
* @package Softonic\TransactionalEventPublisher\Contracts
*/
interface EventMessageContract extends \JsonSerializable
interface EventMessageContract extends JsonSerializable
{
/**
* EventMessageContract constructor.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param $eventType
* @param Model $model
* @param $eventType
*/
public function __construct(Model $model, $eventType);

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/EventStoreMiddlewareContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface EventStoreMiddlewareContract
/**
* Stores in the message-oriented middleware.
*
* @param \Softonic\TransactionalEventPublisher\Contracts\EventMessageContract $message
* @param EventMessageContract $message
*
* @return mixed
*/
Expand Down
12 changes: 7 additions & 5 deletions src/EventStoreMiddlewares/AmqpMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Softonic\TransactionalEventPublisher\EventStoreMiddlewares;

use Bschmitt\Amqp\Amqp;
use Exception;
use Psr\Log\LoggerInterface;
use Softonic\TransactionalEventPublisher\Contracts\EventMessageContract;
use Softonic\TransactionalEventPublisher\Contracts\EventStoreMiddlewareContract;
Expand All @@ -29,10 +30,10 @@ class AmqpMiddleware implements EventStoreMiddlewareContract
/**
* AmqpMiddleware constructor.
*
* @param \Softonic\TransactionalEventPublisher\Factories\AmqpMessageFactory $messageFactory
* @param \Bschmitt\Amqp\Amqp $amqp
* @param array $properties
* @param LoggerInterface $logger
* @param AmqpMessageFactory $messageFactory
* @param Amqp $amqp
* @param array $properties
* @param LoggerInterface $logger
*/
public function __construct(
AmqpMessageFactory $messageFactory,
Expand Down Expand Up @@ -63,8 +64,9 @@ public function store(EventMessageContract $message)
);

return true;
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->error($e->getMessage());

return false;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/EventStoreMiddlewares/AsyncAmqpMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softonic\TransactionalEventPublisher\EventStoreMiddlewares;

use Exception;
use Illuminate\Contracts\Bus\Dispatcher;
use Softonic\TransactionalEventPublisher\Contracts\EventMessageContract;
use Softonic\TransactionalEventPublisher\Contracts\EventStoreMiddlewareContract;
Expand All @@ -22,7 +23,7 @@ public function __construct(Dispatcher $dispatcher)
/**
* Stores in the message-oriented middleware.
*
* @param \Softonic\TransactionalEventPublisher\Contracts\EventMessageContract $message
* @param EventMessageContract $message
*
* @return mixed
*/
Expand All @@ -34,7 +35,7 @@ public function store(EventMessageContract $message)
$this->dispatcher->dispatch($job);

return true;
} catch (\Exception $e) {
} catch (Exception $e) {
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/EventStoreMiddlewares/DatabaseMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softonic\TransactionalEventPublisher\EventStoreMiddlewares;

use Exception;
use Softonic\TransactionalEventPublisher\Contracts\EventMessageContract;
use Softonic\TransactionalEventPublisher\Contracts\EventStoreMiddlewareContract;
use Softonic\TransactionalEventPublisher\Model\DomainEvent;
Expand All @@ -26,7 +27,7 @@ public function store(EventMessageContract $message)
DomainEvent::create(compact('message'));

return true;
} catch (\Exception $e) {
} catch (Exception $e) {
return false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/Exceptions/EventStoreFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace Softonic\TransactionalEventPublisher\Exceptions;

use RuntimeException;

/**
* Class EventStoreFailedException
*
* @package Softonic\TransactionalEventPublisher\Exceptions
*/
class EventStoreFailedException extends \RuntimeException
class EventStoreFailedException extends RuntimeException
{
}
5 changes: 3 additions & 2 deletions src/Factories/AmqpMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softonic\TransactionalEventPublisher\Factories;

use LogicException;
use PhpAmqpLib\Message\AMQPMessage;
use Softonic\TransactionalEventPublisher\Contracts\EventMessageContract;

Expand All @@ -18,7 +19,7 @@ class AmqpMessageFactory
* @param EventMessageContract $eventMessage
* @param array $properties
*
* @return \PhpAmqpLib\Message\AMQPMessage
* @return AMQPMessage
*/
public function make(EventMessageContract $eventMessage, array $properties = null)
{
Expand All @@ -30,7 +31,7 @@ public function make(EventMessageContract $eventMessage, array $properties = nul
private function checkMessage(array $message)
{
if (empty(array_filter($message))) {
throw new \LogicException('No message provided');
throw new LogicException('No message provided');
}
}
}
6 changes: 4 additions & 2 deletions src/Jobs/SendDomainEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace Softonic\TransactionalEventPublisher\Jobs;

use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Softonic\TransactionalEventPublisher\Contracts\EventMessageContract;
use Softonic\TransactionalEventPublisher\EventStoreMiddlewares\AmqpMiddleware;

Expand Down Expand Up @@ -57,7 +59,7 @@ public function handle(AmqpMiddleware $amqpMiddleware, Dispatcher $dispatcher, L

try {
$this->sendEvent();
} catch (\Exception $e) {
} catch (Exception $e) {
$this->waitExponentialBackOff();
$this->retry();
}
Expand All @@ -69,7 +71,7 @@ protected function sendEvent(): void
$errorMessage = "The event could't be sent. Retrying message: " . json_encode($this->eventMessage);
$this->logger->alert($errorMessage);

throw new \RuntimeException($errorMessage);
throw new RuntimeException($errorMessage);
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/Observers/ModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softonic\TransactionalEventPublisher\Observers;

use Exception;
use Illuminate\Database\Eloquent\Model;
use Softonic\TransactionalEventPublisher\Contracts\EventStoreMiddlewareContract;
use Softonic\TransactionalEventPublisher\Exceptions\EventStoreFailedException;
Expand Down Expand Up @@ -34,9 +35,9 @@ public function __construct(
/**
* Handles the model creating event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @throws \Exception
* @throws Exception
*/
public function creating(Model $model)
{
Expand All @@ -46,7 +47,7 @@ public function creating(Model $model)
/**
* Handles the model created event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @return bool
*/
Expand All @@ -60,9 +61,9 @@ public function created(Model $model)
/**
* Handles the model updating event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @throws \Exception
* @throws Exception
*/
public function updating(Model $model)
{
Expand All @@ -72,7 +73,7 @@ public function updating(Model $model)
/**
* Handles the model updated event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @return bool
*/
Expand All @@ -86,9 +87,9 @@ public function updated(Model $model)
/**
* Handles the model deleting event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @throws \Exception
* @throws Exception
*/
public function deleting(Model $model)
{
Expand All @@ -98,7 +99,7 @@ public function deleting(Model $model)
/**
* Handles the model deleted event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param Model $model
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/ValueObjects/EventMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class EventMessage implements EventMessageContract

public function __construct(Model $model, $eventType)
{
$this->service = config('transactional-event-publisher.service');
$this->service = config('transactional-event-publisher.service');
$this->eventType = $eventType;
$this->modelName = class_basename($model);
$this->eventName = $this->buildEventName($this->modelName, $eventType);
$this->payload = $model->toArray();
$this->payload = $model->toArray();
$this->createdAt = date('Y-m-d H:i:s');
}

Expand Down Expand Up @@ -53,10 +53,10 @@ public function jsonSerialize()
public function toArray()
{
return [
'service' => $this->service,
'service' => $this->service,
'eventName' => $this->eventName,
'createdAt' => $this->createdAt,
'payload' => $this->payload,
'payload' => $this->payload,
];
}
}
1 change: 0 additions & 1 deletion tests/Console/Commands/EmitAllEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Softonic\TransactionalEventPublisher\Jobs\SendDomainEvents;
use Softonic\TransactionalEventPublisher\Model\DomainEvent;

use Softonic\TransactionalEventPublisher\TestCase;

class EmitAllEventsTest extends TestCase
Expand Down
Loading

0 comments on commit 5e764ac

Please sign in to comment.