Skip to content

Commit 89fcb15

Browse files
committed
Ensure configlevel2 runs, verify service map broken
1 parent 82fde88 commit 89fcb15

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

tests/fixtures/config/phpunit-drupal-phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameters:
44
# Ignore functions for the PHPUnit bootstrap process.
55
ignoreErrors:
66
- '#Function drupal_phpunit_[a-zA-Z0-9\\_]+ not found#'
7+
- '#Unsafe usage of new static().#'
78
drupal:
89
drupal_root: %currentWorkingDirectory%
910
includes:
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<?php
22

3-
function phpstan_fixtures_included() {
3+
// Catches at level 4.
4+
function phpstan_fixtures_IfConstantConditionRule() {
45
$zero = 0;
56
if ($zero) {
67
}
78
}
9+
10+
// Catches at level 0.
11+
function phpstan_fixtures_MissingReturnRule(): string {
12+
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Drupal\phpstan_fixtures;
4+
5+
use Drupal\Core\Entity\EntityManager;
6+
7+
class UsesDeprecatedServiceMethod {
8+
public function test() {
9+
$entity_manager = \Drupal::getContainer()->get('entity.manager');
10+
// Deprecated for EntityTypeManagerInterface::getDefinitions().
11+
$definitions = $entity_manager->getDefinitions();
12+
}
13+
}

tests/src/AnalyzerTestBase.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ protected function runAnalyze(string $path) {
1414
$rootDir = __DIR__ . '/../fixtures/drupal';
1515
$tmpDir = sys_get_temp_dir() . '/' . time() . 'phpstan';
1616
$containerFactory = new ContainerFactory($rootDir);
17-
$container = $containerFactory->create(
18-
$tmpDir,
19-
[__DIR__ . '/../fixtures/config/phpunit-drupal-phpstan.neon'],
20-
[]
21-
);
17+
18+
$additionalConfigFiles = [
19+
\sprintf('%s/config.level%s.neon', $containerFactory->getConfigDirectory(), 2),
20+
__DIR__ . '/../fixtures/config/phpunit-drupal-phpstan.neon',
21+
];
22+
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, []);
2223
$fileHelper = $container->getByType(FileHelper::class);
2324
assert($fileHelper !== null);
2425

tests/src/DeprecationRulesTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ public function dataDeprecatedSamples(): \Generator
3232
];
3333
yield [
3434
__DIR__ . '/../fixtures/drupal/core/lib/Drupal/Core/Entity/EntityManager.php',
35-
1,
35+
2,
3636
[
3737
'Class Drupal\Core\Entity\EntityManager implements deprecated interface Drupal\Core\Entity\EntityManagerInterface:
38-
in drupal:8.0.0 and is removed from drupal:9.0.0.'
38+
in drupal:8.0.0 and is removed from drupal:9.0.0.',
39+
'Method Drupal\Core\Entity\EntityManager::clearDisplayModeInfo() should return $this(Drupal\Core\Entity\EntityManager) but return statement is missing.'
3940
]
4041
];
4142
yield [
@@ -46,5 +47,13 @@ public function dataDeprecatedSamples(): \Generator
4647
'Call to deprecated constant DATETIME_DATE_STORAGE_FORMAT: Deprecated in drupal:8.5.0 and is removed from drupal:9.0.0. Use \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface::DATE_STORAGE_FORMAT instead.',
4748
]
4849
];
50+
yield [
51+
__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/UsesDeprecatedServiceMethod.php',
52+
2,
53+
[
54+
'\Drupal calls should be avoided in classes, use dependency injection instead',
55+
'Call to deprecated method getDefinitions() of class',
56+
]
57+
];
4958
}
5059
}

tests/src/DrupalIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function testDrupalTestInChildSiteContant() {
3131
public function testExtensionReportsError() {
3232
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module');
3333
$this->assertCount(1, $errors);
34+
$this->assertEquals('Function phpstan_fixtures_MissingReturnRule() should return string but return statement is missing.', $errors[0]->getMessage());
3435
}
3536

3637
}

0 commit comments

Comments
 (0)