Skip to content

Commit

Permalink
Merge pull request #125 from acasademont/php8_fix
Browse files Browse the repository at this point in the history
Remove PHP8 deprecation notices
  • Loading branch information
rosstuck authored Jan 31, 2021
2 parents 66b9747 + 3924ba5 commit 89c5127
Show file tree
Hide file tree
Showing 21 changed files with 83 additions and 75 deletions.
25 changes: 5 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,23 @@ cache:
- "$HOME/.composer/cache"

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0

env:
matrix:
- DOCTRINE="true"
- DOCTRINE="false"
- SYMFONY_VERSION="2.8.*"
- SYMFONY_VERSION="3.3.*"
- SYMFONY_VERSION="3.4.*"
- SYMFONY_VERSION="4.0.*"
- SYMFONY_VERSION="4.1.*"
- SYMFONY_VERSION="4.2.*"
- SYMFONY_VERSION="4.4.*"
- SYMFONY_VERSION="5.2.*"

matrix:
include:
- php: 7.0
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.0
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" DOCTRINE="false"
exclude:
- php: 7.0
env: SYMFONY_VERSION="4.0.*"
- php: 7.0
env: SYMFONY_VERSION="4.1.*"
- php: 7.0
env: SYMFONY_VERSION="4.2.*"
- php: 7.4
env: SYMFONY_VERSION="4.1.*"

before_install:
- echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.3.0
- #125 - PHP 8.0 compatibility fixes

## 1.2.0
- #121 - Multiple buses can now be autowired based on the parameter name

Expand Down
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"MIT"
],
"require" : {
"php": ">=7.0",
"php": ">=7.2",
"league/tactician": "^1.0",
"league/tactician-logger": "^0.10.0",
"league/tactician-container": "^2.0",
"symfony/config": "^2.8|^3.3|^4.0|^5.0",
"symfony/dependency-injection": "^2.8|^3.3|^4.0|^5.0",
"symfony/http-kernel": "^2.8|^3.3|^4.0|^5.0",
"symfony/yaml": "^2.8|^3.3|^4.0|^5.0"
"symfony/config": "^3.4|^4.4|^5.0",
"symfony/dependency-injection": "^3.4|^4.4|^5.0",
"symfony/http-kernel": "^3.4|^4.4|^5.0",
"symfony/yaml": "^3.4|^4.4|^5.0"
},
"minimum-stability": "beta",
"suggest": {
Expand All @@ -61,15 +61,14 @@
}
},
"require-dev": {
"phpunit/phpunit": "~6.1",
"phpunit/phpunit": "~8.5",
"mockery/mockery": "~1.0",
"symfony/console": "^2.8|^3.3|^4.0|^5.0",
"symfony/security": "^2.8|^3.3|^4.0|^5.0",
"symfony/validator": "^2.8|^3.3|^4.0|^5.0",
"league/tactician-doctrine": "^1.1.1",
"symfony/framework-bundle": "^2.8.15|^3.3|^4.0|^5.0",
"symfony/security-bundle": "^2.8|^3.3|^4.0|^5.0",
"matthiasnoback/symfony-config-test": "^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^2.1"
"symfony/console": "^3.4|^4.4|^5.0",
"symfony/security-core": "^3.4|^4.4|^5.0",
"symfony/validator": "^3.4|^4.4|^5.0",
"symfony/framework-bundle": "^3.4.31|^4.4|^5.0",
"symfony/security-bundle": "^3.4|^4.4|^5.0",
"matthiasnoback/symfony-config-test": "^4.2.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.2.1"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
Expand Down
2 changes: 2 additions & 0 deletions src/Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function execute(InputInterface $input, OutputInterface $output)
$io->warning("No registered commands for bus $busId");
}
}

return 0;
}

private function mappingToRows(array $map)
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/HandlerMapping/TypeHintMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ protected function findCommandsForService(ContainerBuilder $container, Definitio

$parameter = $method->getParameters()[0];
if (!$parameter->hasType()
|| $parameter->getType() instanceof \ReflectionUnionType
|| $parameter->getType()->isBuiltin()
|| $parameter->getClass()->isInterface()
|| (new ReflectionClass($parameter->getType()->getName()))->isInterface()
) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CommandHandlerPassTest extends TestCase
*/
private $mappingStrategy;

protected function setUp()
protected function setUp(): void
{
$this->mappingStrategy = new ClassNameMapping();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

class DoctrineMiddlewarePassTest extends AbstractCompilerPassTestCase
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();

$this->container->set('doctrine.orm.default_entity_manager', new stdClass());
$this->container->set('doctrine.orm.second_entity_manager', new stdClass());
}

protected function registerCompilerPass(ContainerBuilder $container)
protected function registerCompilerPass(ContainerBuilder $container): void
{
$container->addCompilerPass(new DoctrineMiddlewarePass());
}
Expand Down
4 changes: 3 additions & 1 deletion tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public function testMiddlewareMustBeScalar()
]
]
],
'Invalid type for path "tactician.commandbus.default.middleware.my_middleware". Expected scalar, but got array.'
//we use a regexp to support the slightly different message thrown by symfony >=5.0
'#Invalid type for path "tactician.commandbus.default.middleware.my_middleware"\. Expected "?scalar"?, but got "?array"?\.#',
true
);
}

Expand Down
23 changes: 11 additions & 12 deletions tests/DependencyInjection/HandlerMapping/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
namespace League\Tactician\Bundle\Tests\DependencyInjection\HandlerMapping;

use League\Tactician\Bundle\DependencyInjection\HandlerMapping\Routing;
use League\Tactician\Bundle\DependencyInjection\InvalidCommandBusId;
use League\Tactician\Bundle\Tests\Fake\FakeCommand;
use League\Tactician\Bundle\Tests\Fake\OtherFakeCommand;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;

final class RoutingTest extends TestCase
{
Expand Down Expand Up @@ -42,32 +44,29 @@ public function test_mixture_of_broadcast_and_specific_routing_commands()
$this->assertEquals([FakeCommand::class => 'very.broad.handler'], $routing->commandToServiceMapping('bus2'));
}

/**
* @expectedException \League\Tactician\Bundle\DependencyInjection\InvalidCommandBusId
* @expectedExceptionMessage Could not find a command bus with id 'fake_bus'. Valid buses are: default
*/
public function test_can_not_get_mapping_for_unknown_bus()
{
$this->expectException(InvalidCommandBusId::class);
$this->expectExceptionMessage('Could not find a command bus with id \'fake_bus\'. Valid buses are: default');

$routing = new Routing(['default']);
$routing->commandToServiceMapping('fake_bus');
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage Can not route Legit\Class to some.handler.service, class Legit\Class does not exist!
*/
public function test_will_not_route_unknown_class_name()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Can not route Legit\Class to some.handler.service, class Legit\Class does not exist!');

$routing = new Routing(['default']);
$routing->routeToBus('default', 'Legit\Class', 'some.handler.service');
}

/**
* @expectedException \League\Tactician\Bundle\DependencyInjection\InvalidCommandBusId
* @expectedExceptionMessage Could not find a command bus with id 'bus3'. Valid buses are: bus1, bus2
*/
public function test_will_not_accept_command_on_invalid_bus_id()
{
$this->expectException(InvalidCommandBusId::class);
$this->expectExceptionMessage('Could not find a command bus with id \'bus3\'. Valid buses are: bus1, bus2');

$routing = new Routing(['bus1', 'bus2']);
$routing->routeToBus('bus3', FakeCommand::class, 'some.handler.service');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function test_standard(string $handlerFQCN, array $expectedMapping)

public function simpleTestCases()
{
return [
$cases = [
'can read __invoke magic method type hint' => [
InvokeHandler::class,
[FakeCommand::class => 'some.handler']
Expand All @@ -79,6 +79,13 @@ public function simpleTestCases()
'will not use abstract methods' => [AbstractHandler::class, []],
'will not use variadic methods' => [VariadicHandler::class, []]
];

if (version_compare(PHP_VERSION, '8.0.0') >= 0) {
require 'php8_handlers.php';
$cases['will not use union type methods'] = [UnionTypeHandler::class, []];
}

return $cases;
}

public function test_can_bind_to_specific_bus()
Expand Down
10 changes: 10 additions & 0 deletions tests/DependencyInjection/HandlerMapping/php8_handlers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace League\Tactician\Bundle\Tests\DependencyInjection\HandlerMapping;

class UnionTypeHandler
{
public function handle(int|bool $foo)
{
}
}
2 changes: 1 addition & 1 deletion tests/DependencyInjection/TacticianExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TacticianExtensionTest extends AbstractExtensionTestCase
*
* @return ExtensionInterface[]
*/
protected function getContainerExtensions()
protected function getContainerExtensions(): array
{
return [
new TacticianExtension()
Expand Down
6 changes: 3 additions & 3 deletions tests/Handler/ContainerBasedHandlerLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace League\Tactician\Bundle\Tests\Handler;

use League\Tactician\Bundle\Handler\ContainerBasedHandlerLocator;
use League\Tactician\Exception\MissingHandlerException;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand All @@ -22,11 +23,10 @@ public function testGetHandler()
$this->assertInstanceOf('stdClass', $locator->getHandlerForCommand('FakeCommand'));
}

/**
* @expectedException \League\Tactician\Exception\MissingHandlerException
*/
public function testGetHandlerThrowsExceptionForNotFound()
{
$this->expectException(MissingHandlerException::class);

$locator = new ContainerBasedHandlerLocator(new ContainerBuilder(), [
'OtherCommand' => 'my_bundle.order.id'
]);
Expand Down
22 changes: 11 additions & 11 deletions tests/Integration/BasicCommandAndBusMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace League\Tactician\Bundle\Tests\Integration;

use League\Tactician\Bundle\DependencyInjection\InvalidCommandBusId;
use League\Tactician\Exception\MissingHandlerException;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

/**
* @runTestsInSeparateProcesses
Expand All @@ -19,11 +22,10 @@ public function testHandleCommandOnDefaultBus()
$this->handleCommand('default', \League\Tactician\Bundle\Tests\EchoText::class, ['Hello world']);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testHandleCommandWithInvalidMiddleware()
{
$this->expectException(ServiceNotFoundException::class);

$this->givenConfig('tactician', <<<'EOF'
commandbus:
default:
Expand Down Expand Up @@ -77,12 +79,11 @@ public function testHandleCommandOnSpecificBus()
$this->handleCommand('other', \League\Tactician\Bundle\Tests\EchoText::class, ['Welcome']);
}

/**
* @expectedException \League\Tactician\Bundle\DependencyInjection\InvalidCommandBusId
* @expectedExceptionMessage Could not find a command bus with id 'other'. Valid buses are: default
*/
public function testHandlerOnUnknownBus()
public function testHandlerOnUnknownBus()
{
$this->expectException(InvalidCommandBusId::class);
$this->expectExceptionMessage('Could not find a command bus with id \'other\'. Valid buses are: default');

$this->givenConfig('tactician', <<<'EOF'
commandbus:
default:
Expand Down Expand Up @@ -112,11 +113,10 @@ public function testInvalidDefaultBus()
static::$kernel->boot();
}

/**
* @expectedException \League\Tactician\Exception\MissingHandlerException
*/
public function testHandleCommandSpecifiedOnAnotherBus()
{
$this->expectException(MissingHandlerException::class);

$this->givenConfig('tactician', <<<'EOF'
commandbus:
default:
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected static function createKernel(array $options = array())
return new \AppKernel('test', true);
}

protected function setUp()
protected function setUp(): void
{
static::$kernel = static::createKernel();
$this->filesystem = new Filesystem();
Expand All @@ -39,7 +39,7 @@ protected function setUp()
static::$kernel->defineCacheDir($cacheDir);
}

protected function tearDown()
protected function tearDown(): void
{
$this->filesystem->remove(
static::$kernel->getCacheDir()
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/MappingPrecedenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
final class MappingPrecedenceTest extends IntegrationTest
{
protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function setUserRole(string $role)
static::$kernel->getContainer()
->get('security.token_storage')
->setToken(
new AnonymousToken('test', 'anon', [new Role($role)])
new AnonymousToken('test', 'anon', [$role])
);
}
}
2 changes: 1 addition & 1 deletion tests/Middleware/SecurityMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SecurityMiddlewareTest extends TestCase
/**
* Set up.
*/
public function setUp()
public function setUp(): void
{
$this->authorizationChecker = Mockery::mock(AuthorizationCheckerInterface::class);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Middleware/ValidatorMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ValidatorMiddlewareTest extends TestCase
*/
protected $middleware;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Security/Voter/HandleCommandVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HandleCommandVoterTest extends TestCase
*/
private $decisionManager;

public function setUp()
public function setUp(): void
{
$this->decisionManager = Mockery::mock(AccessDecisionManager::class);
}
Expand Down

0 comments on commit 89c5127

Please sign in to comment.