-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathUseSafeFunctionsRuleTest.php
More file actions
50 lines (43 loc) · 1.71 KB
/
UseSafeFunctionsRuleTest.php
File metadata and controls
50 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace TheCodingMachine\Safe\PHPStan\Rules;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
/**
* @template-extends RuleTestCase<UseSafeFunctionsRule>
*/
class UseSafeFunctionsRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new UseSafeFunctionsRule();
}
public function testUnsafe(): void
{
$this->analyse([__DIR__ . '/UseSafeFunctionsRule/unsafe.php'], [
[
"Function fopen is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\fopen;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.",
3,
],
[
"Function json_decode is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\json_decode;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.",
4,
],
[
"Function json_encode is unsafe to use. It can return FALSE instead of throwing an exception. Please add 'use function Safe\\json_encode;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library.",
5,
],
]);
}
public function testUseSafe(): void
{
$this->analyse([__DIR__ . '/UseSafeFunctionsRule/use_safe.php'], []);
}
public function testNativeSafe(): void
{
$this->analyse([__DIR__ . '/UseSafeFunctionsRule/native_safe.php'], []);
}
public function testExpr(): void
{
$this->analyse([__DIR__ . '/UseSafeFunctionsRule/expr.php'], []);
}
}