1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Add initial rudimentary tests

This commit is contained in:
Matthew Brown 2016-04-03 19:47:06 -04:00
parent f4dd4cb782
commit b60213395b
2 changed files with 61 additions and 1 deletions

View File

@ -15,7 +15,12 @@
},
"autoload": {
"psr-4": {
"CodeInspector\\": "lib"
"CodeInspector\\": "src/CodeInspector",
}
},
"autoload-dev": {
"psr-4": {
"CodeInspector\\Tests": "tests"
}
}
}

55
tests/TypeTest.php Normal file
View File

@ -0,0 +1,55 @@
<?php
namespace CodeInspector\Tests;
use PhpParser;
use PhpParser\ParserFactory;
use PHPUnit_Framework_TestCase;
class TypeTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException CodeInspector\CodeException
*/
public function testNullableMethodCall()
{
$code = '<?php
class A {
public function foo() {}
}
class B {
public function bar(A $a = null) {
$a->foo();
}
}';
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$stmts = $parser->parse($code);
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
public function testNullableMethodWithGuard()
{
$code = '<?php
class A {
public function foo() {}
}
class B {
public function bar(A $a = null) {
if ($a) {
$a->foo();
}
}
}';
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
$stmts = $parser->parse($code);
$file_checker = new \CodeInspector\FileChecker('somefile.php', $stmts);
$file_checker->check();
}
}