mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add a bunch of elseif tests to fix
This commit is contained in:
parent
c33e66813a
commit
469cee1b80
@ -312,4 +312,102 @@ class TypeAlgebraTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTwoVarLogicNotNestedWithElseif()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function foo(?string $a, ?string $b) : string {
|
||||
if ($a) {
|
||||
// do nothing
|
||||
} elseif ($b) {
|
||||
// do nothing here
|
||||
} else {
|
||||
return "bad";
|
||||
}
|
||||
|
||||
if (!$a) return $b;
|
||||
return $a;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidReturnType
|
||||
* @return void
|
||||
*/
|
||||
public function testTwoVarLogicNotNestedWithElseifNegatedInIf()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function foo(?string $a, ?string $b) : string {
|
||||
if ($a) {
|
||||
$a = null;
|
||||
} elseif ($b) {
|
||||
// do nothing here
|
||||
} else {
|
||||
return "bad";
|
||||
}
|
||||
|
||||
if (!$a) return $b;
|
||||
return $a;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTwoVarLogicNotNestedWithElseifCorrectlyNegatedInElseIf()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function foo(?string $a, ?string $b) : string {
|
||||
if ($a) {
|
||||
// do nothing here
|
||||
} elseif ($b) {
|
||||
$a = null;
|
||||
} else {
|
||||
return "bad";
|
||||
}
|
||||
|
||||
if (!$a) return $b;
|
||||
return $a;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testTwoVarLogicNotNestedWithElseifCorrectlyReinforcedInIf()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
function foo(?string $a, ?string $b) : string {
|
||||
if ($a) {
|
||||
$a = "hello";
|
||||
} elseif ($b) {
|
||||
// do nothing
|
||||
} else {
|
||||
return "bad";
|
||||
}
|
||||
|
||||
if (!$a) return $b;
|
||||
return $a;
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$file_checker->visitAndAnalyzeMethods();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user