Skip to content

Commit 8ddbcc3

Browse files
mglamanclaude
andauthored
Move phpstan_fixtures test data to tests/src/Rules/data (#974)
* Move phpstan_fixtures test data to tests/src/Rules/data Moves rule test data files out of the phpstan_fixtures Drupal module fixture and into the standard tests/src/Rules/data/ directory, keeping test data co-located with the tests that use it. Also removes dead fixture files that were no longer referenced by any test (AppRootParameter, DeprecatedGlobalConstants, EntityFieldReflection, EntityQueryHasAccessRule). Refs #723 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Add unit test for SplString pseudo-service type resolution Replaces the coverage that was lost when AppRootParameter.php was removed. DrupalServiceDefinition::getType() maps SplString to StringType to handle Drupal pseudo-services like 'app.root' which are strings injected into the container rather than real objects. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Register app.root as a synthetic SplString service in DrupalAutoloader app.root is set programmatically by DrupalKernel::initializeContainer() as a synthetic SplString service (not defined in any services.yml). The DrupalAutoloader already hardcodes other synthetic services like kernel, class_loader, and service_container — app.root belongs in the same block. This makes the existing SplString → StringType mapping in DrupalServiceDefinition::getType() reachable, and lets type assertions on \Drupal::getContainer()->get('app.root') resolve to string. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Remove dead SplString pseudo-service handling app.root is a container parameter in Drupal, not a service. The SplString workaround in DrupalServiceDefinition::getType() was never reachable because nothing registered app.root as a service with class SplString. AppRootParameter.php was already removed as part of dead code cleanup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 73172cf commit 8ddbcc3

24 files changed

+23
-141
lines changed

src/Drupal/DrupalServiceDefinition.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace mglaman\PHPStanDrupal\Drupal;
44

55
use PHPStan\Type\ObjectType;
6-
use PHPStan\Type\StringType;
76
use PHPStan\Type\Type;
87
use PHPStan\Type\TypeCombinator;
98
use function count;
@@ -110,13 +109,6 @@ public function getDeprecatedDescription(): string
110109

111110
public function getType(): Type
112111
{
113-
// Work around Drupal misusing the SplString class for string
114-
// pseudo-services such as 'app.root'.
115-
// @see https://www.drupal.org/project/drupal/issues/3074585
116-
if ($this->getClass() === 'SplString') {
117-
return new StringType();
118-
}
119-
120112
$decorating_services = $this->getDecorators();
121113
if (count($decorating_services) !== 0) {
122114
$combined_services = [];

tests/fixtures/drupal/modules/phpstan_fixtures/src/AppRootParameter.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/fixtures/drupal/modules/phpstan_fixtures/src/DeprecatedGlobalConstants.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/fixtures/drupal/modules/phpstan_fixtures/src/EntityFieldReflection/EntityFieldMagicalGetters.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/fixtures/drupal/modules/phpstan_fixtures/src/EntityFieldReflection/EntityFieldOriginalProperty.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/fixtures/drupal/modules/phpstan_fixtures/src/EntityQueryHasAccessRule.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

tests/src/Rules/ConfigEntityConfigExportRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testConfigExportRuleCheck(string $path, array $errorMessages): v
2727
public static function pluginData(): \Generator
2828
{
2929
yield [
30-
__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/src/Entity/ConfigWithoutExport.php',
30+
__DIR__ . '/data/config-entity-without-export.php',
3131
[
3232
[
3333
'Configuration entity must define a `config_export` key. See https://www.drupal.org/node/2481909',
@@ -36,7 +36,7 @@ public static function pluginData(): \Generator
3636
]
3737
];
3838
yield [
39-
__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/src/Entity/ConfigWithExport.php',
39+
__DIR__ . '/data/config-entity-with-export.php',
4040
[]
4141
];
4242
}

tests/src/Rules/EntityQueryHasAccessCheckRuleTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ public function test(array $files, array $errors): void
2727
public static function cases(): \Generator
2828
{
2929
yield [
30-
[__DIR__.'/../../fixtures/drupal/modules/phpstan_fixtures/src/EntityQueryWithAccessRule.php'],
30+
[__DIR__.'/data/entity-query-access-check-valid.php'],
3131
[],
3232
];
3333

3434
yield [
35-
[__DIR__.'/../../fixtures/drupal/modules/phpstan_fixtures/src/EntityQueryWithoutAccessRule.php'],
35+
[__DIR__.'/data/entity-query-access-check-invalid.php'],
3636
[
3737
[
3838
'Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.',
39-
11,
39+
9,
4040
'See https://www.drupal.org/node/3201242',
4141
],
4242
[
4343
'Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.',
44-
19,
44+
17,
4545
'See https://www.drupal.org/node/3201242',
4646
],
4747
],

tests/src/Rules/GlobalDrupalDependencyInjectionRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function resultData(): \Generator
2929
[],
3030
];
3131
yield [
32-
__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/src/UsesDeprecatedUrlFunction.php',
32+
__DIR__ . '/data/global-drupal-di-deprecated-url.php',
3333
[
3434
[
3535
'\Drupal calls should be avoided in classes, use dependency injection instead',
@@ -38,7 +38,7 @@ public static function resultData(): \Generator
3838
]
3939
];
4040
yield [
41-
__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/src/TestServicesMappingExtension.php',
41+
__DIR__ . '/data/global-drupal-di-service-mapping.php',
4242
[
4343
[
4444
'\Drupal calls should be avoided in classes, use dependency injection instead',

tests/src/Rules/LoadIncludesRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public static function cases(): \Generator
2626
{
2727
yield [
2828
[
29-
__DIR__ . '/../../fixtures/drupal/modules/phpstan_fixtures/phpstan_fixtures.module'
29+
__DIR__ . '/data/load-include-invalid.php'
3030
],
3131
[
3232
[
3333
'File modules/phpstan_fixtures/phpstan_fixtures.fetch.inc could not be loaded from Drupal\Core\Extension\ModuleHandlerInterface::loadInclude',
34-
25,
34+
5,
3535
]
3636
],
3737
];

0 commit comments

Comments
 (0)