Skip to content

Commit

Permalink
improve tests for intersection types
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondřej Ešler committed Oct 25, 2022
1 parent d063d15 commit 016de5c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/Fix/ClassWithIntersectionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace IW\Fix;

class ClassWithIntersectionType
{
public function __construct(private Alias&Zero $dependency)
{
}
}
33 changes: 32 additions & 1 deletion tests/ServiceContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,17 @@ public function testOptionalParams(): void
}

/** @requires PHP >= 8.0 */
public function testUnionTypes(): void
public function testUnionTypesWiring(): void
{
$container = new ServiceContainer();

$container->wire('IW\Fix\ClassWithUnionType', 'IW\Fix\First');

$this->assertInstanceOf('IW\Fix\ClassWithUnionType', $container->get('IW\Fix\ClassWithUnionType'));
}

/** @requires PHP >= 8.0 */
public function testUnionTypesCannotBeAutowired(): void
{
$container = new ServiceContainer();

Expand All @@ -317,6 +327,27 @@ public function testUnionTypes(): void
$container->get('IW\Fix\ClassWithUnionType');
}

/** @requires PHP >= 8.1 */
public function testIntersectionTypesWiring(): void
{
$container = new ServiceContainer();

$container->wire('IW\Fix\ClassWithIntersectionType', 'IW\Fix\Zero');

$this->assertInstanceOf('IW\Fix\ClassWithIntersectionType', $container->get('IW\Fix\ClassWithIntersectionType'));
}

/** @requires PHP >= 8.1 */
public function testIntersectionTypesCannotBeAutowired(): void
{
$container = new ServiceContainer();

$this->expectException('IW\ServiceContainer\UnsupportedAutowireParam');
$this->expectExceptionMessage('Unsupported type hint for param: Parameter #0 [ <required> IW\Fix\Alias&IW\Fix\Zero $dependency ]');

$container->get('IW\Fix\ClassWithIntersectionType');
}

public function testNullableParam(): void
{
$container = new ServiceContainer();
Expand Down

0 comments on commit 016de5c

Please sign in to comment.