Skip to content

Commit

Permalink
Test complex generics example
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 10, 2019
1 parent adb41f9 commit 6c9b52e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9642,6 +9642,11 @@ public function dataPsalmPrefixedTagsWithUnresolvableTypes(): array
return $this->gatherAssertTypes(__DIR__ . '/data/psalm-prefix-unresolvable.php');
}

public function dataComplexGenericsExample(): array
{
return $this->gatherAssertTypes(__DIR__ . '/data/complex-generics-example.php');
}

/**
* @dataProvider dataBug2574
* @dataProvider dataBug2577
Expand All @@ -9658,6 +9663,7 @@ public function dataPsalmPrefixedTagsWithUnresolvableTypes(): array
* @dataProvider dataBug2677
* @dataProvider dataBug2676
* @dataProvider dataPsalmPrefixedTagsWithUnresolvableTypes
* @dataProvider dataComplexGenericsExample
* @param ConstantStringType $expectedType
* @param Type $actualType
*/
Expand Down
52 changes: 52 additions & 0 deletions tests/PHPStan/Analyser/data/complex-generics-example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types = 1);

namespace ComplexGenericsExample;

use function PHPStan\Analyser\assertType;

/**
* @template TVariant of VariantInterface
*/
interface ExperimentInterface
{
}

interface VariantInterface
{
}

interface VariantRetrieverInterface
{
/**
* @template TVariant of VariantInterface
* @param ExperimentInterface<TVariant> $experiment
* @return TVariant
*/
public function getVariant(ExperimentInterface $experiment): VariantInterface;
}

/**
* @implements ExperimentInterface<SomeVariant>
*/
class SomeExperiment implements ExperimentInterface
{
}

class SomeVariant implements VariantInterface
{
}

class SomeClass
{
private $variantRetriever;

public function __construct(VariantRetrieverInterface $variantRetriever)
{
$this->variantRetriever = $variantRetriever;
}

public function someFunction(): void
{
assertType('ComplexGenericsExample\SomeVariant', $this->variantRetriever->getVariant(new SomeExperiment()));
}
}

0 comments on commit 6c9b52e

Please sign in to comment.