Skip to content

Commit

Permalink
Update to PHP 8.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Mar 13, 2024
1 parent 141d0d6 commit 6a58685
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 261 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = false
max_line_length = 120
tab_width = 4
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
Expand All @@ -32,7 +32,7 @@ jobs:
composer-flags: ['']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -45,10 +45,6 @@ jobs:

- run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: "Use PHPUnit 9.3+ on PHP 8"
run: composer require --no-update --dev phpunit/phpunit:^9.3
if: "matrix.php == '8.0'"

- run: composer update --no-progress ${{ matrix.composer-flags }}

- run: vendor/bin/phpunit --no-coverage
Expand All @@ -65,7 +61,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ composer.phar
vendor
.sass-cache
.phpunit.result.cache
.phpunit.cache
.phpcs-cache
docs/.jekyll-cache
docs/_site
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
level: 5
treatPhpDocTypesAsCertain: false
paths:
- src
34 changes: 14 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="League Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
18 changes: 9 additions & 9 deletions src/Argument/LiteralArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

class LiteralArgument implements LiteralArgumentInterface
{
public const TYPE_ARRAY = 'array';
public const TYPE_BOOL = 'boolean';
public const TYPE_BOOLEAN = 'boolean';
public const TYPE_ARRAY = 'array';
public const TYPE_BOOL = 'boolean';
public const TYPE_BOOLEAN = 'boolean';
public const TYPE_CALLABLE = 'callable';
public const TYPE_DOUBLE = 'double';
public const TYPE_FLOAT = 'double';
public const TYPE_INT = 'integer';
public const TYPE_INTEGER = 'integer';
public const TYPE_OBJECT = 'object';
public const TYPE_STRING = 'string';
public const TYPE_DOUBLE = 'double';
public const TYPE_FLOAT = 'double';
public const TYPE_INT = 'integer';
public const TYPE_INTEGER = 'integer';
public const TYPE_OBJECT = 'object';
public const TYPE_STRING = 'string';

/**
* @var mixed
Expand Down
24 changes: 5 additions & 19 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,17 @@ public function addServiceProvider(ServiceProviderInterface $provider): Definiti
return $this;
}

/**
* @template RequestedType
*
* @param class-string<RequestedType>|string $id
*
* @return RequestedType|mixed
*/
public function get($id)
public function get(string $id)
{
return $this->resolve($id);
}

/**
* @template RequestedType
*
* @param class-string<RequestedType>|string $id
*
* @return RequestedType|mixed
*/
public function getNew($id)
public function getNew(string $id): mixed
{
return $this->resolve($id, true);
}

public function has($id): bool
public function has(string $id): bool
{
if ($this->definitions->has($id)) {
return true;
Expand Down Expand Up @@ -169,7 +155,7 @@ public function delegate(ContainerInterface $container): self
return $this;
}

protected function resolve($id, bool $new = false)
protected function resolve(string $id, bool $new = false)
{
if ($this->definitions->has($id)) {
$resolved = (true === $new) ? $this->definitions->resolveNew($id) : $this->definitions->resolve($id);
Expand All @@ -191,7 +177,7 @@ protected function resolve($id, bool $new = false)
if ($this->providers->provides($id)) {
$this->providers->register($id);

if (!$this->definitions->has($id) && !$this->definitions->hasTag($id)) {
if (false === $this->definitions->has($id) && false === $this->definitions->hasTag($id)) {
throw new ContainerException(sprintf('Service provider lied about providing (%s) service', $id));
}

Expand Down
8 changes: 2 additions & 6 deletions src/Definition/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,10 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
*/
protected $resolved;

/**
* @param string $id
* @param mixed|null $concrete
*/
public function __construct(string $id, $concrete = null)
public function __construct(string $id, mixed $concrete = null)
{
$concrete ??= $id;
$this->alias = $id;
$this->alias = $id;
$this->concrete = $concrete;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Definition/DefinitionAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DefinitionAggregate implements DefinitionAggregateInterface
/**
* @var DefinitionInterface[]
*/
protected $definitions = [];
protected array $definitions = [];

public function __construct(array $definitions = [])
{
Expand Down
2 changes: 1 addition & 1 deletion src/DefinitionContainerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function add(string $id, $concrete = null): DefinitionInterface;
public function addServiceProvider(ServiceProviderInterface $provider): self;
public function addShared(string $id, $concrete = null): DefinitionInterface;
public function extend(string $id): DefinitionInterface;
public function getNew($id);
public function getNew(string $id): mixed;
public function inflector(string $type, callable $callback = null): InflectorInterface;
}
8 changes: 6 additions & 2 deletions src/ServiceProvider/AbstractServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ abstract class AbstractServiceProvider implements ServiceProviderInterface
/**
* @var string
*/
protected $identifier;
protected string $identifier;

public function getIdentifier(): string
{
return $this->identifier ?? get_class($this);
if (empty($this->identifier)) {
$this->identifier = get_class($this);
}

return $this->identifier;
}

public function setIdentifier(string $id): ServiceProviderInterface
Expand Down
65 changes: 32 additions & 33 deletions tests/Argument/ArgumentResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ public function testResolverResolvesFromContainer(): void

$container = $this->getMockBuilder(Container::class)->getMock();

$matcher = $this->exactly(2);

$container
->expects(self::at(0))
->expects($matcher)
->method('has')
->with(self::equalTo('alias1'))
->willReturn(true)
->willReturnOnConsecutiveCalls(true, false)
;

$container->expects(self::at(1))->method('get')->with(self::equalTo('alias1'))->willReturn($resolver);
$container->expects(self::at(2))->method('has')->with(self::equalTo('alias2'))->willReturn(false);
$container->expects($this->once())->method('get')->with($this->equalTo('alias1'))->willReturn($resolver);

/** @var Container $container */
$resolver->setContainer($container);

$args = $resolver->resolveArguments(['alias1', 'alias2']);

self::assertSame($resolver, $args[0]);
self::assertSame('alias2', $args[1]);
$this->assertSame($resolver, $args[0]);
$this->assertSame('alias2', $args[1]);
}

public function testResolverResolvesLiteralArguments(): void
Expand All @@ -54,16 +54,15 @@ public function testResolverResolvesLiteralArguments(): void
$container = $this->getMockBuilder(Container::class)->getMock();

$container
->expects(self::at(0))
->expects($this->once())
->method('has')
->with(self::equalTo('alias1'))
->willReturn(true)
->willReturnOnConsecutiveCalls(true, false)
;

$container
->expects(self::at(1))
->expects($this->once())
->method('get')
->with(self::equalTo('alias1'))
->with($this->equalTo('alias1'))
->willReturn(new Literal\StringArgument('value1'))
;

Expand All @@ -72,8 +71,8 @@ public function testResolverResolvesLiteralArguments(): void

$args = $resolver->resolveArguments(['alias1', new Literal\StringArgument('value2')]);

self::assertSame('value1', $args[0]);
self::assertSame('value2', $args[1]);
$this->assertSame('value1', $args[0]);
$this->assertSame('value2', $args[1]);
}

public function testResolverResolvesArgumentsViaReflection(): void
Expand All @@ -85,21 +84,21 @@ public function testResolverResolvesArgumentsViaReflection(): void
$class = $this->getMockBuilder(ReflectionNamedType::class)->disableOriginalConstructor()->getMock();
$container = $this->getMockBuilder(Container::class)->getMock();

$class->expects(self::once())->method('getName')->willReturn('Class');
$param1->expects(self::once())->method('getName')->willReturn('param1');
$param1->expects(self::once())->method('getType')->willReturn($class);
$class->expects($this->once())->method('getName')->willReturn('Class');
$param1->expects($this->once())->method('getName')->willReturn('param1');
$param1->expects($this->once())->method('getType')->willReturn($class);

$param2->expects(self::once())->method('getName')->willReturn('param2');
$param2->expects(self::once())->method('getType')->willReturn(null);
$param2->expects(self::once())->method('isDefaultValueAvailable')->willReturn(true);
$param2->expects(self::once())->method('getDefaultValue')->willReturn('value2');
$param2->expects($this->once())->method('getName')->willReturn('param2');
$param2->expects($this->once())->method('getType')->willReturn(null);
$param2->expects($this->once())->method('isDefaultValueAvailable')->willReturn(true);
$param2->expects($this->once())->method('getDefaultValue')->willReturn('value2');

$param3->expects(self::once())->method('getName')->willReturn('param3');
$param3->expects($this->once())->method('getName')->willReturn('param3');

$method->expects(self::once())->method('getParameters')->willReturn([$param1, $param2, $param3]);
$method->expects($this->once())->method('getParameters')->willReturn([$param1, $param2, $param3]);

$container->expects(self::once())->method('has')->with($this->equalTo('Class'))->willReturn(true);
$container->expects(self::once())->method('get')->with($this->equalTo('Class'))->willReturn('classObject');
$container->expects($this->once())->method('has')->with($this->equalTo('Class'))->willReturn(true);
$container->expects($this->once())->method('get')->with($this->equalTo('Class'))->willReturn('classObject');

$resolver = new class implements ArgumentResolverInterface {
use ArgumentResolverTrait;
Expand All @@ -111,9 +110,9 @@ public function testResolverResolvesArgumentsViaReflection(): void

$args = $resolver->reflectArguments($method, ['param3' => 'value3']);

self::assertSame('classObject', $args[0]);
self::assertSame('value2', $args[1]);
self::assertSame('value3', $args[2]);
$this->assertSame('classObject', $args[0]);
$this->assertSame('value2', $args[1]);
$this->assertSame('value3', $args[2]);
}

public function testResolvesDefaultValueArgument(): void
Expand All @@ -124,7 +123,7 @@ public function testResolvesDefaultValueArgument(): void
};

$result = $resolver->reflectArguments((new ReflectionClass(Baz::class))->getConstructor());
self::assertSame([null], $result);
$this->assertSame([null], $result);
}

public function testResolverThrowsExceptionWhenReflectionDoesNotResolve(): void
Expand All @@ -134,11 +133,11 @@ public function testResolverThrowsExceptionWhenReflectionDoesNotResolve(): void
$method = $this->getMockBuilder(ReflectionFunctionAbstract::class)->getMock();
$param = $this->getMockBuilder(ReflectionParameter::class)->disableOriginalConstructor()->getMock();

$param->expects(self::once())->method('getName')->willReturn('param1');
$param->expects(self::once())->method('getType')->willReturn(null);
$param->expects(self::once())->method('isDefaultValueAvailable')->willReturn(false);
$param->expects($this->once())->method('getName')->willReturn('param1');
$param->expects($this->once())->method('getType')->willReturn(null);
$param->expects($this->once())->method('isDefaultValueAvailable')->willReturn(false);

$method->expects(self::once())->method('getParameters')->willReturn([$param]);
$method->expects($this->once())->method('getParameters')->willReturn([$param]);

$resolver = new class implements ArgumentResolverInterface {
use ArgumentResolverTrait;
Expand Down
2 changes: 1 addition & 1 deletion tests/Argument/TypedArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testLiteralArgumentSetsAndGetsArgument(): void

foreach ($arguments as $type => $expected) {
$argument = new $type($expected);
self::assertSame($expected, $argument->getValue());
$this->assertSame($expected, $argument->getValue());
}
}

Expand Down
Loading

0 comments on commit 6a58685

Please sign in to comment.