2017-04-25 05:45:02 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests\Traits;
|
|
|
|
|
|
|
|
use Psalm\Checker\FileChecker;
|
|
|
|
use Psalm\Config;
|
|
|
|
use Psalm\Context;
|
|
|
|
|
|
|
|
trait FileCheckerInvalidCodeParseTestTrait
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
abstract public function providerFileCheckerInvalidCodeParse();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFileCheckerInvalidCodeParse
|
2017-11-28 06:25:21 +01:00
|
|
|
* @small
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-04-25 05:45:02 +02:00
|
|
|
* @param string $code
|
|
|
|
* @param string $error_message
|
|
|
|
* @param array<string> $error_levels
|
2017-05-27 02:16:18 +02:00
|
|
|
* @param bool $strict_mode
|
|
|
|
*
|
2017-04-25 05:45:02 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInvalidCode($code, $error_message, $error_levels = [], $strict_mode = false)
|
|
|
|
{
|
|
|
|
if (strpos($this->getName(), 'SKIPPED-') !== false) {
|
|
|
|
$this->markTestSkipped();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($strict_mode) {
|
|
|
|
Config::getInstance()->strict_binary_operands = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($error_levels as $error_level) {
|
|
|
|
Config::getInstance()->setCustomErrorLevel($error_level, Config::REPORT_SUPPRESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->expectException('\Psalm\Exception\CodeException');
|
2017-11-16 03:04:25 +01:00
|
|
|
$this->expectExceptionMessageRegexp('/\b' . preg_quote($error_message, '/') . '/');
|
2017-04-25 05:45:02 +02:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->addFile(
|
2017-07-25 23:04:58 +02:00
|
|
|
self::$src_dir_path . 'somefile.php',
|
2017-07-25 22:11:02 +02:00
|
|
|
$code
|
|
|
|
);
|
2017-04-25 05:45:02 +02:00
|
|
|
|
|
|
|
$context = new Context();
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2017-07-25 23:04:58 +02:00
|
|
|
$file_checker = new FileChecker(self::$src_dir_path . 'somefile.php', $this->project_checker);
|
2017-04-25 05:45:02 +02:00
|
|
|
$file_checker->visitAndAnalyzeMethods($context);
|
|
|
|
}
|
|
|
|
}
|