Skip to content

Commit

Permalink
Merge pull request #1164 from keithbrink/support-php81-intersection-t…
Browse files Browse the repository at this point in the history
…ypes

Support PHP8.1 intersection types
  • Loading branch information
davedevelopment committed Apr 12, 2022
2 parents 6439fe5 + a43d526 commit 5ea6075
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .styleci.yml
@@ -1,5 +1,7 @@
preset: psr12

version: 8.1

enabled:
- symfony_braces

Expand Down
4 changes: 2 additions & 2 deletions library/Mockery/Reflector.php
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions tests/PHP81/Php81LanguageFeaturesTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -124,3 +134,17 @@ public function getTimestamp(): float
{
}
}

class IntersectionTypeHelperClass
{
}
interface IntersectionTypeHelperInterface
{
}

class ArgumentIntersectionTypeHint
{
public function foo(IntersectionTypeHelperClass&IntersectionTypeHelperInterface $foo)
{
}
}

0 comments on commit 5ea6075

Please sign in to comment.