Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 18, 2021
1 parent 9b1c0c8 commit 63bc2b2
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,10 @@ public function testBug4530(): void
$this->analyse([__DIR__ . '/data/bug-4530.php'], []);
}

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

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

namespace Bug2268;

abstract class Message implements \ArrayAccess
{
/**
* @param string $value
*/
abstract public function offsetSet($key, $value);
}


function test(Message $data)
{
if (isset($data['name'])) {
$data['name'] = 1;
}

test($data);
}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1786,4 +1786,12 @@ public function testBug2837(): void
$this->analyse([__DIR__ . '/data/bug-2837.php'], []);
}

public function testBug2298(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-2298.php'], []);
}

}
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,14 @@ public function testBug3997(): void
]);
}

public function testBug1903(): void
{
$this->analyse([__DIR__ . '/data/bug-1903.php'], [
/*[
'Method Bug1903\Test::doFoo() should return array but returns int.',
19,
],*/
]);
}

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

namespace Bug1903;

class Test
{

private $answersOrder = [];

public function doFoo(string $qId): array
{
if (null !== $this->answersOrder[$qId]) {
return $this->answersOrder[$qId];
}


$this->answersOrder[$qId] = 5;

return $this->answersOrder[$qId];
}

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

namespace Bug2298;

abstract class BitbucketDriver
{

/**
* @var VcsDriver
*/
protected $fallbackDriver;

protected $rootIdentifier;

}

class HgBitbucketDriver extends BitbucketDriver
{

public function getRootIdentifier(): string
{
if ($this->fallbackDriver) {
return $this->fallbackDriver->getRootIdentifier();
}

if (null === $this->rootIdentifier) {
return $this->fallbackDriver->getRootIdentifier();
}

return 'foo';
}

}

interface VcsDriver
{

public function getRootIdentifier(): string;

}

0 comments on commit 63bc2b2

Please sign in to comment.