Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
/ container Public archive
generated from spaceonfire/skeleton

Commit

Permalink
Merge pull request #10 from spaceonfire/php8
Browse files Browse the repository at this point in the history
chore: support installation on PHP 8
  • Loading branch information
tntrex authored Feb 19, 2021
2 parents b5a0bb0 + 447c90f commit ea3ef1b
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 61 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ jobs:
COMPOSER_CACHE_KEY: 'composer-7.2'
with:
path: vendor
key: ${{ env.COMPOSER_CACHE_KEY }}
key: ${{ env.COMPOSER_CACHE_KEY }}-${{ hashFiles('composer.json') }}
restore-keys: ${{ env.COMPOSER_CACHE_KEY }}

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
run: |
/opt/spaceonfire/bin/select-composer.sh v2
composer install --prefer-dist --no-progress
- name: Check coding standard
run: vendor/bin/ecs check --no-progress-bar --no-interaction
Expand All @@ -58,12 +59,13 @@ jobs:
COMPOSER_CACHE_KEY: 'composer-7.2'
with:
path: vendor
key: ${{ env.COMPOSER_CACHE_KEY }}
key: ${{ env.COMPOSER_CACHE_KEY }}-${{ hashFiles('composer.json') }}
restore-keys: ${{ env.COMPOSER_CACHE_KEY }}

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
run: |
/opt/spaceonfire/bin/select-composer.sh v2
composer install --prefer-dist --no-progress
- name: PHPStan
run: vendor/bin/phpstan analyse --no-progress --no-interaction
Expand All @@ -76,6 +78,7 @@ jobs:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
container: spaceonfire/nginx-php-fpm:latest-${{ matrix.php-version }}
steps:
- name: Checkout
Expand All @@ -88,18 +91,19 @@ jobs:
COMPOSER_CACHE_KEY: 'composer-${{ matrix.php-version }}'
with:
path: vendor
key: ${{ env.COMPOSER_CACHE_KEY }}
key: ${{ env.COMPOSER_CACHE_KEY }}-${{ hashFiles('composer.json') }}
restore-keys: ${{ env.COMPOSER_CACHE_KEY }}

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
run: |
/opt/spaceonfire/bin/select-composer.sh v2
composer install --prefer-dist --no-progress
- name: PHPUnit
run: |
apk update
docker-php-ext-enable xdebug
vendor/bin/phpunit --no-interaction
php -d xdebug.mode=coverage vendor/bin/phpunit --no-interaction
cat build/coverage.txt
- name: PHPUnit Artifacts
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- Nothing
-->

## [2.4.1] - 2020-02-19

### Added

- Support installation on PHP 8

## [2.4.0] - 2020-12-19

### Added
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"psr/container": "^1.0",
"spaceonfire/collection": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^8.5|^9.5",
"phpspec/prophecy-phpunit": "^1.1|^2.0",
"phpstan/phpstan": "^0.12",
"roave/security-advisories": "dev-master",
"symplify/easy-coding-standard-prefixed": "^8.3"
"symplify/easy-coding-standard-prefixed": "^8.3|^9.1"
},
"provide": {
"psr/container-implementation": "^1.0"
Expand All @@ -50,7 +51,7 @@
}
},
"scripts": {
"test": "phpunit",
"test": "@php -d xdebug.mode=coverage `which phpunit`",
"codestyle": "ecs check --ansi",
"lint": "phpstan analyze --memory-limit=512M --ansi"
},
Expand Down
20 changes: 20 additions & 0 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace spaceonfire\Container;

use PHPUnit\Framework\TestCase;

if (trait_exists('\Prophecy\PhpUnit\ProphecyTrait')) {
abstract class AbstractTestCase extends TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
use WithContainerMockTrait;
}
} else {
abstract class AbstractTestCase extends TestCase
{
use WithContainerMockTrait;
}
}
7 changes: 2 additions & 5 deletions tests/Argument/ArgumentResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@

namespace spaceonfire\Container\Argument;

use PHPUnit\Framework\TestCase;
use ReflectionMethod;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Exception\ContainerException;
use spaceonfire\Container\Fixtures\A;
use spaceonfire\Container\Fixtures\B;
use spaceonfire\Container\Fixtures\MyClass;
use spaceonfire\Container\RawValueHolder;
use spaceonfire\Container\WithContainerMockTrait;

class ArgumentResolverTest extends TestCase
class ArgumentResolverTest extends AbstractTestCase
{
use WithContainerMockTrait;

/**
* @var ArgumentResolver
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/Argument/ArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace spaceonfire\Container\Argument;

use PHPUnit\Framework\TestCase;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Exception\ContainerException;
use spaceonfire\Container\RawValueHolder;

class ArgumentTest extends TestCase
class ArgumentTest extends AbstractTestCase
{
public function testGetName(): void
{
Expand Down
5 changes: 1 addition & 4 deletions tests/CompositeContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace spaceonfire\Container;

use ArrayIterator;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use spaceonfire\Collection\Collection;
Expand All @@ -15,10 +14,8 @@
use spaceonfire\Container\Fixtures\AbstractClass\AcceptNullableAbstractClass;
use spaceonfire\Container\Fixtures\AbstractClass\RequiresAbstractClass;

class CompositeContainerTest extends TestCase
class CompositeContainerTest extends AbstractTestCase
{
use WithContainerMockTrait;

public function testHas(): void
{
$composite = new CompositeContainer([
Expand Down
3 changes: 1 addition & 2 deletions tests/ContainerAwareTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace spaceonfire\Container;

use PHPUnit\Framework\TestCase;
use spaceonfire\Container\Exception\ContainerException;

class ContainerAwareTraitTest extends TestCase
class ContainerAwareTraitTest extends AbstractTestCase
{
private function factory()
{
Expand Down
12 changes: 5 additions & 7 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace spaceonfire\Container;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use spaceonfire\Container\Exception\ContainerException;
use spaceonfire\Container\Exception\NotFoundException;
use spaceonfire\Container\Fixtures\A;
Expand All @@ -14,7 +13,7 @@
use spaceonfire\Container\Fixtures\MyClass;
use spaceonfire\Container\Fixtures\MyClassProvider;

class ContainerTest extends TestCase
class ContainerTest extends AbstractTestCase
{
public function testAdd(): void
{
Expand Down Expand Up @@ -104,10 +103,6 @@ public function testInvoke(): void

self::assertSame('bar', $container->invoke(MyClass::class . '::staticMethod'));

$oldReporting = error_reporting(E_ALL ^ E_DEPRECATED);
self::assertSame('foo', $container->invoke([MyClass::class, 'method']));
error_reporting($oldReporting);

self::assertSame('foo', $container->invoke([new MyClass(), 'method']));

$invokable = new class {
Expand All @@ -118,7 +113,10 @@ public function __invoke()
};
self::assertSame(42, $container->invoke($invokable));

self::assertSame(42, $container->invoke('intval', ['var' => '42', 'base' => 10]));
self::assertSame(42, $container->invoke('intval', [
(PHP_VERSION_ID >= 80000 ? 'value' : 'var') => '42',
'base' => 10,
]));
}

public function testResolveDefinitionWithParentContainer(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Definition/DefinitionAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace spaceonfire\Container\Definition;

use PHPUnit\Framework\TestCase;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Exception\ContainerException;

class DefinitionAggregateTest extends TestCase
class DefinitionAggregateTest extends AbstractTestCase
{
public function testConstruct(): void
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Definition/DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

namespace spaceonfire\Container\Definition;

use PHPUnit\Framework\TestCase;
use Prophecy\Argument as ArgumentProphecy;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\Argument\Argument;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Exception\ContainerException;
use spaceonfire\Container\RawValueHolder;
use stdClass;

class DefinitionTest extends TestCase
class DefinitionTest extends AbstractTestCase
{

public function testGetters(): void
{
$foo = new Definition('foo');
Expand Down
7 changes: 2 additions & 5 deletions tests/Reflection/ReflectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

namespace spaceonfire\Container\Reflection;

use PHPUnit\Framework\TestCase;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\Argument\ArgumentResolver;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Exception\NotFoundException;
use spaceonfire\Container\Fixtures\A;
use spaceonfire\Container\Fixtures\B;
use spaceonfire\Container\WithContainerMockTrait;

class ReflectionFactoryTest extends TestCase
class ReflectionFactoryTest extends AbstractTestCase
{
use WithContainerMockTrait;

/**
* @var ReflectionFactory
*/
Expand Down
15 changes: 6 additions & 9 deletions tests/Reflection/ReflectionInvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

namespace spaceonfire\Container\Reflection;

use PHPUnit\Framework\TestCase;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\Argument\ArgumentResolver;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Fixtures\A;
use spaceonfire\Container\Fixtures\B;
use spaceonfire\Container\Fixtures\MyClass;
use spaceonfire\Container\WithContainerMockTrait;

class ReflectionInvokerTest extends TestCase
class ReflectionInvokerTest extends AbstractTestCase
{
use WithContainerMockTrait;

/**
* @var ReflectionInvoker
*/
Expand Down Expand Up @@ -46,24 +43,24 @@ protected function setUp(): void
*/
public function testInvoker($expect, $callable, $arguments = []): void
{
$oldReporting = error_reporting(E_ALL ^ E_DEPRECATED);
self::assertSame($expect, ($this->invoker)($callable, $arguments));
error_reporting($oldReporting);
}

public function dataProvider(): array
{
return [
['bar', MyClass::class . '::staticMethod'],
['foo', [MyClass::class, 'method']],
['foo', [new MyClass(), 'method']],
[42, new class {
public function __invoke()
{
return 42;
}
}],
[42, 'intval', ['var' => '42', 'base' => 10]],
[42, 'intval', [
(PHP_VERSION_ID >= 80000 ? 'value' : 'var') => '42',
'base' => 10,
]],
];
}
}
12 changes: 5 additions & 7 deletions tests/ReflectionContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace spaceonfire\Container;

use BadMethodCallException;
use PHPUnit\Framework\TestCase;
use spaceonfire\Container\Exception\ContainerException;
use spaceonfire\Container\Exception\NotFoundException;
use spaceonfire\Container\Fixtures\A;
Expand All @@ -14,7 +13,7 @@
use spaceonfire\Container\Fixtures\B;
use spaceonfire\Container\Fixtures\MyClass;

class ReflectionContainerTest extends TestCase
class ReflectionContainerTest extends AbstractTestCase
{
public function testHas(): void
{
Expand Down Expand Up @@ -44,10 +43,6 @@ public function testInvoke(): void

self::assertSame('bar', $container->invoke(MyClass::class . '::staticMethod'));

$oldReporting = error_reporting(E_ALL ^ E_DEPRECATED);
self::assertSame('foo', $container->invoke([MyClass::class, 'method']));
error_reporting($oldReporting);

self::assertSame('foo', $container->invoke([new MyClass(), 'method']));

$invokable = new class {
Expand All @@ -58,7 +53,10 @@ public function __invoke()
};
self::assertSame(42, $container->invoke($invokable));

self::assertSame(42, $container->invoke('intval', ['var' => '42', 'base' => 10]));
self::assertSame(42, $container->invoke('intval', [
(PHP_VERSION_ID >= 80000 ? 'value' : 'var') => '42',
'base' => 10,
]));
}

public function testAdd(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/ServiceProvider/ServiceProviderAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace spaceonfire\Container\ServiceProvider;

use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use spaceonfire\Container\AbstractTestCase;
use spaceonfire\Container\ContainerInterface;
use spaceonfire\Container\Definition\Definition;
use spaceonfire\Container\Exception\ContainerException;

class ServiceProviderAggregateTest extends TestCase
class ServiceProviderAggregateTest extends AbstractTestCase
{
private function createAggregate(?ContainerInterface $container = null): ServiceProviderAggregate
{
Expand Down

0 comments on commit ea3ef1b

Please sign in to comment.