2016-12-29 16:24:10 +01:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests;
|
|
|
|
|
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Config;
|
2018-01-21 16:22:04 +01:00
|
|
|
use Psalm\Context;
|
2016-12-29 16:24:10 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
class ConfigTest extends TestCase
|
2016-12-29 16:24:10 +01:00
|
|
|
{
|
2017-02-01 01:22:05 +01:00
|
|
|
/** @var TestConfig */
|
|
|
|
protected static $config;
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
/** @var \Psalm\Checker\ProjectChecker */
|
|
|
|
protected $project_checker;
|
|
|
|
|
2017-02-01 01:22:05 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
self::$config = new TestConfig();
|
2018-04-27 21:00:22 +02:00
|
|
|
|
|
|
|
if (!defined('PSALM_VERSION')) {
|
|
|
|
define('PSALM_VERSION', '2.0.0');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defined('PHP_PARSER_VERSION')) {
|
|
|
|
define('PHP_PARSER_VERSION', '4.0.0');
|
|
|
|
}
|
2017-02-01 01:22:05 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-29 16:24:10 +01:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
FileChecker::clearCache();
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->file_provider = new Provider\FakeFileProvider();
|
2016-12-29 16:24:10 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
* @psalm-return array<mixed, string>
|
|
|
|
*/
|
2016-12-30 04:31:52 +01:00
|
|
|
public static function getAllIssues()
|
|
|
|
{
|
|
|
|
return array_filter(
|
|
|
|
array_map(
|
2017-01-13 20:14:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $file_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-01-13 20:14:24 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 04:31:52 +01:00
|
|
|
function ($file_name) {
|
|
|
|
return substr($file_name, 0, -4);
|
|
|
|
},
|
|
|
|
scandir(dirname(__DIR__) . '/src/Psalm/Issue')
|
|
|
|
),
|
2017-01-13 20:14:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $issue_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-01-13 20:14:24 +01:00
|
|
|
* @return bool
|
|
|
|
*/
|
2016-12-30 04:31:52 +01:00
|
|
|
function ($issue_name) {
|
2018-01-06 01:49:27 +01:00
|
|
|
return !empty($issue_name)
|
2018-03-21 03:36:03 +01:00
|
|
|
&& $issue_name !== 'MethodIssue'
|
2018-05-11 06:07:41 +02:00
|
|
|
&& $issue_name !== 'PropertyIssue'
|
2018-03-21 03:36:03 +01:00
|
|
|
&& $issue_name !== 'ClassIssue'
|
|
|
|
&& $issue_name !== 'CodeIssue';
|
2016-12-30 04:31:52 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
/**
|
|
|
|
* @param Config $config
|
|
|
|
*
|
|
|
|
* @return \Psalm\Checker\ProjectChecker
|
|
|
|
*/
|
|
|
|
private function getProjectCheckerWithConfig(Config $config)
|
|
|
|
{
|
|
|
|
return new \Psalm\Checker\ProjectChecker(
|
|
|
|
$config,
|
|
|
|
$this->file_provider,
|
2018-02-19 06:27:39 +01:00
|
|
|
new Provider\FakeParserCacheProvider(),
|
|
|
|
new \Psalm\Provider\NoCache\NoFileStorageCacheProvider(),
|
|
|
|
new \Psalm\Provider\NoCache\NoClassLikeStorageCacheProvider()
|
2018-01-21 16:22:04 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-29 16:24:10 +01:00
|
|
|
public function testBarebonesConfig()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
(string)getcwd(),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
2016-12-29 16:24:10 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$config = $this->project_checker->getConfig();
|
|
|
|
|
2017-01-16 17:41:57 +01:00
|
|
|
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php')));
|
2016-12-29 16:24:10 +01:00
|
|
|
}
|
2016-12-30 00:33:03 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-30 00:33:03 +01:00
|
|
|
public function testIgnoreProjectDirectory()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
<ignoreFiles>
|
|
|
|
<directory name="src/Psalm/Checker" />
|
|
|
|
</ignoreFiles>
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
2016-12-30 00:33:03 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$config = $this->project_checker->getConfig();
|
|
|
|
|
2017-01-16 17:41:57 +01:00
|
|
|
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('src/Psalm/Checker/FileChecker.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php')));
|
2016-12-30 00:33:03 +01:00
|
|
|
}
|
2016-12-30 02:07:42 +01:00
|
|
|
|
2018-06-06 02:15:18 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIgnoreWildcardProjectDirectory()
|
|
|
|
{
|
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
<ignoreFiles>
|
|
|
|
<directory name="src/**/Checker" />
|
|
|
|
</ignoreFiles>
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$config = $this->project_checker->getConfig();
|
|
|
|
|
|
|
|
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('src/Psalm/Checker/FileChecker.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('src/Psalm/Checker/Statements/ReturnChecker.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php')));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIgnoreWildcardFiles()
|
|
|
|
{
|
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
<ignoreFiles>
|
|
|
|
<file name="src/Psalm/Checker/*Checker.php" />
|
|
|
|
</ignoreFiles>
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$config = $this->project_checker->getConfig();
|
|
|
|
|
|
|
|
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Type.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('src/Psalm/Checker/FileChecker.php')));
|
|
|
|
$this->assertTrue($config->isInProjectDirs(realpath('src/Psalm/Checker/Statements/ReturnChecker.php')));
|
|
|
|
$this->assertFalse($config->isInProjectDirs(realpath('examples/StringChecker.php')));
|
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-30 02:07:42 +01:00
|
|
|
public function testIssueHandler()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
<directory name="tests" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<issueHandlers>
|
|
|
|
<MissingReturnType errorLevel="suppress" />
|
|
|
|
</issueHandlers>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
2016-12-30 02:07:42 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$config = $this->project_checker->getConfig();
|
|
|
|
|
2017-03-24 23:34:46 +01:00
|
|
|
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('tests/ConfigTest.php')));
|
|
|
|
$this->assertFalse($config->reportIssueInFile('MissingReturnType', realpath('src/Psalm/Type.php')));
|
2016-12-30 02:07:42 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-30 02:07:42 +01:00
|
|
|
public function testIssueHandlerWithCustomErrorLevels()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
<directory name="tests" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<issueHandlers>
|
|
|
|
<MissingReturnType errorLevel="info">
|
|
|
|
<errorLevel type="suppress">
|
|
|
|
<directory name="tests" />
|
|
|
|
</errorLevel>
|
|
|
|
<errorLevel type="error">
|
|
|
|
<directory name="src/Psalm/Checker" />
|
|
|
|
</errorLevel>
|
|
|
|
</MissingReturnType>
|
2018-03-21 03:36:03 +01:00
|
|
|
<UndefinedClass>
|
|
|
|
<errorLevel type="suppress">
|
|
|
|
<referencedClass name="Psalm\Badger" />
|
|
|
|
</errorLevel>
|
|
|
|
</UndefinedClass>
|
|
|
|
<UndefinedMethod>
|
|
|
|
<errorLevel type="suppress">
|
|
|
|
<referencedMethod name="Psalm\Bodger::find1" />
|
|
|
|
</errorLevel>
|
|
|
|
</UndefinedMethod>
|
2018-05-11 06:07:41 +02:00
|
|
|
<UndefinedPropertyFetch>
|
|
|
|
<errorLevel type="suppress">
|
|
|
|
<referencedProperty name="Psalm\Bodger::$find3" />
|
|
|
|
</errorLevel>
|
|
|
|
</UndefinedPropertyFetch>
|
2018-01-21 16:22:04 +01:00
|
|
|
</issueHandlers>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
2016-12-30 02:07:42 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$config = $this->project_checker->getConfig();
|
|
|
|
|
2017-04-25 05:45:02 +02:00
|
|
|
$this->assertSame(
|
|
|
|
'info',
|
|
|
|
$config->getReportingLevelForFile(
|
|
|
|
'MissingReturnType',
|
|
|
|
realpath('src/Psalm/Type.php')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'error',
|
|
|
|
$config->getReportingLevelForFile(
|
|
|
|
'MissingReturnType',
|
|
|
|
realpath('src/Psalm/Checker/FileChecker.php')
|
|
|
|
)
|
|
|
|
);
|
2018-03-21 03:36:03 +01:00
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'suppress',
|
|
|
|
$config->getReportingLevelForClass(
|
|
|
|
'UndefinedClass',
|
|
|
|
'Psalm\Badger'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'error',
|
|
|
|
$config->getReportingLevelForClass(
|
|
|
|
'UndefinedClass',
|
|
|
|
'Psalm\Bodger'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'suppress',
|
|
|
|
$config->getReportingLevelForMethod(
|
|
|
|
'UndefinedMethod',
|
|
|
|
'Psalm\Bodger::find1'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'error',
|
2018-05-11 06:07:41 +02:00
|
|
|
$config->getReportingLevelForProperty(
|
|
|
|
'UndefinedMethod',
|
|
|
|
'Psalm\Bodger::$find3'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
'error',
|
|
|
|
$config->getReportingLevelForProperty(
|
2018-03-21 03:36:03 +01:00
|
|
|
'UndefinedMethod',
|
2018-05-11 06:07:41 +02:00
|
|
|
'Psalm\Bodger::$find4'
|
2018-03-21 03:36:03 +01:00
|
|
|
)
|
|
|
|
);
|
2016-12-30 02:07:42 +01:00
|
|
|
}
|
2016-12-30 04:31:52 +01:00
|
|
|
|
2017-01-13 20:07:23 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-30 04:31:52 +01:00
|
|
|
public function testAllPossibleIssues()
|
|
|
|
{
|
|
|
|
$all_possible_handlers = implode(
|
|
|
|
' ',
|
|
|
|
array_map(
|
2017-01-13 20:14:24 +01:00
|
|
|
/**
|
|
|
|
* @param string $issue_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-01-13 20:14:24 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-30 04:31:52 +01:00
|
|
|
function ($issue_name) {
|
2018-04-13 01:42:24 +02:00
|
|
|
return '<' . $issue_name . ' errorLevel="suppress" />' . "\n";
|
2016-12-30 04:31:52 +01:00
|
|
|
},
|
|
|
|
self::getAllIssues()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<issueHandlers>
|
|
|
|
' . $all_possible_handlers . '
|
|
|
|
</issueHandlers>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
2016-12-30 04:31:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-13 20:07:23 +01:00
|
|
|
* @expectedException \Psalm\Exception\ConfigException
|
2016-12-30 04:31:52 +01:00
|
|
|
* @expectedExceptionMessage This element is not expected
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-01-13 20:07:23 +01:00
|
|
|
* @return void
|
2016-12-30 04:31:52 +01:00
|
|
|
*/
|
|
|
|
public function testImpossibleIssue()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
Config::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<issueHandlers>
|
|
|
|
<ImpossibleIssue errorLevel="suppress" />
|
|
|
|
</issueHandlers>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-01 16:13:37 +01:00
|
|
|
/**
|
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
|
|
|
* @expectedExceptionMessage MissingReturnType
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-01 16:13:37 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRequireVoidReturnTypeExists()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-02-01 16:13:37 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-02-01 16:13:37 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm
|
|
|
|
requireVoidReturnType="true">
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$file_path = getcwd() . '/src/somefile.php';
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->addFile(
|
2018-01-21 16:22:04 +01:00
|
|
|
$file_path,
|
2017-07-25 22:11:02 +02:00
|
|
|
'<?php
|
|
|
|
function foo() {}'
|
|
|
|
);
|
2017-02-01 16:13:37 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-02-01 16:13:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDoNotRequireVoidReturnTypeExists()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-02-01 16:13:37 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-02-01 16:13:37 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm
|
|
|
|
requireVoidReturnType="false">
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$file_path = getcwd() . '/src/somefile.php';
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->addFile(
|
2018-01-21 16:22:04 +01:00
|
|
|
$file_path,
|
2017-07-25 22:11:02 +02:00
|
|
|
'<?php
|
|
|
|
function foo() {}'
|
|
|
|
);
|
2017-02-01 16:13:37 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-02-01 16:13:37 +01:00
|
|
|
}
|
2017-02-13 05:59:33 +01:00
|
|
|
|
2018-04-28 19:05:43 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMethodCallMemoize()
|
|
|
|
{
|
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
TestConfig::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm memoizeMethodCallResults="true">
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$file_path = getcwd() . '/src/somefile.php';
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
$file_path,
|
|
|
|
'<?php
|
|
|
|
class A {
|
|
|
|
function getFoo() : ?Foo {
|
|
|
|
return rand(0, 1) ? new Foo : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
class Foo {
|
|
|
|
public function bar() : void {}
|
|
|
|
};
|
|
|
|
|
|
|
|
$a = new A();
|
|
|
|
|
|
|
|
if ($a->getFoo()) {
|
|
|
|
$a->getFoo()->bar();
|
|
|
|
}'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile($file_path, new Context());
|
|
|
|
}
|
|
|
|
|
2017-02-13 05:59:33 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTemplatedFiles()
|
|
|
|
{
|
2018-04-19 07:03:28 +02:00
|
|
|
foreach (['1.xml', '2.xml', '3.xml', '4.xml', '5.xml', '6.xml', '7.xml', '8.xml'] as $file_name) {
|
2017-05-04 20:25:58 +02:00
|
|
|
Config::loadFromXMLFile(
|
|
|
|
realpath(dirname(__DIR__) . '/assets/config_levels/' . $file_name),
|
|
|
|
dirname(__DIR__)
|
|
|
|
);
|
2017-02-13 05:59:33 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-29 16:24:10 +01:00
|
|
|
}
|