Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7021 from pawel-slowik/unresolvable-include-tests
Add tests for UnresolvableInclude
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
namespace Psalm\Tests; | ||
|
||
use Psalm\Context; | ||
use Psalm\Exception\CodeException; | ||
|
||
class UnresolvableIncludeTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider providerUnresolvableInclude | ||
*/ | ||
public function testShouldThrowUnresolvableInclude(string $phpCode, int $expectedExceptionLine): void | ||
{ | ||
$this->addFile('somefile.php', $phpCode); | ||
$context = new Context(); | ||
|
||
$this->expectException(CodeException::class); | ||
$this->expectExceptionMessage("UnresolvableInclude - somefile.php:$expectedExceptionLine:"); | ||
|
||
$this->analyzeFile('somefile.php', $context); | ||
} | ||
|
||
/** | ||
* @return array<string,array{0:string,expectedExceptionLine:int}> | ||
*/ | ||
public function providerUnresolvableInclude(): array | ||
{ | ||
return [ | ||
'basic' => [ | ||
'<?php | ||
function requireFile(string $s) : void { | ||
require_once($s); | ||
} | ||
', | ||
'expectedExceptionLine' => 3, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider providerNoUnresolvableInclude | ||
*/ | ||
public function testShouldNotThrowUnresolvableInclude(string $phpCode): void | ||
{ | ||
$this->addFile('somefile.php', $phpCode); | ||
|
||
$context = new Context(); | ||
|
||
$this->analyzeFile('somefile.php', $context); | ||
} | ||
|
||
/** | ||
* @return array<string,array{0:string}> | ||
*/ | ||
public function providerNoUnresolvableInclude(): array | ||
{ | ||
return [ | ||
'github_issue_908_file_exists' => [ | ||
'<?php | ||
function requireFile(string $s) : void { | ||
if (file_exists($s)) { | ||
require_once($s); | ||
} | ||
} | ||
' | ||
], | ||
'github_issue_4788_is_file' => [ | ||
'<?php | ||
function requireFile(string $s) : void { | ||
if (is_file($s)) { | ||
require_once($s); | ||
} | ||
} | ||
' | ||
], | ||
]; | ||
} | ||
} |