1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-13 01:37:23 +01:00
psalm/tests/ForbiddenCodeTest.php
AndrolGenhald d4590711d6
Fix object-like array keys when combining string and automatic keys (fixes #5427). (#5428)
* Fix object-like array keys (fixes #5427).

* Fix incorrect return types for tests.

* Fix false positive list with literal int key.
2021-03-19 21:44:44 -04:00

66 lines
1.8 KiB
PHP

<?php
namespace Psalm\Tests;
class ForbiddenCodeTest extends TestCase
{
use Traits\InvalidCodeAnalysisTestTrait;
use Traits\ValidCodeAnalysisTestTrait;
/**
* @return iterable<string,array{string,error_message:string,1?:string[],2?:bool,3?:string}>
*/
public function providerInvalidCodeParse(): iterable
{
return [
'varDump' => [
'<?php
var_dump("hello");',
'error_message' => 'ForbiddenCode',
],
'varDumpCased' => [
'<?php
vAr_dUMp("hello");',
'error_message' => 'ForbiddenCode',
],
'execTicks' => [
'<?php
`rm -rf`;',
'error_message' => 'ForbiddenCode',
],
'exec' => [
'<?php
shell_exec("rm -rf");',
'error_message' => 'ForbiddenCode',
],
'execCased' => [
'<?php
sHeLl_EXeC("rm -rf");',
'error_message' => 'ForbiddenCode',
],
];
}
/**
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
*/
public function providerValidCodeParse(): iterable
{
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";
}',
],
];
}
}