diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index a53f31d..3b5da94 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b26697..fa2121a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,6 @@ jobs: strategy: matrix: php-version: - - "8.0" - "8.1" - "8.2" steps: @@ -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: | diff --git a/MIGRATION.md b/MIGRATION.md index 5ac811d..828dbe5 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -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 diff --git a/Makefile b/Makefile index 1bcf894..861862f 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index 71c87f4..1ce1c1e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ implementation][2]. Here are some differences: - Can proxy `final` classes. - Can only proxy classes with interfaces. - The generated proxies are self-contained. -- The package is ~10Kb and doesn't have dependencies, other than `symfony/dependency-injection` of course. +- The package is ~10Kb and doesn't have dependencies. - The package can be removed once the proxies have been generated. If you're not familiar with proxy services, better have a look at [Symfony's documentation][3] diff --git a/composer.json b/composer.json index a6794c2..611b550 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/docker-compose.yaml b/docker-compose.yaml index e862c31..0ab45d8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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: . diff --git a/lib/FactoryRenderer.php b/lib/FactoryRenderer.php index f2b3983..ea5a6c0 100644 --- a/lib/FactoryRenderer.php +++ b/lib/FactoryRenderer.php @@ -21,7 +21,7 @@ class FactoryRenderer { public function __construct( - private MethodRenderer $methodRenderer + private readonly MethodRenderer $methodRenderer ) { } @@ -36,16 +36,13 @@ public function __invoke(string $interface, string $factoryCode): string return << $factoryCode ) implements \\$interface { private \$service; - public function __construct( - private \Closure \$factory - ) { + public function __construct(private \Closure \$factory) + { } $methods diff --git a/lib/ProxyDumper.php b/lib/ProxyDumper.php index 4fd3642..6d7bf20 100644 --- a/lib/ProxyDumper.php +++ b/lib/ProxyDumper.php @@ -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()); } /** @@ -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 ); diff --git a/phpunit.xml b/phpunit.xml index cf79b90..f83be0c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,17 +1,17 @@ - + - - - ./lib - - ./tests + + + ./lib + + diff --git a/tests/FactoryRendererTest.php b/tests/FactoryRendererTest.php index 8e414cb..55371aa 100644 --- a/tests/FactoryRendererTest.php +++ b/tests/FactoryRendererTest.php @@ -15,7 +15,6 @@ use olvlvl\SymfonyDependencyInjectionProxy\MethodRenderer; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; -use ReflectionException; use ReflectionMethod; use Serializable; @@ -24,9 +23,6 @@ */ final class FactoryRendererTest extends TestCase { - /** - * @throws ReflectionException - */ public function testRender(): void { $interface = Serializable::class; @@ -44,16 +40,13 @@ public function testRender(): void $stu = new FactoryRenderer($methodRenderer); $expected = << $factoryCode ) implements \\$interface { private \$service; - public function __construct( - private \Closure \$factory - ) { + public function __construct(private \Closure \$factory) + { } codeFor:serialize diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index f5f6ae5..0f805df 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -60,11 +60,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(); @@ -78,15 +78,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()); }, ], @@ -100,15 +100,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()); }, ], @@ -124,15 +124,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()); }, ], @@ -144,17 +144,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) ]); @@ -169,15 +169,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) ]); diff --git a/tests/InterfaceResolver/BasicInterfaceResolverTest.php b/tests/InterfaceResolver/BasicInterfaceResolverTest.php index 3dc7d2b..a6ba70e 100644 --- a/tests/InterfaceResolver/BasicInterfaceResolverTest.php +++ b/tests/InterfaceResolver/BasicInterfaceResolverTest.php @@ -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 [ diff --git a/tests/MethodRendererTest.php b/tests/MethodRendererTest.php index 3851ba8..f15c05e 100644 --- a/tests/MethodRendererTest.php +++ b/tests/MethodRendererTest.php @@ -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( diff --git a/tests/ProxyDumperTest.php b/tests/ProxyDumperTest.php index 8378156..4efebd1 100644 --- a/tests/ProxyDumperTest.php +++ b/tests/ProxyDumperTest.php @@ -41,7 +41,7 @@ public function testIsProxyCandidate(Definition $definition, bool $expected): vo } // @phpstan-ignore-next-line - public function provideIsProxyCandidate(): array + public static function provideIsProxyCandidate(): array { $factory = 'aFactory'; $class = ArrayObject::class; @@ -117,14 +117,14 @@ public function testGetProxyFactoryCode(string $id, bool $private, bool $shared, } // @phpstan-ignore-next-line - public function provideGetProxyFactoryCode(): array + public static function provideGetProxyFactoryCode(): array { $id = 'aServiceId'; return [ - [ $id, false, true, "\$this->services['$id'] = " ], - [ $id, true, true, "\$this->privates['$id'] = " ], + [ $id, false, true, "\$container->services['$id'] = " ], + [ $id, true, true, "\$container->privates['$id'] = " ], [ $id, false, false, "" ], [ $id, true, false, "" ], diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..edfae99 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,14 @@ +getPathname()); +} diff --git a/tests/cases/Buildable.php b/tests/cases/Buildable.php index 52cbab8..691f106 100644 --- a/tests/cases/Buildable.php +++ b/tests/cases/Buildable.php @@ -2,7 +2,7 @@ namespace tests\olvlvl\SymfonyDependencyInjectionProxy\cases; -class Buildable +class Buildable implements BuildableInterface { /** * @var string