Skip to content

Commit b8b14a2

Browse files
authored
blazy test.module fix (#45)
* Test failure with blazy_test.module * Ignore the Blazy test module * Push blazy_test loading to last. * Try another way to test * Verify the fix with new tests * Sorting broke module namespace registration
1 parent 7e7d1f3 commit b8b14a2

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

.travis.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@ before_install:
88
- composer global require "hirak/prestissimo:^0.3"
99
install:
1010
- composer install --no-interaction
11+
- composer create-project drupal-composer/drupal-project:8.x-dev $TRAVIS_BUILD_DIR/../drupal --no-interaction --no-progress
1112
script:
1213
# Inspections
1314
- ./vendor/bin/phpcs src
1415
- ./vendor/bin/phpstan analyze src
1516
- ./vendor/bin/phpunit
1617

17-
# Try to add to a Drupal setup.
18-
- composer create-project drupal-composer/drupal-project:8.x-dev $TRAVIS_BUILD_DIR/../drupal --no-interaction
18+
# Install package to a Drupal project. Use repository key 1 to not override Drupal's packagist endpoint.
1919
- cd $TRAVIS_BUILD_DIR/../drupal
20-
21-
# Install dependency.
22-
- composer config repositories.0 path $TRAVIS_BUILD_DIR
23-
- cat composer.json
20+
- composer config repositories.1 path $TRAVIS_BUILD_DIR
2421
- composer require mglaman/phpstan-drupal *@dev
2522
- cp $TRAVIS_BUILD_DIR/tests/fixtures/drupal-phpstan.neon phpstan.neon
23+
24+
# Test that a known non-failing file doesn't error out.
2625
- ./vendor/bin/phpstan analyze web/core/install.php
27-
- ./vendor/bin/phpstan analyze web/core/modules/migrate_drupal --no-progress | grep -q "tests/fixtures" && echo 1 || echo 0
26+
# Verify test fixtures are ignored.
27+
- ./vendor/bin/phpstan analyze web/core/modules/migrate_drupal --no-progress | grep -q "tests/fixtures" && false || true
28+
29+
# Check "Cannot redeclare token_theme() due to blazy_test.module"
30+
- composer require drupal/token drupal/blazy
31+
- ./vendor/bin/phpstan analyze web/modules/contrib/blazy --no-progress || if (($? == 255)); then false; else true; fi
2832

2933
cache:
3034
directories:

src/Drupal/Bootstrap.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ class Bootstrap
2828
/**
2929
* List of available modules.
3030
*
31-
* @var \PHPStan\Drupal\Extension[]
31+
* @var Extension[]
3232
*/
3333
protected $moduleData = [];
3434

3535
/**
3636
* List of available themes.
3737
*
38-
* @var \PHPStan\Drupal\Extension[]
38+
* @var Extension[]
3939
*/
4040
protected $themeData = [];
4141

@@ -69,12 +69,16 @@ public function register(): void
6969
$this->extensionDiscovery = new ExtensionDiscovery($this->drupalRoot);
7070
$this->extensionDiscovery->setProfileDirectories([]);
7171
$profiles = $this->extensionDiscovery->scan('profile');
72-
$profile_directories = array_map(function (\PHPStan\Drupal\Extension $profile) : string {
72+
$profile_directories = array_map(static function (Extension $profile) : string {
7373
return $profile->getPath();
7474
}, $profiles);
7575
$this->extensionDiscovery->setProfileDirectories($profile_directories);
7676

7777
$this->moduleData = array_merge($this->extensionDiscovery->scan('module'), $profiles);
78+
usort($this->moduleData, static function (Extension $a, Extension $b) {
79+
// blazy_test causes errors, ensure it is loaded last.
80+
return $a->getName() === 'blazy_test' ? 10 : 0;
81+
});
7882
$this->themeData = $this->extensionDiscovery->scan('theme');
7983

8084
$this->loadLegacyIncludes();
@@ -147,7 +151,8 @@ protected function addCoreNamespaces(): void
147151
}
148152
protected function addModuleNamespaces(): void
149153
{
150-
foreach ($this->moduleData as $module_name => $module) {
154+
foreach ($this->moduleData as $module) {
155+
$module_name = $module->getName();
151156
$module_dir = $this->drupalRoot . '/' . $module->getPath();
152157
$this->namespaces["Drupal\\$module_name"] = $module_dir . '/src';
153158

0 commit comments

Comments
 (0)