1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Move more tests into appropriate directory

This commit is contained in:
Matthew Brown 2019-12-07 13:38:06 -05:00
parent 2b6831ba10
commit d7fdd9b179
5 changed files with 84 additions and 16 deletions

View File

@ -1910,6 +1910,17 @@ class ConditionalTest extends \Psalm\Tests\TestCase
$c = ($a instanceof B && $b instanceof B) || ($a instanceof C && $b instanceof C);
}'
],
'assertVarAfterNakedBinaryOp' => [
'<?php
class A {
public bool $b = false;
}
function foo(A $a, A $b): void {
$c = !$a->b && !$b->b;
echo $a->b ? 1 : 0;
}'
],
'assertAssertionsWithCreation' => [
'<?php
class A {}
@ -2043,7 +2054,62 @@ class ConditionalTest extends \Psalm\Tests\TestCase
if (isset($a["b"]) || isset($a["c"])) {
$all_params = ($a["b"] ?? []) + ($a["c"] ?? []);
}'
]
],
'assertOnNestedLogic' => [
'<?php
function foo(?string $a) : void {
if (($a && rand(0, 1)) || rand(0, 1)) {
if ($a && strlen($a) > 5) {}
}
}'
],
'arrayUnionTypeSwitching' => [
'<?php
/** @param array<string, int|string> $map */
function foo(array $map, string $o) : void {
if ($mapped_type = $map[$o] ?? null) {
if (is_int($mapped_type)) {
return;
}
}
if (($mapped_type = $map[""] ?? null) && is_string($mapped_type)) {
}
}'
],
'propertySetOnElementInConditional' => [
'<?php
class DiffElem {
/** @var scalar */
public $old = false;
/** @var scalar */
public $new = false;
}
function foo(DiffElem $diff_elem) : void {
if ((is_string($diff_elem->old) && is_string($diff_elem->new))
|| (is_int($diff_elem->old) && is_int($diff_elem->new))
) {
}
}'
],
'manyNestedAsserts' => [
'<?php
class A {}
class B extends A {}
function foo(A $left, A $right) : void {
if (($left instanceof B && rand(0, 1))
|| ($right instanceof B && rand(0, 1))
) {
if ($left instanceof B
&& rand(0, 1)
&& $right instanceof B
&& rand(0, 1)
) {}
}
}'
],
];
}

View File

@ -1,10 +1,10 @@
<?php
namespace Psalm\Tests;
class EmptyTest extends TestCase
class EmptyTest extends \Psalm\Tests\TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
use \Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use \Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>

View File

@ -1,10 +1,10 @@
<?php
namespace Psalm\Tests;
class IssetTest extends TestCase
class IssetTest extends \Psalm\Tests\TestCase
{
use Traits\ValidCodeAnalysisTestTrait;
use Traits\InvalidCodeAnalysisTestTrait;
use \Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
use \Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
@ -413,7 +413,7 @@ class IssetTest extends TestCase
throw new \InvalidArgumentException();
}',
],
'notIssetOneOrOther' => [
'notIssetOneOrOtherSimple' => [
'<?php
$foo = [
"one" => rand(0,1) ? new DateTime : null,
@ -437,7 +437,7 @@ class IssetTest extends TestCase
"three" => new DateTime
];
isset($foo["one"]) || isset($foo["two"]);
$a = isset($foo["one"]) || isset($foo["two"]);
echo $foo["one"]->format("Y");',
'assertions' => [],

View File

@ -1,10 +1,10 @@
<?php
namespace Psalm\Tests;
namespace Psalm\Tests\TypeReconciliation;
class TypeAlgebraTest extends TestCase
class TypeAlgebraTest extends \Psalm\Tests\TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
use \Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use \Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
@ -139,7 +139,9 @@ class TypeAlgebraTest extends TestCase
return new stdClass;
}
if (!$a && !$b) return $c;
if (!$a && !$b) {
return $c;
}
if (!$a) return $b;
return $a;
}',
@ -570,7 +572,7 @@ class TypeAlgebraTest extends TestCase
}
if (rand(0, 10) > 5) {
} elseif (($a = new A) && $a->foo) {}',
} elseif (($a = rand(0, 1) ? new A : null) && $a->foo) {}',
],
'noParadoxForGetopt' => [
'<?php
@ -1082,7 +1084,7 @@ class TypeAlgebraTest extends TestCase
],
'repeatedConditionals' => [
'<?php
function foo(?string $a): void {
function foo(?object $a): void {
if ($a) {
// do something
} elseif ($a) {