From 228c9b6d2da7ef018ba23f64b7fa52b1fd766b35 Mon Sep 17 00:00:00 2001 From: Valentin V / vvval Date: Wed, 16 Dec 2020 11:47:40 +0300 Subject: [PATCH 01/12] add php8.0 to composer requirements --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 137aa6f..7ff6db3 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": "MIT", "description": "Proxy Factory Interface implementation for cycle ORM", "require": { - "php": "^7.2", + "php": "^7.2 || ^8.0", "ext-mbstring": "*", "nikic/php-parser": "^4.2", "doctrine/instantiator": "^1.2", From f41e66d1f78385a0ad5d5d5bd83219a4925940c1 Mon Sep 17 00:00:00 2001 From: Valentin V / vvval Date: Wed, 16 Dec 2020 11:47:53 +0300 Subject: [PATCH 02/12] add php8.0 to gh actions --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a19559..032d47b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-versions: ['7.2', '7.3', '7.4'] + php-versions: ['7.2', '7.3', '7.4', '8.0'] steps: - name: Checkout uses: actions/checkout@v2 From e40859ad2c72e4a6fcee971164ab7aec04f6b56c Mon Sep 17 00:00:00 2001 From: Valentin V / vvval Date: Wed, 16 Dec 2020 11:48:09 +0300 Subject: [PATCH 03/12] fix possible filemtime issue --- src/Promise/Materizalizer/ModificationInspector.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Promise/Materizalizer/ModificationInspector.php b/src/Promise/Materizalizer/ModificationInspector.php index 9db8069..e0055de 100644 --- a/src/Promise/Materizalizer/ModificationInspector.php +++ b/src/Promise/Materizalizer/ModificationInspector.php @@ -54,11 +54,11 @@ public function getLastModifiedDate(ReflectionClass $reflection): DateTime */ private function getLatestParentsModifiedDate(ReflectionClass $reflection): DateTime { - $modifiedDate = new DateTime('@' . filemtime($reflection->getFileName())); + $modifiedDate = new DateTime('@' . $this->getDatetime($reflection)); $parent = $reflection->getParentClass(); while ($parent !== false) { - $parentsModifiedDate = new DateTime('@' . filemtime($parent->getFileName())); + $parentsModifiedDate = new DateTime('@' . $this->getDatetime($reflection)); if ($parentsModifiedDate > $modifiedDate) { $modifiedDate = $parentsModifiedDate; @@ -69,4 +69,9 @@ private function getLatestParentsModifiedDate(ReflectionClass $reflection): Date return $modifiedDate; } + + private function getDatetime(ReflectionClass $reflection) + { + return $reflection->getFileName() ? filemtime($reflection->getFileName()) : time(); + } } From 699a12b150e24b9492393e4686240eecf07cfc09 Mon Sep 17 00:00:00 2001 From: Valentin V / vvval Date: Wed, 16 Dec 2020 11:49:15 +0300 Subject: [PATCH 04/12] fix "optional prior to required params" issue in tests --- tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php | 2 +- tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php b/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php index 039c594..0f564a9 100644 --- a/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php +++ b/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php @@ -19,7 +19,7 @@ public function typedSetter(string $a, $b, int $c): void } - public function defaultsSetter(string $a, $b = [], int $c = 3, bool $d): void + public function defaultsSetter(string $a, $b = [], int $c = 3, ?bool $d = null): void { } diff --git a/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php b/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php index c2e7ce3..9d8ace2 100644 --- a/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php +++ b/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php @@ -35,7 +35,7 @@ public function testArgDefaults(): void $output = $this->makeOutput(Fixtures\ArgsFixture::class, self::NS . __CLASS__ . __LINE__); //Long syntax by default - $this->assertStringContainsString('defaultsSetter(string $a, $b = array(), int $c = 3, bool $d)', $output); + $this->assertStringContainsString('defaultsSetter(string $a, $b = array(), int $c = 3, ?bool $d = null)', $output); } /** From 5dfabb93ae138c95176d56cfde77a0d2eea83d79 Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 13:27:20 +0300 Subject: [PATCH 05/12] fix code style --- tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php b/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php index 9d8ace2..5a97dc6 100644 --- a/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php +++ b/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php @@ -35,7 +35,10 @@ public function testArgDefaults(): void $output = $this->makeOutput(Fixtures\ArgsFixture::class, self::NS . __CLASS__ . __LINE__); //Long syntax by default - $this->assertStringContainsString('defaultsSetter(string $a, $b = array(), int $c = 3, ?bool $d = null)', $output); + $this->assertStringContainsString( + 'defaultsSetter(string $a, $b = array(), int $c = 3, ?bool $d = null)', + $output + ); } /** From bfa4c40b96162ba9b0994ab8e5d6fead5df116d4 Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 13:37:56 +0300 Subject: [PATCH 06/12] add php8.0 test cases support --- composer.json | 1 + phpunit.xml | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7ff6db3..30cadd8 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "psr-4": { "Cycle\\ORM\\Promise\\Tests\\": "tests/Promise/", "Cycle\\ORM\\Promise\\Tests74\\": "tests/php74/", + "Cycle\\ORM\\Promise\\Tests80\\": "tests/php80/", "Cycle\\ORM\\Promise\\Tests\\Promises\\": "tests/fixtures/promises/", "": "tests/fixtures/withoutNamespace/" } diff --git a/phpunit.xml b/phpunit.xml index 62b6386..8334103 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,9 +16,12 @@ ./tests/Promise/ - + ./tests/php74/ + + ./tests/php80/ + From 57392dbccbbbdcf074e1b660e86c4a5acb1c936a Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 13:38:52 +0300 Subject: [PATCH 07/12] fix nullable mixed arg type #17 --- src/Promise/Declaration/Extractor/Methods.php | 2 +- tests/php80/Fixtures/EntityWithMixedArg.php | 19 ++++++ tests/php80/MethodsPHP80Test.php | 60 +++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tests/php80/Fixtures/EntityWithMixedArg.php create mode 100644 tests/php80/MethodsPHP80Test.php diff --git a/src/Promise/Declaration/Extractor/Methods.php b/src/Promise/Declaration/Extractor/Methods.php index f809921..5e515f5 100644 --- a/src/Promise/Declaration/Extractor/Methods.php +++ b/src/Promise/Declaration/Extractor/Methods.php @@ -219,7 +219,7 @@ private function defineType(ReflectionMethod $method, ?ReflectionType $type): ?s $name = '\\' . $name; } - if ($type->allowsNull()) { + if ($name !== 'mixed' && $type->allowsNull()) { $name = "?$name"; } diff --git a/tests/php80/Fixtures/EntityWithMixedArg.php b/tests/php80/Fixtures/EntityWithMixedArg.php new file mode 100644 index 0000000..36550d6 --- /dev/null +++ b/tests/php80/Fixtures/EntityWithMixedArg.php @@ -0,0 +1,19 @@ +makeOutput(EntityWithMixedArg::class, self::NS . __CLASS__ . __LINE__); + + //Long syntax by default + $this->assertStringContainsString( + 'public function method(mixed $arg)', + $output + ); + } + + /** + * @param string $classname + * @param string $as + * @return string + * @throws ReflectionException + * @throws ProxyFactoryException + * @throws Throwable + */ + private function makeOutput(string $classname, string $as): string + { + $reflection = new ReflectionClass($classname); + + $parent = Declarations::createParentFromReflection($reflection); + $class = Declarations::createClassFromName($as, $parent); + + $output = $this->make($reflection, $class, $parent); + $output = ltrim($output, 'assertFalse(class_exists($class->getFullName())); + + eval($output); + + return $output; + } +} From 4459dab4aa65d46373c3d5ac23456592ce3ec81f Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 13:57:45 +0300 Subject: [PATCH 08/12] fix union types in methods declaration #17 --- src/Promise/Declaration/Extractor/Methods.php | 30 +++++++++++++++++++ tests/php80/Fixtures/EntityWithMixedArg.php | 3 +- tests/php80/MethodsPHP80Test.php | 24 +++++++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/Promise/Declaration/Extractor/Methods.php b/src/Promise/Declaration/Extractor/Methods.php index 5e515f5..2630f06 100644 --- a/src/Promise/Declaration/Extractor/Methods.php +++ b/src/Promise/Declaration/Extractor/Methods.php @@ -20,6 +20,7 @@ use ReflectionClass; use ReflectionException; use ReflectionMethod; +use ReflectionNamedType; use ReflectionParameter; use ReflectionType; @@ -207,6 +208,35 @@ private function defineParamType(ReflectionParameter $parameter, ReflectionMetho * @return string|null */ private function defineType(ReflectionMethod $method, ?ReflectionType $type): ?string + { + if ($type instanceof ReflectionNamedType) { + return $this->defineSingularType($method, $type); + } + + if ($type instanceof \ReflectionUnionType) { + $types = array_filter( + array_map( + function (ReflectionNamedType $type) use ($method): ?string { + return $this->defineSingularType($method, $type); + }, + $type->getTypes() + ) + ); + + if ($types) { + return implode('|', array_filter($types)); + } + } + + return null; + } + + /** + * @param ReflectionMethod $method + * @param ReflectionNamedType|null $type + * @return string|null + */ + private function defineSingularType(ReflectionMethod $method, ?ReflectionNamedType $type): ?string { if ($type === null) { return null; diff --git a/tests/php80/Fixtures/EntityWithMixedArg.php b/tests/php80/Fixtures/EntityWithMixedArg.php index 36550d6..7332982 100644 --- a/tests/php80/Fixtures/EntityWithMixedArg.php +++ b/tests/php80/Fixtures/EntityWithMixedArg.php @@ -13,7 +13,8 @@ class EntityWithMixedArg { - public function method(mixed $arg): void + public function method(mixed $arg): mixed { + return $arg; } } diff --git a/tests/php80/MethodsPHP80Test.php b/tests/php80/MethodsPHP80Test.php index d85c08f..ed52f87 100644 --- a/tests/php80/MethodsPHP80Test.php +++ b/tests/php80/MethodsPHP80Test.php @@ -2,20 +2,32 @@ declare(strict_types=1); - namespace Cycle\ORM\Promise\Tests80; use Cycle\ORM\Promise\Declaration\Declarations; use Cycle\ORM\Promise\Exception\ProxyFactoryException; use Cycle\ORM\Promise\Tests\ProxyPrinter\BaseProxyPrinterTest; -use Cycle\ORM\Promise\Tests80\Fixtures\EntityWithMixedArg; -use PHPUnit\Framework\TestCase; +use Cycle\ORM\Promise\Tests80\Fixtures; use ReflectionClass; use ReflectionException; use Throwable; class MethodsPHP80Test extends BaseProxyPrinterTest { + /** + * @throws ProxyFactoryException + * @throws ReflectionException + * @throws Throwable + */ + public function testUnionTypes(): void + { + $output = $this->makeOutput(Fixtures\EntityWithUnionTypes::class, self::NS . __CLASS__ . __LINE__); + + $this->assertStringContainsString( + 'public function method(\Exception|\Error $arg): \Exception|\Error', + $output + ); + } /** * @throws ReflectionException @@ -24,11 +36,10 @@ class MethodsPHP80Test extends BaseProxyPrinterTest */ public function testNullableMixedArg(): void { - $output = $this->makeOutput(EntityWithMixedArg::class, self::NS . __CLASS__ . __LINE__); + $output = $this->makeOutput(Fixtures\EntityWithMixedArg::class, self::NS . __CLASS__ . __LINE__); - //Long syntax by default $this->assertStringContainsString( - 'public function method(mixed $arg)', + 'public function method(mixed $arg): mixed', $output ); } @@ -50,6 +61,7 @@ private function makeOutput(string $classname, string $as): string $output = $this->make($reflection, $class, $parent); $output = ltrim($output, 'assertFalse(class_exists($class->getFullName())); From 948d85c84aab1daaa5b9ad70a53eda3d1780e052 Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 14:02:13 +0300 Subject: [PATCH 09/12] fix union types in methods declaration #17 --- tests/php80/ConstantsPHP80Test.php | 92 +++++++++++++++++++ tests/php80/Fixtures/EntityWithUnionTypes.php | 22 +++++ 2 files changed, 114 insertions(+) create mode 100644 tests/php80/ConstantsPHP80Test.php create mode 100644 tests/php80/Fixtures/EntityWithUnionTypes.php diff --git a/tests/php80/ConstantsPHP80Test.php b/tests/php80/ConstantsPHP80Test.php new file mode 100644 index 0000000..97dab98 --- /dev/null +++ b/tests/php80/ConstantsPHP80Test.php @@ -0,0 +1,92 @@ +container = new Container(); + } + + /** + * @throws ProxyFactoryException + * @throws ReflectionException + * @throws Throwable + */ + public function testConstValues(): void + { + $classname = Fixtures\EntityWithUnionTypes::class; + $as = self::NS . __CLASS__ . __LINE__; + $reflection = new ReflectionClass($classname); + + $parent = Declarations::createParentFromReflection($reflection); + $class = Declarations::createClassFromName($as, $parent); + + $output = $this->make($reflection, $class, $parent); + $output = ltrim($output, 'assertStringContainsString( + "PUBLIC_PROPERTIES = ['throwable'];", + $output + ); + } + + /** + * @param ReflectionClass $reflection + * @param DeclarationInterface $class + * @param DeclarationInterface $parent + * @return string + * @throws ProxyFactoryException + * @throws ReflectionException + * @throws Throwable + */ + protected function make( + ReflectionClass $reflection, + DeclarationInterface $class, + DeclarationInterface $parent + ): string { + return $this->proxyCreator()->make($reflection, $class, $parent); + } + + /** + * @return Printer + * @throws Throwable + */ + private function proxyCreator(): Printer + { + $this->container->bind(PrettyPrinterAbstract::class, Standard::class); + + return $this->container->get(Printer::class); + } +} diff --git a/tests/php80/Fixtures/EntityWithUnionTypes.php b/tests/php80/Fixtures/EntityWithUnionTypes.php new file mode 100644 index 0000000..022a165 --- /dev/null +++ b/tests/php80/Fixtures/EntityWithUnionTypes.php @@ -0,0 +1,22 @@ + Date: Wed, 20 Jan 2021 14:06:14 +0300 Subject: [PATCH 10/12] simplify methods extractor --- src/Promise/Declaration/Extractor/Methods.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Promise/Declaration/Extractor/Methods.php b/src/Promise/Declaration/Extractor/Methods.php index 2630f06..904940a 100644 --- a/src/Promise/Declaration/Extractor/Methods.php +++ b/src/Promise/Declaration/Extractor/Methods.php @@ -214,13 +214,11 @@ private function defineType(ReflectionMethod $method, ?ReflectionType $type): ?s } if ($type instanceof \ReflectionUnionType) { - $types = array_filter( - array_map( - function (ReflectionNamedType $type) use ($method): ?string { - return $this->defineSingularType($method, $type); - }, - $type->getTypes() - ) + $types = array_map( + function (ReflectionNamedType $type) use ($method): ?string { + return $this->defineSingularType($method, $type); + }, + $type->getTypes() ); if ($types) { From 828cbd958cce961a3e3e167114e83e3ce71f0db8 Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 14:10:41 +0300 Subject: [PATCH 11/12] simplify methods extractor --- src/Promise/Declaration/Extractor/Methods.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Promise/Declaration/Extractor/Methods.php b/src/Promise/Declaration/Extractor/Methods.php index 904940a..b3d9423 100644 --- a/src/Promise/Declaration/Extractor/Methods.php +++ b/src/Promise/Declaration/Extractor/Methods.php @@ -231,15 +231,11 @@ function (ReflectionNamedType $type) use ($method): ?string { /** * @param ReflectionMethod $method - * @param ReflectionNamedType|null $type + * @param ReflectionNamedType $type * @return string|null */ - private function defineSingularType(ReflectionMethod $method, ?ReflectionNamedType $type): ?string + private function defineSingularType(ReflectionMethod $method, ReflectionNamedType $type): ?string { - if ($type === null) { - return null; - } - $name = $type->getName(); $name = $this->replacedSelfTypeName($method, $name); From 4802659f7bcaf58bd44ae1fd2aff2a1c384732c0 Mon Sep 17 00:00:00 2001 From: vvval Date: Wed, 20 Jan 2021 14:11:13 +0300 Subject: [PATCH 12/12] polish cs --- src/Promise/Declaration/Extractor/Methods.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Promise/Declaration/Extractor/Methods.php b/src/Promise/Declaration/Extractor/Methods.php index b3d9423..bd457e4 100644 --- a/src/Promise/Declaration/Extractor/Methods.php +++ b/src/Promise/Declaration/Extractor/Methods.php @@ -230,7 +230,7 @@ function (ReflectionNamedType $type) use ($method): ?string { } /** - * @param ReflectionMethod $method + * @param ReflectionMethod $method * @param ReflectionNamedType $type * @return string|null */