diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..c9b363c --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,54 @@ +name: Test + +on: + push: + branches-ignore: + - 'master' + tags-ignore: + - '**' + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: 7.4 + coverage: none + - uses: actions/cache@v2 + with: + path: vendor + key: php-7.4-vendor-${{ hashFiles('**/composer.json') }} + restore-keys: php-7.4-vendor- + - run: composer install --no-interaction --no-ansi + - id: set-php-versions + run: echo "::set-output name=php-versions::$(vendor/bin/devtools list:php-versions)" + - id: set-tools + run: echo "::set-output name=tools::$(vendor/bin/devtools list:enabled-tools)" + outputs: + php-versions: ${{ steps.set-php-versions.outputs.php-versions }} + tools: ${{ steps.set-tools.outputs.tools }} + + test: + needs: setup + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ${{ fromJson(needs.setup.outputs.php-versions) }} + tool: ${{ fromJson(needs.setup.outputs.tools) }} + fail-fast: false + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + ini-values: date.timezone=Europe/Amsterdam, assert.exception=1, zend.assertions=1 + - uses: actions/cache@v2 + with: + path: vendor + key: php-${{ matrix.php-version }}-vendor-${{ hashFiles('**/composer.json') }} + restore-keys: php-${{ matrix.php-version }}-vendor- + - run: composer install --no-interaction --no-ansi + + - run: vendor/bin/devtools ${{ matrix.tool }} diff --git a/.gitignore b/.gitignore index 52b38ed..0f54b53 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.idea /.DS_Store /.phpcs-cache +/.phpunit.result.cache /vendor /composer.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 95277e2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -language: php - -matrix: - include: - - php: 7.0 - env: SYMFONY_VERSION="^3.0" - - - php: 7.1 - env: SYMFONY_VERSION="^3.0" - - php: 7.1 - env: SYMFONY_VERSION="^4.0" - - - php: 7.2 - env: SYMFONY_VERSION="^3.0" - - php: 7.2 - env: SYMFONY_VERSION="^4.0" - -env: - global: - - SYMFONY_VERSION="" - -before_install: - - if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/framework-bundle "$SYMFONY_VERSION"; fi - -install: - - composer install --prefer-source - -before_script: - - composer self-update - - composer install --prefer-source diff --git a/composer.json b/composer.json index fc4d9ce..395171a 100644 --- a/composer.json +++ b/composer.json @@ -15,21 +15,23 @@ } }, "require": { - "php": "^7.0.33", - "league/tactician": "^1.0" + "php": "^7.4 | ^8.0", + "league/tactician": "^1.1" }, "require-dev": { - "myonlinestore/coding-standard": "^1.0", - "phpunit/phpunit": "^6.5" + "myonlinestore/coding-standard": "^3.1", + "myonlinestore/php-devtools": "^0.2", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^4.18" }, "config": { - "vendor-dir": "vendor", "preferred-install": { "*": "dist" }, "sort-packages": true, - "platform": { - "php": "7.0.33" + "allow-plugins": { + "composer/package-versions-deprecated": true, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2112fc9..1bca7d1 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -13,7 +13,7 @@ tests - - + + diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 4294212..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - tests - - - - - src - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..5ef4977 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + + src + + + + + + tests + + + diff --git a/psalm.xml.dist b/psalm.xml.dist new file mode 100644 index 0000000..20cdecb --- /dev/null +++ b/psalm.xml.dist @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/src/Application/CommandBusInterface.php b/src/Application/CommandBusInterface.php index f2cb559..18fa59b 100644 --- a/src/Application/CommandBusInterface.php +++ b/src/Application/CommandBusInterface.php @@ -10,11 +10,10 @@ interface CommandBusInterface /** * Executes the given command and optionally returns a value * - * @param object $command - * * @return mixed * * @throws CommandFailedException */ - public function handle($command); + // phpcs:ignore SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint + public function handle(object $command); } diff --git a/src/Domain/Exception/CommandFailedException.php b/src/Domain/Exception/CommandFailedException.php index e91748d..ce27a08 100644 --- a/src/Domain/Exception/CommandFailedException.php +++ b/src/Domain/Exception/CommandFailedException.php @@ -7,6 +7,6 @@ final class CommandFailedException extends \RuntimeException { public static function wrap(\Throwable $previous): self { - return new self($previous->getMessage(), $previous->getCode(), $previous); + return new self($previous->getMessage(), (int) $previous->getCode(), $previous); } } diff --git a/src/Infrastructure/League/Tactician/CommandBus.php b/src/Infrastructure/League/Tactician/CommandBus.php index fe0dc4d..6463892 100644 --- a/src/Infrastructure/League/Tactician/CommandBus.php +++ b/src/Infrastructure/League/Tactician/CommandBus.php @@ -8,10 +8,7 @@ final class CommandBus implements CommandBusInterface { - /** - * @var TacticianCommandBus - */ - private $commandBus; + private TacticianCommandBus $commandBus; public function __construct(TacticianCommandBus $commandBus) { @@ -21,7 +18,7 @@ public function __construct(TacticianCommandBus $commandBus) /** * @inheritdoc */ - public function handle($command) + public function handle(object $command) { return $this->commandBus->handle($command); } diff --git a/tests/Domain/Exception/CommandFailedExceptionTest.php b/tests/Domain/Exception/CommandFailedExceptionTest.php index 2129008..c345796 100644 --- a/tests/Domain/Exception/CommandFailedExceptionTest.php +++ b/tests/Domain/Exception/CommandFailedExceptionTest.php @@ -8,7 +8,7 @@ final class CommandFailedExceptionTest extends TestCase { - public function testWrap() + public function testWrap(): void { $commandFailed = CommandFailedException::wrap( $previous = new \Exception('Foobar', 234) diff --git a/tests/Infrastructure/MyOnlineStore/Infrastructure/League/Tactician/CommandBusTest.php b/tests/Infrastructure/League/Tactician/CommandBusTest.php similarity index 72% rename from tests/Infrastructure/MyOnlineStore/Infrastructure/League/Tactician/CommandBusTest.php rename to tests/Infrastructure/League/Tactician/CommandBusTest.php index f65aa51..17ab5c0 100644 --- a/tests/Infrastructure/MyOnlineStore/Infrastructure/League/Tactician/CommandBusTest.php +++ b/tests/Infrastructure/League/Tactician/CommandBusTest.php @@ -5,28 +5,23 @@ use League\Tactician\CommandBus as TacticianCommandBus; use MyOnlineStore\CommandBus\Infrastructure\League\Tactician\CommandBus; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; final class CommandBusTest extends TestCase { - /** - * @var TacticianCommandBus - */ - private $tacticianCommandBus; + /** @var TacticianCommandBus&MockObject */ + private TacticianCommandBus $tacticianCommandBus; + private CommandBus $commandBus; - /** - * @var CommandBus - */ - private $commandBus; - - protected function setUp() + protected function setUp(): void { $this->tacticianCommandBus = $this->createMock(TacticianCommandBus::class); $this->commandBus = new CommandBus($this->tacticianCommandBus); } - public function testWillThrowOnTheBus() + public function testWillThrowOnTheBus(): void { $command = new \stdClass();