mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
use Psalm\Type;
|
|
|
|
use PhpParser;
|
|
use PhpParser\ParserFactory;
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
class PropertyTypeTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
protected static $_parser;
|
|
protected static $_file_filter;
|
|
|
|
public static function setUpBeforeClass()
|
|
{
|
|
self::$_parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
|
|
|
$config = \Psalm\Config::getInstance();
|
|
$config->throw_exception = true;
|
|
|
|
self::$_file_filter = $filter;
|
|
}
|
|
|
|
public function setUp()
|
|
{
|
|
\Psalm\ClassMethodChecker::clearCache();
|
|
}
|
|
|
|
public function testNewVarInIf()
|
|
{
|
|
$stmts = self::$_parser->parse('<?php
|
|
class A {
|
|
/**
|
|
* @var mixed
|
|
*/
|
|
public $foo;
|
|
|
|
public function bar()
|
|
{
|
|
if (rand(0,10) === 5) {
|
|
$this->foo = [];
|
|
}
|
|
|
|
if (!is_array($this->foo)) {
|
|
// do something
|
|
}
|
|
}
|
|
}
|
|
');
|
|
|
|
$file_checker = new \Psalm\FileChecker('somefile.php', $stmts);
|
|
$file_checker->check();
|
|
}
|
|
}
|