Skip to content

Commit

Permalink
Merge pull request #2 from ICanBoogie/2.0
Browse files Browse the repository at this point in the history
Require PHP 8.0
  • Loading branch information
olvlvl committed Apr 25, 2022
2 parents 72db895 + 0fc7d3d commit 893f231
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yml
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: "7.2"
php-version: "8.0"
ini-values: memory_limit=-1
tools: phpcs, cs2pr
- name: Run PHP Code Sniffer
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "7.2"
php-version: "8.0"
ini-values: memory_limit=-1
tools: composer:v2
- name: Cache dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -14,8 +14,8 @@ jobs:
- lowest
- highest
php-version:
- "7.2"
- "7.4"
- "8.0"
- "8.1"
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
run: make test-coveralls

- name: Upload code coverage
if: ${{ matrix.php-version == '7.2' }}
if: ${{ matrix.php-version == '8.0' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
@@ -1,4 +1,4 @@
FROM php:7.2-cli-buster
FROM php:8.0-cli-buster

RUN apt-get update && \
apt-get install -y autoconf pkg-config && \
Expand Down
21 changes: 21 additions & 0 deletions MIGRATION.md
@@ -0,0 +1,21 @@
# Migration

## v1.x to v2.x

### New features

N/A

### Backward Incompatible Changes

N/A

### Deprecated Features

N/A

### Other Changes

- Require [PHP 8.0](https://www.php.net/releases/8.0/en.php)+
- Compatible with [psr/container](https://github.com/php-fig/container) 1.0 and 2.0
- Compatible with [Symfony 6.0](https://symfony.com/releases/6.0)
13 changes: 7 additions & 6 deletions composer.json
Expand Up @@ -27,15 +27,16 @@
"prefer-stable": true,
"prefer-dist": true,
"require": {
"php": ">=7.2.5"
"php": ">=8.0.2"
},
"require-dev": {
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan": "^1.5",
"phpunit/phpunit": "^8.5",
"psr/container": "^1.0",
"symfony/config": "^4.0|^5.1",
"symfony/dependency-injection": "^4.0|^5.1",
"symfony/yaml": "^4.0|^5.1"
"phpunit/phpunit": "^9.5",
"psr/container": "^1.0|^2.0",
"symfony/config": "^6.0",
"symfony/dependency-injection": "^6.0",
"symfony/yaml": "^6.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 6 additions & 10 deletions lib/AssertingDispatcher.php
Expand Up @@ -16,23 +16,19 @@
*/
class AssertingDispatcher implements Dispatcher
{
/**
* @var Dispatcher
*/
private $dispatcher;

/**
* @var callable
*/
private $assertion;

/**
* @param Dispatcher $dispatcher
* @param callable $assertion A callable that should throw an exception if the message shouldn't
* be dispatched.
* @param callable $assertion
* A callable that should throw an exception if the message shouldn't be dispatched.
*/
public function __construct(Dispatcher $dispatcher, callable $assertion)
{
public function __construct(
private Dispatcher $dispatcher,
callable $assertion
) {
$this->dispatcher = $dispatcher;
$this->assertion = $assertion;
}
Expand Down
23 changes: 7 additions & 16 deletions lib/PSR/ContainerHandlerProvider.php
Expand Up @@ -21,24 +21,15 @@
class ContainerHandlerProvider implements HandlerProvider
{
/**
* @var ContainerInterface
* @param array<string, string> $handlers
* Where _key_ is a message class and _value_ the service identifier of its handler.
*/
private $container;

/**
* @var array<string, string>
*/
private $handlers;

/**
* @param array<string, string> $mapping
* An array of key/value pairs where _key_ is a message class and _value_ the service
* identifier of its handler.
*/
public function __construct(ContainerInterface $container, array $mapping)
{
$this->handlers = $mapping;
public function __construct(
private ContainerInterface $container,
private array $handlers
) {
$this->container = $container;
$this->handlers = $handlers;
}

public function getHandlerForMessage(object $message): callable
Expand Down
11 changes: 3 additions & 8 deletions lib/SimpleDispatcher.php
Expand Up @@ -16,14 +16,9 @@
*/
class SimpleDispatcher implements Dispatcher
{
/**
* @var HandlerProvider
*/
private $handlerProvider;

public function __construct(HandlerProvider $handlerProvider)
{
$this->handlerProvider = $handlerProvider;
public function __construct(
private HandlerProvider $handlerProvider
) {
}

public function dispatch(object $message)
Expand Down
19 changes: 5 additions & 14 deletions lib/SimpleHandlerProvider.php
Expand Up @@ -16,28 +16,19 @@
*/
final class SimpleHandlerProvider implements HandlerProvider
{
/**
* @var array<string, callable>
*/
private $handlers;

/**
* @param array<string, callable> $handlers
*/
public function __construct(array $handlers)
{
$this->handlers = $handlers;
public function __construct(
private array $handlers
) {
}

public function getHandlerForMessage(object $message): callable
{
$class = get_class($message);
$handler = $this->handlers[$class] ?? null;

if (!$handler) {
throw new NotFound("No handler for messages of type `$class`.");
}

return $handler;
return $this->handlers[$class]
?? throw new NotFound("No handler for messages of type `$class`.");
}
}
39 changes: 6 additions & 33 deletions lib/Symfony/HandlerProviderPass.php
Expand Up @@ -32,36 +32,12 @@ class HandlerProviderPass implements CompilerPassInterface
public const DEFAULT_MESSAGE_PROPERTY = 'message';
public const DEFAULT_PROVIDER_CLASS = ContainerHandlerProvider::class;

/**
* @var string
*/
private $serviceId;

/**
* @var string
*/
private $handlerTag;

/**
* @var string
*/
private $messageProperty;

/**
* @var string
*/
private $providerClass;

public function __construct(
string $serviceId = self::DEFAULT_SERVICE_ID,
string $handlerTag = self::DEFAULT_HANDLER_TAG,
string $messageProperty = self::DEFAULT_MESSAGE_PROPERTY,
string $providerClass = self::DEFAULT_PROVIDER_CLASS
private string $serviceId = self::DEFAULT_SERVICE_ID,
private string $handlerTag = self::DEFAULT_HANDLER_TAG,
private string $messageProperty = self::DEFAULT_MESSAGE_PROPERTY,
private string $providerClass = self::DEFAULT_PROVIDER_CLASS
) {
$this->serviceId = $serviceId;
$this->handlerTag = $handlerTag;
$this->messageProperty = $messageProperty;
$this->providerClass = $providerClass;
}

/**
Expand Down Expand Up @@ -92,13 +68,10 @@ private function collectHandlers(ContainerBuilder $container): array
foreach ($handlers as $id => $tags) {
assert(is_string($id));

$command = $tags[0][$messageProperty] ?? null;

if (!$command) {
throw new InvalidArgumentException(
$command = $tags[0][$messageProperty]
?? throw new InvalidArgumentException(
"The `$messageProperty` property is required for service `$id`."
);
}

assert(is_string($command));

Expand Down
30 changes: 13 additions & 17 deletions phpunit.xml
@@ -1,19 +1,15 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="icanboogie/message-bus">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./lib</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" colors="true"
bootstrap="./vendor/autoload.php">
<coverage>
<include>
<directory suffix=".php">./lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="icanboogie/message-bus">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
14 changes: 7 additions & 7 deletions tests/AssertingDispatcherTest.php
Expand Up @@ -13,14 +13,14 @@

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

class AssertingDispatcherTest extends TestCase
final class AssertingDispatcherTest extends TestCase
{
/**
* @var Dispatcher|ObjectProphecy
*/
private $dispatcher;
use ProphecyTrait;

private Dispatcher|ObjectProphecy $dispatcher;

protected function setUp(): void
{
Expand All @@ -29,7 +29,7 @@ protected function setUp(): void
parent::setUp();
}

public function testBubbleFailure()
public function testBubbleFailure(): void
{
$message = (object) [];
$exception = new \Exception();
Expand All @@ -54,7 +54,7 @@ function ($actual) use ($message, $exception) {
$this->fail("Expected exception");
}

public function testDispatch()
public function testDispatch(): void
{
$message = (object) [];
$result = uniqid();
Expand Down
9 changes: 9 additions & 0 deletions tests/HandlerA.php
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\MessageBus;

class HandlerA
Expand Down
9 changes: 9 additions & 0 deletions tests/HandlerB.php
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ICanBoogie\MessageBus;

class HandlerB
Expand Down
4 changes: 2 additions & 2 deletions tests/NotFoundTest.php
Expand Up @@ -15,9 +15,9 @@

use function uniqid;

class NotFoundTest extends TestCase
final class NotFoundTest extends TestCase
{
public function testException()
public function testException(): void
{
$exception = new NotFound($message = uniqid(), $previous = new \Exception());

Expand Down

0 comments on commit 893f231

Please sign in to comment.