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 diff --git a/library/Mockery/Reflector.php b/library/Mockery/Reflector.php index 9672924cf..4e8c6e1fc 100644 --- a/library/Mockery/Reflector.php +++ b/library/Mockery/Reflector.php @@ -147,8 +147,8 @@ 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) { + // PHP 8 union types and PHP 8.1 intersection types can be recursively processed + 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..26af5885f 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,17 @@ public function getTimestamp(): float { } } + +class IntersectionTypeHelperClass +{ +} +interface IntersectionTypeHelperInterface +{ +} + +class ArgumentIntersectionTypeHint +{ + public function foo(IntersectionTypeHelperClass&IntersectionTypeHelperInterface $foo) + { + } +}