1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 02:27:59 +01:00
psalm/tests/Traits/FileCheckerInvalidCodeParseTestTrait.php
Matthew Brown f16642dad2
Better switch analysis (#343)
* Experiment with good switch analysis

* Improve switch accuracy at expense of some processor cycles

* Evaluate switch case expression in case context
2017-11-28 00:25:21 -05:00

54 lines
1.4 KiB
PHP

<?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
* @small
*
* @param string $code
* @param string $error_message
* @param array<string> $error_levels
* @param bool $strict_mode
*
* @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');
$this->expectExceptionMessageRegexp('/\b' . preg_quote($error_message, '/') . '/');
$this->addFile(
self::$src_dir_path . 'somefile.php',
$code
);
$context = new Context();
$file_checker = new FileChecker(self::$src_dir_path . 'somefile.php', $this->project_checker);
$file_checker->visitAndAnalyzeMethods($context);
}
}