From e286ae3c84905861c5916716c11383848d315309 Mon Sep 17 00:00:00 2001 From: Keith Brink Date: Thu, 3 Feb 2022 13:44:10 +0200 Subject: [PATCH 1/5] Support PHP8.1 intersection types --- library/Mockery/Reflector.php | 2 +- tests/PHP81/Php81LanguageFeaturesTest.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/library/Mockery/Reflector.php b/library/Mockery/Reflector.php index 9672924cf..de4d58d0f 100644 --- a/library/Mockery/Reflector.php +++ b/library/Mockery/Reflector.php @@ -148,7 +148,7 @@ private static function typeToString(\ReflectionType $type, \ReflectionClass $de private static function getTypeInformation(\ReflectionType $type, \ReflectionClass $declaringClass) { // PHP 8 union types can be recursively processed - if ($type instanceof \ReflectionUnionType) { + if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { $types = []; foreach ($type->getTypes() as $innterType) { diff --git a/tests/PHP81/Php81LanguageFeaturesTest.php b/tests/PHP81/Php81LanguageFeaturesTest.php index afb761435..30d02e240 100644 --- a/tests/PHP81/Php81LanguageFeaturesTest.php +++ b/tests/PHP81/Php81LanguageFeaturesTest.php @@ -72,6 +72,16 @@ public function testMockingClassWithNewInInitializer() $this->assertInstanceOf(ClassWithNewInInitializer::class, $mock); } + + /** @test */ + public function it_can_mock_a_class_with_an_intersection_argument_type_hint() + { + $mock = Mockery::mock(ArgumentIntersectionTypeHint::class); + $object = new IntersectionTypeHelperClass(); + $mock->allows()->foo($object); + + $mock->foo($object); + } } interface LoggerInterface @@ -124,3 +134,13 @@ public function getTimestamp(): float { } } + +class IntersectionTypeHelperClass {} +interface IntersectionTypeHelperInterface {} + +class ArgumentIntersectionTypeHint +{ + public function foo(IntersectionTypeHelperClass&IntersectionTypeHelperInterface $foo) + { + } +} From e2179448657b81c6fb2938a9605f63e67d17d413 Mon Sep 17 00:00:00 2001 From: Keith Brink Date: Thu, 3 Feb 2022 13:49:03 +0200 Subject: [PATCH 2/5] Update styleci to php8.1 --- .styleci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.styleci.yml b/.styleci.yml index a1a1caa0c..614c1fbf7 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,5 +1,7 @@ preset: psr12 +version: 8.1 + enabled: - symfony_braces From 3f6af6b09c8b82dbc23ce294f539e1f38b42457c Mon Sep 17 00:00:00 2001 From: Keith Brink Date: Thu, 3 Feb 2022 13:51:04 +0200 Subject: [PATCH 3/5] Apply styleci fixes --- tests/PHP81/Php81LanguageFeaturesTest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/PHP81/Php81LanguageFeaturesTest.php b/tests/PHP81/Php81LanguageFeaturesTest.php index 30d02e240..26af5885f 100644 --- a/tests/PHP81/Php81LanguageFeaturesTest.php +++ b/tests/PHP81/Php81LanguageFeaturesTest.php @@ -75,7 +75,7 @@ public function testMockingClassWithNewInInitializer() /** @test */ public function it_can_mock_a_class_with_an_intersection_argument_type_hint() - { + { $mock = Mockery::mock(ArgumentIntersectionTypeHint::class); $object = new IntersectionTypeHelperClass(); $mock->allows()->foo($object); @@ -135,8 +135,12 @@ public function getTimestamp(): float } } -class IntersectionTypeHelperClass {} -interface IntersectionTypeHelperInterface {} +class IntersectionTypeHelperClass +{ +} +interface IntersectionTypeHelperInterface +{ +} class ArgumentIntersectionTypeHint { From 69bcf8f6d9f3c3577e8ca3a33d158e68c4de575d Mon Sep 17 00:00:00 2001 From: Keith Brink Date: Thu, 3 Feb 2022 13:52:15 +0200 Subject: [PATCH 4/5] Update comment --- library/Mockery/Reflector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Mockery/Reflector.php b/library/Mockery/Reflector.php index de4d58d0f..78b88b07e 100644 --- a/library/Mockery/Reflector.php +++ b/library/Mockery/Reflector.php @@ -147,7 +147,7 @@ private static function typeToString(\ReflectionType $type, \ReflectionClass $de */ private static function getTypeInformation(\ReflectionType $type, \ReflectionClass $declaringClass) { - // PHP 8 union types can be recursively processed + // PHP 8 union types and PHP 8.1 intersection type can be recursively processed if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { $types = []; From a43d526c79fa54c34c4a1aa7efe8d691457e70f6 Mon Sep 17 00:00:00 2001 From: Keith Brink Date: Thu, 3 Feb 2022 13:56:15 +0200 Subject: [PATCH 5/5] Spelling --- library/Mockery/Reflector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Mockery/Reflector.php b/library/Mockery/Reflector.php index 78b88b07e..4e8c6e1fc 100644 --- a/library/Mockery/Reflector.php +++ b/library/Mockery/Reflector.php @@ -147,7 +147,7 @@ private static function typeToString(\ReflectionType $type, \ReflectionClass $de */ private static function getTypeInformation(\ReflectionType $type, \ReflectionClass $declaringClass) { - // PHP 8 union types and PHP 8.1 intersection type can be recursively processed + // PHP 8 union types and PHP 8.1 intersection types can be recursively processed if ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) { $types = [];