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();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
&& $issue_name !== 'CodeError'
|
|
|
|
&& $issue_name !== 'CodeIssue'
|
|
|
|
&& $issue_name !== 'FixableCodeIssue';
|
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
|
|
|
|
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>
|
|
|
|
</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')
|
|
|
|
)
|
|
|
|
);
|
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) {
|
|
|
|
return '<' . $issue_name . ' errorLevel="suppress" />' . PHP_EOL;
|
|
|
|
},
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Psalm\Exception\ConfigException
|
|
|
|
* @expectedExceptionMessage Cannot resolve stubfile path
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-01 01:22:05 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNonexistentStubFile()
|
|
|
|
{
|
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>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="stubs/invalidfile.php" />
|
|
|
|
</stubs>
|
|
|
|
</psalm>'
|
|
|
|
)
|
2017-02-01 01:22:05 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testStubFile()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-02-01 01:22:05 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-02-01 01:22:05 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="tests/stubs/systemclass.php" />
|
|
|
|
</stubs>
|
|
|
|
</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
|
|
|
|
$a = new SystemClass();
|
|
|
|
echo SystemClass::HELLO;
|
2017-02-01 01:22:05 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$b = $a->foo(5, "hello");
|
|
|
|
$c = SystemClass::bar(5, "hello");'
|
|
|
|
);
|
2017-03-19 20:37:07 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-03-19 20:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNamespacedStubClass()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-03-19 20:37:07 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-03-19 20:37:07 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="tests/stubs/namespaced_class.php" />
|
|
|
|
</stubs>
|
|
|
|
</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
|
|
|
|
$a = new Foo\SystemClass();
|
|
|
|
echo Foo\SystemClass::HELLO;
|
2017-03-19 20:37:07 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$b = $a->foo(5, "hello");
|
|
|
|
$c = Foo\SystemClass::bar(5, "hello");'
|
|
|
|
);
|
2017-03-19 20:37:07 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-03-19 20:37:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testStubFunction()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-03-19 20:37:07 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-03-19 20:37:07 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="tests/stubs/custom_functions.php" />
|
|
|
|
</stubs>
|
|
|
|
</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
|
|
|
|
echo barBar("hello");'
|
|
|
|
);
|
2017-03-19 20:37:07 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-03-19 20:37:07 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 18:44:46 +01:00
|
|
|
/**
|
|
|
|
* @expectedException \Psalm\Exception\CodeException
|
|
|
|
* @expectedExceptionMessage UndefinedFunction - /src/somefile.php:2 - Function barBar does not exist
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNoStubFunction()
|
|
|
|
{
|
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
|
|
|
TestConfig::loadFromXML(
|
|
|
|
dirname(__DIR__),
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
</psalm>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$file_path = getcwd() . '/src/somefile.php';
|
|
|
|
|
|
|
|
$this->addFile(
|
|
|
|
$file_path,
|
|
|
|
'<?php
|
|
|
|
echo barBar("hello");'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->analyzeFile($file_path, new Context());
|
|
|
|
}
|
|
|
|
|
2017-03-19 20:37:07 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNamespacedStubFunction()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-03-19 20:37:07 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-03-19 20:37:07 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="tests/stubs/namespaced_functions.php" />
|
|
|
|
</stubs>
|
|
|
|
</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
|
|
|
|
echo Foo\barBar("hello");'
|
|
|
|
);
|
2017-03-19 20:41:24 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-03-19 20:41:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConditionalNamespacedStubFunction()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-03-19 20:41:24 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-03-19 20:41:24 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="tests/stubs/conditional_namespaced_functions.php" />
|
|
|
|
</stubs>
|
|
|
|
</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
|
|
|
|
echo Foo\barBar("hello");'
|
|
|
|
);
|
2017-02-01 01:22:05 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-02-01 01:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testStubFileWithExistingClassDefinition()
|
|
|
|
{
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->project_checker = $this->getProjectCheckerWithConfig(
|
2017-02-01 01:22:05 +01:00
|
|
|
TestConfig::loadFromXML(
|
2017-05-04 20:25:58 +02:00
|
|
|
dirname(__DIR__),
|
2017-02-01 01:22:05 +01:00
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<psalm>
|
|
|
|
<projectFiles>
|
|
|
|
<directory name="src" />
|
|
|
|
</projectFiles>
|
|
|
|
|
|
|
|
<stubs>
|
|
|
|
<file name="tests/stubs/logicexception.php" />
|
|
|
|
</stubs>
|
|
|
|
</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
|
|
|
|
$a = new LogicException(5);'
|
|
|
|
);
|
2017-02-01 01:22:05 +01:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2016-12-30 04:31:52 +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
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTemplatedFiles()
|
|
|
|
{
|
|
|
|
foreach (['1.xml', '2.xml', '3.xml', '4.xml', '5.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
|
|
|
}
|