2016-07-12 06:53:36 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-26 00:37:44 +02:00
|
|
|
namespace Psalm\Tests;
|
2016-07-12 06:53:36 +02:00
|
|
|
|
2016-07-26 00:37:44 +02:00
|
|
|
use Psalm\Type;
|
2016-07-12 06:53:36 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-07-26 00:37:44 +02:00
|
|
|
$config = \Psalm\Config::getInstance();
|
2016-07-12 06:53:36 +02:00
|
|
|
$config->throw_exception = true;
|
|
|
|
|
|
|
|
self::$_file_filter = $filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2016-07-26 00:37:44 +02:00
|
|
|
\Psalm\ClassMethodChecker::clearCache();
|
2016-07-12 06:53:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
2016-07-26 00:37:44 +02:00
|
|
|
$file_checker = new \Psalm\FileChecker('somefile.php', $stmts);
|
2016-07-12 06:53:36 +02:00
|
|
|
$file_checker->check();
|
|
|
|
}
|
|
|
|
}
|