1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/tests/ForbiddenCodeTest.php
2019-03-02 08:43:19 -05:00

56 lines
1.5 KiB
PHP

<?php
namespace Psalm\Tests;
class ForbiddenCodeTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,error_message:string,2?:string[],3?:bool,4?:string}>
*/
public function providerInvalidCodeParse()
{
return [
'varDump' => [
'<?php
var_dump("hello");',
'error_message' => 'ForbiddenCode',
],
'execTicks' => [
'<?php
`rm -rf`;',
'error_message' => 'ForbiddenCode',
],
'exec' => [
'<?php
shell_exec("rm -rf");',
'error_message' => 'ForbiddenCode',
],
];
}
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
*/
public function providerValidCodeParse()
{
return [
'execWithSuppression' => [
'<?php
@exec("pwd 2>&1", $output, $returnValue);
if ($returnValue === 0) {
echo "success";
}',
],
'execWithoutSuppression' => [
'<?php
exec("pwd 2>&1", $output, $returnValue);
if ($returnValue === 0) {
echo "success";
}',
],
];
}
}