Skip to content

Commit f78fb38

Browse files
committed
Verify service mapping works, but deprecations are not caught
1 parent 89fcb15 commit f78fb38

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

tests/fixtures/drupal/modules/phpstan_fixtures/src/UsesDeprecatedServiceMethod.php renamed to tests/fixtures/drupal/modules/phpstan_fixtures/src/TestServicesMappingExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
use Drupal\Core\Entity\EntityManager;
66

7-
class UsesDeprecatedServiceMethod {
7+
class TestServicesMappingExtension {
88
public function test() {
99
$entity_manager = \Drupal::getContainer()->get('entity.manager');
10-
// Deprecated for EntityTypeManagerInterface::getDefinitions().
10+
$doesNotExist = $entity_manager->thisMethodDoesNotExist();
11+
// @todo this should be throwing deprecations...
1112
$definitions = $entity_manager->getDefinitions();
1213
}
1314
}

tests/src/DeprecationRulesTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,5 @@ public function dataDeprecatedSamples(): \Generator
4747
'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.',
4848
]
4949
];
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-
];
5850
}
5951
}

tests/src/DrupalIntegrationTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ public function testExtensionReportsError() {
3434
$this->assertEquals('Function phpstan_fixtures_MissingReturnRule() should return string but return statement is missing.', $errors[0]->getMessage());
3535
}
3636

37+
public function testServiceMapping() {
38+
$errorMessages = [
39+
'\Drupal calls should be avoided in classes, use dependency injection instead',
40+
'Call to an undefined method Drupal\Core\Entity\EntityManager::thisMethodDoesNotExist().',
41+
];
42+
$errors = $this->runAnalyze(__DIR__ . '/../fixtures/drupal/modules/phpstan_fixtures/src/TestServicesMappingExtension.php');
43+
$this->assertCount(2, $errors);
44+
foreach ($errors as $key => $error) {
45+
$this->assertEquals($errorMessages[$key], $error->getMessage());
46+
}
47+
}
3748
}

0 commit comments

Comments
 (0)