Skip to content
Permalink
Browse files

Add tests for things that should work

  • Loading branch information...
muglug committed Jun 26, 2019
1 parent 41837eb commit 3a52ccd5a685e9b10ae58cb16959ef285157e231
Showing with 93 additions and 0 deletions.
  1. +66 −0 tests/TypeReconciliationTest.php
  2. +27 −0 tests/UnusedCodeTest.php
@@ -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']
],
];
}
@@ -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);'
],
];
}

0 comments on commit 3a52ccd

Please sign in to comment.
You can’t perform that action at this time.