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:
parent
f4dd4cb782
commit
b60213395b
@ -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
55
tests/TypeTest.php
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user