2017-04-25 05:45:02 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Tests\Traits;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-07-13 23:44:50 +02:00
|
|
|
if (strpos($this->getTestName(), 'SKIPPED-') !== false) {
|
2017-04-25 05:45:02 +02:00
|
|
|
$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');
|
2018-01-11 23:35:28 +01:00
|
|
|
$this->expectExceptionMessageRegexp('/\b' . preg_quote($error_message, '/') . '\b/');
|
2017-04-25 05:45:02 +02:00
|
|
|
|
2018-01-21 16:22:04 +01:00
|
|
|
$file_path = self::$src_dir_path . 'somefile.php';
|
|
|
|
|
2018-01-21 19:38:51 +01:00
|
|
|
$this->addFile($file_path, $code);
|
2018-01-21 16:22:04 +01:00
|
|
|
$this->analyzeFile($file_path, new Context());
|
2017-04-25 05:45:02 +02:00
|
|
|
}
|
|
|
|
}
|