Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 19, 2021
1 parent 19e3cde commit e494c81
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,19 @@ public function testBug1903(): void
]);
}

public function testBug3117(): void
{
$this->analyse([__DIR__ . '/data/bug-3117.php'], [
[
'Method Bug3117\SimpleTemporal::adjustInto() should return T of Bug3117\Temporal but returns $this(Bug3117\SimpleTemporal).',
35,
],
]);
}

public function testBug3034(): void
{
$this->analyse([__DIR__ . '/data/bug-3034.php'], []);
}

}
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3034.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Bug3034;

/**
* @implements \IteratorAggregate<int, array{name: string, value: string}>
*/
class HelloWorld implements \IteratorAggregate
{
/**
* @var array<int, array{name: string, value: string}>
*/
private $list;

/**
* @return \ArrayIterator<int, array{name: string, value: string}>
*/
public function getIterator()
{
return new \ArrayIterator($this->list);
}
}
49 changes: 49 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3117.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Bug3117;

interface Temporal
{

/**
* @return static
*/
public function adjustedWith(TemporalAdjuster $adjuster): Temporal;

}

interface TemporalAdjuster
{

/**
* @template T of Temporal
*
* @param T $temporal
*
* @return T
*/
public function adjustInto(Temporal $temporal) : Temporal;

}

final class SimpleTemporal implements Temporal, TemporalAdjuster
{

public function adjustInto(Temporal $temporal): Temporal
{
if ($temporal instanceof self) {
return $this;
}

return $temporal->adjustedWith($this);
}

/**
* @return static
*/
public function adjustedWith(TemporalAdjuster $adjuster): Temporal
{
return $this;
}

}

0 comments on commit e494c81

Please sign in to comment.