Skip to content

Commit

Permalink
Require symfony/dependency-injection v6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Sep 10, 2023
1 parent 90c40a7 commit 0af2f98
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.0"
php-version: "8.1"
ini-values: memory_limit=-1
tools: composer:v2
- name: Cache dependencies
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
steps:
Expand Down Expand Up @@ -40,7 +39,7 @@ jobs:
run: make test-coveralls

- name: Upload code coverage
if: ${{ matrix.php-version == '8.0' }}
if: ${{ matrix.php-version == '8.1' }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
27 changes: 26 additions & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# Migration

## v3.x to v4.x
## v4.x to v5.0

### New requirements

- Requires PHP v8.1+
- Requires `symfony/dependency-injection` v6.3+

### New features

N/A

### Backward Incompatible Changes

N/A

### Deprecated Features

N/A

### Other Changes

N/A



## v3.x to v4.0

### New requirements

Expand Down
7 changes: 1 addition & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ test-cleanup:
@rm -rf tests/sandbox/*

.PHONY: test-container
test-container: test-container-80

.PHONY: test-container-80
test-container-80:
@-docker-compose run --rm app80 bash
@docker-compose down -v
test-container: test-container-81

.PHONY: test-container-81
test-container-81:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"prefer-stable": true,
"prefer-dist": true,
"require": {
"php": ">=8.0.2",
"php": ">=8.1",
"ext-json": "*",
"symfony/dependency-injection": ">=6.0 <6.3"
"symfony/dependency-injection": "^6.3"
},
"require-dev": {
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": "^9.5",
"symfony/config": "^6.0"
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.3",
"symfony/config": "^6.3"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 0 additions & 10 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
---
version: "3.2"
services:
app80:
build:
context: .
args:
PHP_VERSION: "8.0"
environment:
PHP_IDE_CONFIG: "serverName=symfony-di-proxy"
volumes:
- .:/app:delegated
- ~/.composer:/root/.composer:delegated
app81:
build:
context: .
Expand Down
11 changes: 4 additions & 7 deletions lib/FactoryRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class FactoryRenderer
{
public function __construct(
private MethodRenderer $methodRenderer
private readonly MethodRenderer $methodRenderer
) {
}

Expand All @@ -36,16 +36,13 @@ public function __invoke(string $interface, string $factoryCode): string

return <<<PHPTPL
new class(
function () {
return $factoryCode;
}
static fn () => $factoryCode
) implements \\$interface
{
private \$service;
public function __construct(
private \Closure \$factory
) {
public function __construct(private \Closure \$factory)
{
}
$methods
Expand Down
11 changes: 3 additions & 8 deletions lib/ProxyDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@

final class ProxyDumper implements DumperInterface
{
private InterfaceResolver $interfaceResolver;
private FactoryRenderer $factoryRenderer;

public function __construct(
InterfaceResolver $interfaceResolver = null,
FactoryRenderer $factoryRenderer = null
private readonly InterfaceResolver $interfaceResolver = new BasicInterfaceResolver(),
private readonly FactoryRenderer $factoryRenderer = new FactoryRenderer(new MethodRenderer()),
) {
$this->interfaceResolver = $interfaceResolver ?? new BasicInterfaceResolver();
$this->factoryRenderer = $factoryRenderer ?? new FactoryRenderer(new MethodRenderer());
}

/**
Expand All @@ -60,7 +55,7 @@ public function getProxyFactoryCode(Definition $definition, string $id, string $

if ($definition->isShared()) {
$store = sprintf(
'$this->%s[\'%s\'] = ',
'$container->%s[\'%s\'] = ',
$definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates',
$id
);
Expand Down
20 changes: 10 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<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"
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
>
<coverage>
<include>
<directory suffix=".php">./lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="olvlvl/symfony-dependency-injection-proxy">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./lib</directory>
</include>
</source>
</phpunit>
13 changes: 3 additions & 10 deletions tests/FactoryRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use olvlvl\SymfonyDependencyInjectionProxy\MethodRenderer;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use ReflectionException;
use ReflectionMethod;
use Serializable;

Expand All @@ -24,9 +23,6 @@
*/
final class FactoryRendererTest extends TestCase
{
/**
* @throws ReflectionException
*/
public function testRender(): void
{
$interface = Serializable::class;
Expand All @@ -44,16 +40,13 @@ public function testRender(): void
$stu = new FactoryRenderer($methodRenderer);
$expected = <<<PHPTPL
new class(
function () {
return $factoryCode;
}
static fn () => $factoryCode
) implements \\$interface
{
private \$service;
public function __construct(
private \Closure \$factory
) {
public function __construct(private \Closure \$factory)
{
}
codeFor:serialize
Expand Down
59 changes: 30 additions & 29 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace tests\olvlvl\SymfonyDependencyInjectionProxy;

use Closure;
use olvlvl\SymfonyDependencyInjectionProxy\ProxyDumper;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -60,11 +61,11 @@ public function testCompilation(array $definitions, callable $assert, callable $

require $containerFile;

$assert(new $containerClass());
$assert($this, new $containerClass());
}

// @phpstan-ignore-next-line
public function provideDefinition(): array
public static function provideDefinition(): array
{
$alias = 'alias-' . uniqid();

Expand All @@ -78,15 +79,15 @@ public function provideDefinition(): array
->setPublic(true)
->addArgument($value = uniqid()),
],
function (ContainerInterface $container) use ($id, $value) {
function (self $test, ContainerInterface $container) use ($id, $value) {
/** @var SampleInterface $service */
$service = $container->get($id);
$this->assertSame($service, $container->get($id));
$test->assertSame($service, $container->get($id));

$this->assertInstanceOf(SampleInterface::class, $service);
$this->assertNotInstanceOf(Sample::class, $service);
$test->assertInstanceOf(SampleInterface::class, $service);
$test->assertNotInstanceOf(Sample::class, $service);

$this->assertSame($value, $service->getValue());
$test->assertSame($value, $service->getValue());
},
],

Expand All @@ -100,15 +101,15 @@ function (ContainerInterface $container) use ($id, $value) {
->addArgument($value2 = uniqid())
->addTag('proxy', ['interface' => SampleInterface2::class]),
],
function (ContainerInterface $container) use ($id, $value2) {
function (self $test, ContainerInterface $container) use ($id, $value2) {
/** @var SampleInterface2 $service */
$service = $container->get($id);
$this->assertSame($service, $container->get($id));
$test->assertSame($service, $container->get($id));

$this->assertInstanceOf(SampleInterface2::class, $service);
$this->assertNotInstanceOf(Sample2::class, $service);
$test->assertInstanceOf(SampleInterface2::class, $service);
$test->assertNotInstanceOf(Sample2::class, $service);

$this->assertSame($value2, $service->getValue2());
$test->assertSame($value2, $service->getValue2());
},
],

Expand All @@ -124,15 +125,15 @@ function (ContainerInterface $container) use ($id, $value2) {
->setClass(BuildableFactory::class)
->addArgument($factoryName = 'factory-' . uniqid()),
],
function (ContainerInterface $container) use ($id, $factoryName) {
function (self $test, ContainerInterface $container) use ($id, $factoryName) {
/** @var BuildableInterface $service */
$service = $container->get($id);
$this->assertSame($service, $container->get($id));
$test->assertSame($service, $container->get($id));

$this->assertInstanceOf(BuildableInterface::class, $service);
$this->assertNotInstanceOf(Buildable::class, $service);
$test->assertInstanceOf(BuildableInterface::class, $service);
$test->assertNotInstanceOf(Buildable::class, $service);

$this->assertSame($factoryName, $service->getFactory());
$test->assertSame($factoryName, $service->getFactory());
},
],

Expand All @@ -144,17 +145,17 @@ function (ContainerInterface $container) use ($id, $factoryName) {
->setPublic(true)
->addArgument($value = uniqid()),
],
function (ContainerInterface $container) use ($id, $alias, $value) {
function (self $test, ContainerInterface $container) use ($id, $alias, $value) {
/** @var SampleInterface $service */
$service = $container->get($alias);
$this->assertSame($service, $container->get($alias));
$this->assertSame($service, $container->get($id));
$test->assertSame($service, $container->get($alias));
$test->assertSame($service, $container->get($id));

$this->assertInstanceOf(SampleInterface::class, $service);
$this->assertNotInstanceOf(Sample::class, $service);
$test->assertInstanceOf(SampleInterface::class, $service);
$test->assertNotInstanceOf(Sample::class, $service);

$this->assertSame($value, $service->getValue());
$this->assertSame($service, $container->get($id));
$test->assertSame($value, $service->getValue());
$test->assertSame($service, $container->get($id));
},
function (ContainerBuilder $builder) use ($id, $alias) {
$builder->addAliases([ $alias => new Alias($id, true) ]);
Expand All @@ -169,15 +170,15 @@ function (ContainerBuilder $builder) use ($id, $alias) {
->setPublic(false)
->addArgument($value = uniqid()),
],
function (ContainerInterface $container) use ($alias, $value) {
function (self $test, ContainerInterface $container) use ($alias, $value) {
/** @var SampleInterface $service */
$service = $container->get($alias);
$this->assertSame($service, $container->get($alias));
$test->assertSame($service, $container->get($alias));

$this->assertInstanceOf(SampleInterface::class, $service);
$this->assertNotInstanceOf(Sample::class, $service);
$test->assertInstanceOf(SampleInterface::class, $service);
$test->assertNotInstanceOf(Sample::class, $service);

$this->assertSame($value, $service->getValue());
$test->assertSame($value, $service->getValue());
},
function (ContainerBuilder $builder) use ($id, $alias) {
$builder->addAliases([ $alias => new Alias($id, true) ]);
Expand Down
2 changes: 1 addition & 1 deletion tests/InterfaceResolver/BasicInterfaceResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function testResolveInterface(string $class, string $expected): void
}

// @phpstan-ignore-next-line
public function provideResolveInterface(): array
public static function provideResolveInterface(): array
{
return [

Expand Down
2 changes: 1 addition & 1 deletion tests/MethodRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testRender(ReflectionMethod $method, string $getterCode, string
}

// @phpstan-ignore-next-line
public function provideRender(): array
public static function provideRender(): array
{
$getterCode = "get()";
$reflectionFor70 = fn(string $method) => new ReflectionMethod(
Expand Down
Loading

0 comments on commit 0af2f98

Please sign in to comment.