diff --git a/phpunit.xml b/phpunit.xml index c8fdf32..441720c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,7 +9,6 @@ processIsolation="false" stopOnError="false" stopOnFailure="false" - syntaxCheck="true" verbose="true" > diff --git a/src/Busses/SynchronousCommandBus.php b/src/Busses/SynchronousCommandBus.php index 4aacb83..acf3e0e 100644 --- a/src/Busses/SynchronousCommandBus.php +++ b/src/Busses/SynchronousCommandBus.php @@ -11,7 +11,7 @@ class SynchronousCommandBus implements CommandBus { protected $resolver; - public function __construct(CommandHandlerResolver $resolver = null) + public function __construct(?CommandHandlerResolver $resolver = null) { $this->resolver = $resolver ?: new NativeCommandHandlerResolver; } diff --git a/src/Chief.php b/src/Chief.php index 52d05f5..c56e19f 100644 --- a/src/Chief.php +++ b/src/Chief.php @@ -22,7 +22,7 @@ class Chief implements CommandBus * @param CommandBus $bus * @param array $decorators Array of \Chief\Decorator objects */ - public function __construct(CommandBus $bus = null, array $decorators = []) + public function __construct(?CommandBus $bus = null, array $decorators = []) { $this->bus = $bus ?: new SynchronousCommandBus; diff --git a/src/Decorators/CachingDecorator.php b/src/Decorators/CachingDecorator.php index fbaf15c..57c3374 100644 --- a/src/Decorators/CachingDecorator.php +++ b/src/Decorators/CachingDecorator.php @@ -32,7 +32,7 @@ class CachingDecorator implements Decorator * @param int $expiresAfter * @param CommandBus $innerCommandBus */ - public function __construct(CacheItemPoolInterface $cache, $expiresAfter = 3600, CommandBus $innerCommandBus = null) + public function __construct(CacheItemPoolInterface $cache, int $expiresAfter = 3600, ?CommandBus $innerCommandBus = null) { $this->cache = $cache; $this->expiresAfter = $expiresAfter; diff --git a/src/Decorators/CommandQueueingDecorator.php b/src/Decorators/CommandQueueingDecorator.php index cfc1eca..e83101a 100644 --- a/src/Decorators/CommandQueueingDecorator.php +++ b/src/Decorators/CommandQueueingDecorator.php @@ -25,7 +25,7 @@ class CommandQueueingDecorator implements Decorator * @param CommandQueuer $queuer * @param CommandBus $innerCommandBus */ - public function __construct(CommandQueuer $queuer, CommandBus $innerCommandBus = null) + public function __construct(CommandQueuer $queuer, ?CommandBus $innerCommandBus = null) { $this->queuer = $queuer; $this->setInnerBus($innerCommandBus ?: new SynchronousCommandBus()); diff --git a/src/Decorators/EventDispatchingDecorator.php b/src/Decorators/EventDispatchingDecorator.php index f3344ee..010e74c 100644 --- a/src/Decorators/EventDispatchingDecorator.php +++ b/src/Decorators/EventDispatchingDecorator.php @@ -22,9 +22,9 @@ class EventDispatchingDecorator implements Decorator /** * @param EventDispatcher $dispatcher - * @param CommandBus $innerCommandBus + * @param CommandBus|null $innerCommandBus */ - public function __construct(EventDispatcher $dispatcher, CommandBus $innerCommandBus = null) + public function __construct(EventDispatcher $dispatcher, ?CommandBus $innerCommandBus = null) { $this->dispatcher = $dispatcher; $this->setInnerBus($innerCommandBus ?: new SynchronousCommandBus()); diff --git a/src/Decorators/LoggingDecorator.php b/src/Decorators/LoggingDecorator.php index 21a715f..faf1417 100644 --- a/src/Decorators/LoggingDecorator.php +++ b/src/Decorators/LoggingDecorator.php @@ -27,7 +27,7 @@ class LoggingDecorator implements Decorator * the command execution, such as the request/session information. * @param CommandBus $innerCommandBus */ - public function __construct(LoggerInterface $logger, $context = null, CommandBus $innerCommandBus = null) + public function __construct(LoggerInterface $logger, mixed $context = null, ?CommandBus $innerCommandBus = null) { $this->logger = $logger; $this->context = $context; diff --git a/src/Decorators/TransactionalCommandLockingDecorator.php b/src/Decorators/TransactionalCommandLockingDecorator.php index 57f8273..d8215ee 100644 --- a/src/Decorators/TransactionalCommandLockingDecorator.php +++ b/src/Decorators/TransactionalCommandLockingDecorator.php @@ -28,7 +28,7 @@ class TransactionalCommandLockingDecorator implements Decorator */ protected $queue = []; - public function __construct(CommandBus $innerCommandBus = null) + public function __construct(?CommandBus $innerCommandBus = null) { $this->setInnerBus($innerCommandBus ?: new SynchronousCommandBus()); } diff --git a/src/Resolvers/NativeCommandHandlerResolver.php b/src/Resolvers/NativeCommandHandlerResolver.php index c6ba902..29defdc 100644 --- a/src/Resolvers/NativeCommandHandlerResolver.php +++ b/src/Resolvers/NativeCommandHandlerResolver.php @@ -17,7 +17,7 @@ class NativeCommandHandlerResolver implements CommandHandlerResolver protected $handlers = []; - public function __construct(Container $container = null) + public function __construct(?Container $container = null) { $this->container = $container ?: new NativeContainer; } diff --git a/tests/Decorators/CachingDecoratorTest.php b/tests/Decorators/CachingDecoratorTest.php index d9bfff1..6c1753a 100644 --- a/tests/Decorators/CachingDecoratorTest.php +++ b/tests/Decorators/CachingDecoratorTest.php @@ -153,12 +153,22 @@ protected function getDecorator() class FakeCachableCommand implements CacheableCommand { - public $data; + private $data; public function __construct($data) { $this->data = $data; } + + public function getData() + { + return $this->data; + } + + public function setData($data) + { + $this->data = $data; + } } class FakeCachableCommandWithCacheOptions extends FakeCachableCommand implements HasCacheOptions @@ -168,7 +178,7 @@ class FakeCachableCommandWithCacheOptions extends FakeCachableCommand implements public function __construct($data, $expiry, $cacheKey) { - $this->data = $data; + parent::__construct($data); $this->expiry = $expiry; $this->cacheKey = $cacheKey; } diff --git a/tests/Stubs/LogDecoratorCommandBus.php b/tests/Stubs/LogDecoratorCommandBus.php index faf0497..35fbb86 100644 --- a/tests/Stubs/LogDecoratorCommandBus.php +++ b/tests/Stubs/LogDecoratorCommandBus.php @@ -9,6 +9,9 @@ class LogDecoratorCommandBus implements Decorator { + public $logger; + public $commandBus; + public function __construct(LoggerInterface $logger, CommandBus $commandBus) { $this->logger = $logger; diff --git a/tests/Stubs/NonInterfaceImplementingCommand.php b/tests/Stubs/NonInterfaceImplementingCommand.php index 1b8330b..747d285 100644 --- a/tests/Stubs/NonInterfaceImplementingCommand.php +++ b/tests/Stubs/NonInterfaceImplementingCommand.php @@ -4,4 +4,6 @@ use Chief\Command; -class NonInterfaceImplementingCommand implements Command {} \ No newline at end of file +class NonInterfaceImplementingCommand implements Command { + public $handled = false; +} \ No newline at end of file diff --git a/tests/Stubs/NonInterfaceImplementingCommandHandler.php b/tests/Stubs/NonInterfaceImplementingCommandHandler.php index dccfc47..fc4e510 100644 --- a/tests/Stubs/NonInterfaceImplementingCommandHandler.php +++ b/tests/Stubs/NonInterfaceImplementingCommandHandler.php @@ -7,6 +7,8 @@ class NonInterfaceImplementingCommandHandler { + public $handled = false; + public function handle($command) { $command->handled = true; diff --git a/tests/Stubs/SelfHandlingCommand.php b/tests/Stubs/SelfHandlingCommand.php index 5fafb5b..35de6c8 100644 --- a/tests/Stubs/SelfHandlingCommand.php +++ b/tests/Stubs/SelfHandlingCommand.php @@ -7,6 +7,8 @@ class SelfHandlingCommand implements Command, CommandHandler { + public $handled = false; + public function handle(Command $command) { $command->handled = true; diff --git a/tests/Stubs/TestCommand.php b/tests/Stubs/TestCommand.php index 7e88caa..69a0b90 100644 --- a/tests/Stubs/TestCommand.php +++ b/tests/Stubs/TestCommand.php @@ -4,4 +4,6 @@ use Chief\Command; -class TestCommand implements Command {} \ No newline at end of file +class TestCommand implements Command { + public $handled = false; +} \ No newline at end of file