1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Add new tests for functionality

This commit is contained in:
Matthew Brown 2016-06-29 18:15:51 -04:00
parent e0c16308a8
commit 382fcb3a07
2 changed files with 115 additions and 0 deletions

View File

@ -287,4 +287,26 @@ class ReturnTypeTest extends PHPUnit_Framework_TestCase
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
public function testSwitchReturnTypeWitDefaultException()
{
$stmts = self::$_parser->parse('<?php
class A {
/** @return bool */
public function foo() {
switch (rand(0,10)) {
case 1:
case 2:
return true;
default:
throw new \Exception("badness");
}
}
}
');
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
}

View File

@ -651,6 +651,99 @@ class TypeTest extends PHPUnit_Framework_TestCase
$file_checker->check();
}
/**
* @expectedException CodeInspector\Exception\CodeException
*/
public function testNullableMethodWithGuardedSwitchRedefinitionNoDefault()
{
$stmts = self::$_parser->parse('<?php
class One {
public function foo() {}
}
class B {
public function bar(One $one = null) {
$a = 4;
if ($one === null) {
switch ($a) {
case 4:
$one = new One();
break;
}
}
$one->foo();
}
}');
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
/**
* @expectedException CodeInspector\Exception\CodeException
*/
public function testNullableMethodWithGuardedSwitchRedefinitionEmptyDefault()
{
$stmts = self::$_parser->parse('<?php
class One {
public function foo() {}
}
class B {
public function bar(One $one = null) {
$a = 4;
if ($one === null) {
switch ($a) {
case 4:
$one = new One();
break;
default:
break;
}
}
$one->foo();
}
}');
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
public function testNullableMethodWithGuardedSwitchRedefinitionDueToException()
{
$stmts = self::$_parser->parse('<?php
class One {
public function foo() {}
}
class B {
public function bar(One $one = null) {
$a = 4;
if ($one === null) {
switch ($a) {
case 4:
$one = new One();
break;
default:
throw new \Exception("bad");
}
}
$one->foo();
}
}');
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
public function testNullableMethodWithGuardedNestedRedefinitionWithReturn()
{
$stmts = self::$_parser->parse('<?php