2016-11-21 14:36:06 -05:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use PhpParser\ParserFactory;
|
|
|
|
use PHPUnit_Framework_TestCase;
|
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Config;
|
|
|
|
use Psalm\Context;
|
|
|
|
|
|
|
|
class Php40Test extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
2016-12-14 12:55:23 -05:00
|
|
|
/** @var \PhpParser\Parser */
|
2016-11-21 14:36:06 -05:00
|
|
|
protected static $parser;
|
|
|
|
|
2017-01-31 19:22:05 -05:00
|
|
|
/** @var TestConfig */
|
|
|
|
protected static $config;
|
|
|
|
|
2017-01-02 15:31:18 -05:00
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
|
|
protected $project_checker;
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-21 14:36:06 -05:00
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
2017-01-31 19:22:05 -05:00
|
|
|
self::$config = new TestConfig();
|
2016-11-21 14:36:06 -05:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-21 14:36:06 -05:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
FileChecker::clearCache();
|
2017-01-02 15:31:18 -05:00
|
|
|
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
2017-01-31 19:22:05 -05:00
|
|
|
$this->project_checker->setConfig(self::$config);
|
2016-11-21 14:36:06 -05:00
|
|
|
}
|
|
|
|
|
2017-01-13 14:07:23 -05:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-11-21 14:36:06 -05:00
|
|
|
public function testExtendOldStyleConstructor()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
class A {
|
2016-12-07 14:13:39 -05:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-21 14:36:06 -05:00
|
|
|
public function A() {
|
2016-12-07 14:13:39 -05:00
|
|
|
return "hello";
|
2016-11-21 14:36:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class B extends A {
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
2017-01-02 15:31:18 -05:00
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
2017-01-16 18:33:04 -05:00
|
|
|
$context = new Context();
|
2017-01-07 15:09:47 -05:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
2016-11-21 14:36:06 -05:00
|
|
|
}
|
2017-04-10 11:03:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSameNameMethodWithNewStyleConstructor()
|
|
|
|
{
|
|
|
|
$stmts = self::$parser->parse('<?php
|
|
|
|
class A {
|
|
|
|
public function __construct(string $s) { }
|
|
|
|
/** @return void */
|
|
|
|
public function a(int $i) { }
|
|
|
|
}
|
|
|
|
new A("hello");
|
|
|
|
');
|
|
|
|
|
|
|
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
|
|
|
$context = new Context();
|
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
|
|
|
|
2016-11-21 14:36:06 -05:00
|
|
|
}
|