Skip to content

Commit

Permalink
Add tests for things that should work
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 26, 2019
1 parent 41837eb commit 3a52ccd
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
66 changes: 66 additions & 0 deletions tests/TypeReconciliationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,72 @@ function reflectCallable(callable $callable): ReflectionFunctionAbstract {
}
}'
],
'noLeakyClassType' => [
'<?php
class A {
public array $foo = [];
public array $bar = [];
public function setter() : void {
if ($this->foo) {
$this->foo = [];
}
}
public function iffer() : bool {
return $this->foo || $this->bar;
}
}'
],
'noLeakyForeachType' => [
'<?php
class A {
/** @var mixed */
public $_array_value;
private function getArrayValue() : ?array {
return rand(0, 1) ? [] : null;
}
public function setValue(string $var) : void {
$this->_array_value = $this->getArrayValue();
if ($this->_array_value !== null && !count($this->_array_value)) {
return;
}
switch ($var) {
case "a":
foreach ($this->_array_value ?: [] as $v) {}
break;
case "b":
foreach ($this->_array_value ?: [] as $v) {}
break;
}
}
}',
[],
['MixedAssignment']
],
'nonEmptyThing' => [
'<?php
/** @param mixed $clips */
function foo($clips, bool $found, int $id) : void {
if ($found === false) {
$clips = [];
}
$i = array_search($id, $clips);
if ($i !== false) {
unset($clips[$i]);
}
}',
[],
['MixedArgument', 'MixedArrayAccess']
],
];
}

Expand Down
27 changes: 27 additions & 0 deletions tests/UnusedCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,33 @@ public function __construct() {}
new A();
}',
],
'usedParamInIf' => [
'<?php
class O {}
class C {
private bool $a = false;
public array $_types = [];
private static function mirror(array $a) : array {
return $a;
}
/**
* @param class-string<O>|null $type
* @return self
*/
public function addType(?string $type, array $ids = array())
{
if ($this->a) {
$ids = self::mirror($ids);
}
$this->_types[$type ?: ""] = new ArrayObject($ids);
return $this;
}
}
(new C)->addType(null);'
],
];
}

Expand Down

0 comments on commit 3a52ccd

Please sign in to comment.