1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 17:52:45 +01:00
psalm/tests/Traits/FileCheckerInvalidCodeParseTestTrait.php
Bruce Weirdan c1e21fcf5d Update PHPUnit (#888)
* upgrade phpunit, test with low and high deps

* work around possibly-anonymous test cases introduced by newer PHPUnit

* Alternative TestCase::getName() nullability workaround

Previous workaround was failing due to PHP warnings on 7.1 or 7.2
(depending on specific signature). There's just no signature that would
be working for all 4 variants of (ver / dep) matrix.

* don't disable xdebug if it's not enabled

* allowed 7.0/high to fail until PHPUnit 6.5.10 is released

see sebastianbergmann/phpunit#3209
2018-07-13 17:44:50 -04:00

48 lines
1.3 KiB
PHP

<?php
namespace Psalm\Tests\Traits;
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->getTestName(), '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, '/') . '\b/');
$file_path = self::$src_dir_path . 'somefile.php';
$this->addFile($file_path, $code);
$this->analyzeFile($file_path, new Context());
}
}