mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add more tests
This commit is contained in:
parent
6637bb653c
commit
5f4ab230c3
@ -72,6 +72,52 @@ class ReturnTypeTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker->check();
|
||||
}
|
||||
|
||||
public function testReturnTypeNotEmptyCheckInElseIf()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
class B {
|
||||
/**
|
||||
* @param string|null $str
|
||||
* @return string
|
||||
*/
|
||||
public function bar($str) {
|
||||
if ($str === "badger") {
|
||||
// do nothing
|
||||
}
|
||||
elseif (empty($str)) {
|
||||
$str = "";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}');
|
||||
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$file_checker->check();
|
||||
}
|
||||
|
||||
public function testReturnTypeNotEmptyCheckInElse()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
class B {
|
||||
/**
|
||||
* @param string|null $str
|
||||
* @return string
|
||||
*/
|
||||
public function bar($str) {
|
||||
if (!empty($str)) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
$str = "";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}');
|
||||
|
||||
$file_checker = new \Psalm\Checker\FileChecker('somefile.php', $stmts);
|
||||
$file_checker->check();
|
||||
}
|
||||
|
||||
public function testReturnTypeAfterIf()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
|
@ -1099,6 +1099,9 @@ class TypeTest extends PHPUnit_Framework_TestCase
|
||||
$file_checker->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Psalm\Exception\CodeException
|
||||
*/
|
||||
public function testUnnecessaryInstanceof()
|
||||
{
|
||||
$stmts = self::$_parser->parse('<?php
|
||||
@ -1106,15 +1109,6 @@ class TypeTest extends PHPUnit_Framework_TestCase
|
||||
public function foo() {}
|
||||
}
|
||||
|
||||
class Two {
|
||||
public function bar() {}
|
||||
}
|
||||
|
||||
class Three {
|
||||
public function baz() {}
|
||||
}
|
||||
|
||||
|
||||
$var = new One();
|
||||
|
||||
if ($var instanceof One) {
|
||||
|
Loading…
Reference in New Issue
Block a user