Skip to content

Commit 575b950

Browse files
committed
Add test for AccessDeprecatedConstant
1 parent fa953a7 commit 575b950

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tests/fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ function phpstan_fixtures_thing_with_anonymous_class(): void {
4242
}
4343
};
4444
}
45+
46+
function phpstan_fixtures_using_deprecated_constants(): void {
47+
print SCHEMA_UNINSTALLED;
48+
print FILE_INSECURE_EXTENSION_REGEX;
49+
print PREG_CLASS_PUNCTUATION;
50+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace mglaman\PHPStanDrupal\Tests\Rules;
4+
5+
use mglaman\PHPStanDrupal\Rules\Deprecations\AccessDeprecatedConstant;
6+
use mglaman\PHPStanDrupal\Tests\DrupalRuleTestCase;
7+
8+
/**
9+
* @extends \mglaman\PHPStanDrupal\Tests\DrupalRuleTestCase<\mglaman\PHPStanDrupal\Rules\Deprecations\AccessDeprecatedConstant>
10+
*/
11+
final class AccessDeprecatedConstantTest extends DrupalRuleTestCase
12+
{
13+
14+
protected function getRule(): \PHPStan\Rules\Rule
15+
{
16+
return new AccessDeprecatedConstant($this->createReflectionProvider());
17+
}
18+
19+
public function testRule(): void
20+
{
21+
[$version] = explode('.', \Drupal::VERSION, 2);
22+
if ($version !== '9') {
23+
self::markTestSkipped('Only tested on Drupal 9.x.x');
24+
}
25+
26+
$this->analyse(
27+
[__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module'],
28+
[
29+
[
30+
'Call to deprecated constant SCHEMA_UNINSTALLED: Deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use \Drupal\Core\Update\UpdateHookRegistry::SCHEMA_UNINSTALLED',
31+
47
32+
],
33+
[
34+
'Call to deprecated constant FILE_INSECURE_EXTENSION_REGEX: Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use \Drupal\Core\File\FileSystemInterface::INSECURE_EXTENSION_REGEX.',
35+
48
36+
],
37+
[
38+
'Call to deprecated constant PREG_CLASS_PUNCTUATION: Deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use \Drupal\search\SearchTextProcessorInterface::PREG_CLASS_PUNCTUATION',
39+
49
40+
],
41+
],
42+
);
43+
}
44+
}

0 commit comments

Comments
 (0)