-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
DisallowedSuperglobalFactoryTest.php
55 lines (46 loc) · 1.37 KB
/
DisallowedSuperglobalFactoryTest.php
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
51
52
53
54
55
<?php
declare(strict_types = 1);
namespace Spaze\PHPStan\Rules\Disallowed;
use Generator;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\PHPStanTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class DisallowedSuperglobalFactoryTest extends PHPStanTestCase
{
/**
* @dataProvider superglobalsProvider
* @param string $superglobal
* @param class-string|null $exceptionClass
* @throws ShouldNotHappenException
*/
#[DataProvider('superglobalsProvider')]
public function testNonSuperglobalInConfig(string $superglobal, ?string $exceptionClass)
{
if ($exceptionClass) {
$this->expectException($exceptionClass);
$this->expectExceptionMessage("{$superglobal} is not a superglobal variable");
} else {
$this->expectNotToPerformAssertions();
}
self::getContainer()->getByType(DisallowedSuperglobalFactory::class)->getDisallowedVariables([['superglobal' => $superglobal]]);
}
public static function superglobalsProvider(): Generator
{
yield ['$GLOBALS', null];
yield ['$_SERVER', null];
yield ['$_GET', null];
yield ['$_POST', null];
yield ['$_FILES', null];
yield ['$_COOKIE', null];
yield ['$_SESSION', null];
yield ['$_REQUEST', null];
yield ['$_ENV', null];
yield ['$foo', ShouldNotHappenException::class];
}
public static function getAdditionalConfigFiles(): array
{
return [
__DIR__ . '/../extension.neon',
];
}
}