Skip to content

Commit 9d218ec

Browse files
authored
Fix autoloading of PhpunitCompatibilityTrait (#145)
* Adjust autoloading * Verify phpstan/phpstan:0.12.40 works * Verify phpstan/phpstan:0.12.42 works
2 parents 0daeb13 + 8f12c60 commit 9d218ec

File tree

3 files changed

+16
-20
lines changed

3 files changed

+16
-20
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"autoload-dev": {
3939
"classmap": ["tests/src"]
4040
},
41+
"conflict": {
42+
"phpstan/phpstan": "^0.12.43"
43+
},
4144
"extra": {
4245
"branch-alias": {
4346
"dev-master": "0.12-dev"

src/Drupal/DrupalAutoloader.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function register(Container $container): void
9595
return $a->getName() === 'blazy_test' ? 10 : 0;
9696
});
9797
$this->themeData = $this->extensionDiscovery->scan('theme');
98-
$this->addCoreNamespaces();
98+
$this->addTestNamespaces();
9999
$this->addModuleNamespaces();
100100
$this->addThemeNamespaces();
101101
$this->registerPs4Namespaces($this->namespaces);
@@ -209,28 +209,18 @@ protected function loadLegacyIncludes(): void
209209
}
210210
}
211211

212-
protected function addCoreNamespaces(): void
212+
protected function addTestNamespaces(): void
213213
{
214-
foreach (['Core', 'Component'] as $parent_directory) {
215-
$path = $this->drupalRoot . '/core/lib/Drupal/' . $parent_directory;
216-
$parent_namespace = 'Drupal\\' . $parent_directory;
217-
foreach (new \DirectoryIterator($path) as $component) {
218-
if (!$component->isDot() && $component->isDir()) {
219-
$this->namespaces[$parent_namespace . '\\' . $component->getFilename()] = $path . '/' . $component->getFilename();
220-
}
221-
}
222-
}
223-
224214
// Add core test namespaces.
225215
$core_tests_dir = $this->drupalRoot . '/core/tests/Drupal';
216+
$this->namespaces['Drupal\\BuildTests'] = $core_tests_dir . '/BuildTests';
217+
$this->namespaces['Drupal\\FunctionalJavascriptTests'] = $core_tests_dir . '/FunctionalJavascriptTests';
218+
$this->namespaces['Drupal\\FunctionalTests'] = $core_tests_dir . '/FunctionalTests';
219+
$this->namespaces['Drupal\\KernelTests'] = $core_tests_dir . '/KernelTests';
226220
$this->namespaces['Drupal\\Tests'] = $core_tests_dir . '/Tests';
227221
$this->namespaces['Drupal\\TestSite'] = $core_tests_dir . '/TestSite';
228-
$this->namespaces['Drupal\\KernelTests'] = $core_tests_dir . '/KernelTests';
229-
$this->namespaces['Drupal\\FunctionalTests'] = $core_tests_dir . '/FunctionalTests';
230-
$this->namespaces['Drupal\\FunctionalJavascriptTests'] = $core_tests_dir . '/FunctionalJavascriptTests';
231-
$this->namespaces['Drupal\\Tests\\TestSuites'] = $this->drupalRoot . '/core/tests/TestSuites';
232-
$this->namespaces['Drupal\\BuildTests'] = $core_tests_dir . '/BuildTests';
233222
$this->namespaces['Drupal\\TestTools'] = $core_tests_dir . '/TestTools';
223+
$this->namespaces['Drupal\\Tests\\TestSuites'] = $this->drupalRoot . '/core/tests/TestSuites';
234224
}
235225

236226
protected function addModuleNamespaces(): void

tests/src/DrupalIntegrationTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPStan\Drupal;
44

5+
use PHPStan\Analyser\Error;
6+
57
final class DrupalIntegrationTest extends AnalyzerTestBase {
68

79
public function testInstallPhp() {
@@ -52,16 +54,17 @@ public function testExtensionReportsError() {
5254

5355
public function testExtensionTestSuiteAutoloading()
5456
{
55-
$this->markTestSkipped('Causing a ridiculous amount of memory usage.');
5657
$paths = [
5758
__DIR__ . '/../fixtures/drupal/modules/module_with_tests/tests/src/Unit/ModuleWithTestsTest.php',
5859
__DIR__ . '/../fixtures/drupal/modules/module_with_tests/tests/src/Traits/ModuleWithTestsTrait.php',
5960
__DIR__ . '/../fixtures/drupal/modules/module_with_tests/tests/src/TestSite/ModuleWithTestsTestSite.php',
6061
];
6162
foreach ($paths as $path) {
6263
$errors = $this->runAnalyze($path);
63-
$this->assertCount(0, $errors->getErrors(), print_r($errors, true));
64-
$this->assertCount(0, $errors->getInternalErrors(), print_r($errors, true));
64+
$this->assertCount(0, $errors->getErrors(), implode(PHP_EOL, array_map(static function (Error $error) {
65+
return $error->getMessage();
66+
}, $errors->getErrors())));
67+
$this->assertCount(0, $errors->getInternalErrors(), implode(PHP_EOL, $errors->getInternalErrors()));
6568
}
6669
}
6770

0 commit comments

Comments
 (0)