Initial Drupal 11 with DDEV setup

This commit is contained in:
gluebox
2025-10-08 11:39:17 -04:00
commit 89ef74b305
25344 changed files with 2599172 additions and 0 deletions

4
web/core/tests/PHPStan/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
composer.lock
coverage.cobertura.xml
junit.xml
vendor/

View File

@ -0,0 +1,43 @@
# Drupal custom PHPStan rules
This directory contains PHPStan rules specifically developed for Drupal.
## Subdirectories
* _Rules_: contains the actual rules.
* _tests_: contains PHPUnit tests for the rules.
* _fixtures_: contains fixture files for the PHPUnit tests of the rules.
## Enabling rules
Rules are executed when they are added to the the phpstan.neon(.dist)
configuration file of a PHPStan scan run. You need to add them under the
`rules` entry in the file, specifying the fully qualified class name of the
rule. For example:
```
rules:
- Drupal\PHPStan\Rules\ComponentTestDoesNotExtendCoreTest
```
## Testing rules
PHPStan rules must be tested in the context of the PHPStan testing framework,
that differs in terms of dependencies from Drupal's one.
Note that for this reason, these tests are run _separately_ from Drupal core
tests.
A _composer.json_ file is present in this directory, indicating the required
packages for the execution of the tests. Installing via composer
```
$ composer install
```
builds a _vendor_ subdirectory that includes all the packages required. Note
this packages' codebase is totally independent from Drupal core's one.
In the context of this directory, you can then execute the rule tests like
```
$ vendor/bin/phpunit tests
```

View File

@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
// cspell:ignore analyse
namespace Drupal\PHPStan\Rules;
use Drupal\BuildTests\Framework\BuildTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UnitTestCase;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\InClassNode;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
/**
* Ensures that no component tests are extending a core test base class.
*
* @implements Rule<\PHPStan\Node\InClassNode>
*
* @internal
*/
final class ComponentTestDoesNotExtendCoreTest implements Rule {
public function __construct(
private ReflectionProvider $reflectionProvider,
) {
}
/**
* {@inheritdoc}
*/
public function getNodeType(): string {
return InClassNode::class;
}
/**
* {@inheritdoc}
*/
public function processNode(Node $node, Scope $scope): array {
$class = $node->getClassReflection();
if (!str_starts_with($class->getName(), 'Drupal\Tests\Component')) {
return [];
}
$invalidParents = [
$this->reflectionProvider->getClass(UnitTestCase::class),
$this->reflectionProvider->getClass(BuildTestBase::class),
$this->reflectionProvider->getClass(KernelTestBase::class),
$this->reflectionProvider->getClass(BrowserTestBase::class),
];
foreach ($invalidParents as $invalidParent) {
if ($class->isSubclassOfClass($invalidParent)) {
return [
RuleErrorBuilder::message("Component tests should not extend {$invalidParent->getName()}.")
->line($node->getStartLine())
->build(),
];
}
}
return [];
}
}

View File

@ -0,0 +1,20 @@
{
"name": "drupal/phpstan-testing",
"description": "Tests Drupal core's PHPStan rules",
"require-dev": {
"phpunit/phpunit": "^11",
"phpstan/phpstan": "2.1.17"
},
"license": "GPL-2.0-or-later",
"autoload": {
"psr-4": {
"Drupal\\PHPStan\\Rules\\": "Rules/",
"Drupal\\BuildTests\\": "../Drupal/BuildTests/",
"Drupal\\FunctionalJavascriptTests\\": "../Drupal/FunctionalJavascriptTests",
"Drupal\\FunctionalTests\\": "../Drupal/FunctionalTests",
"Drupal\\KernelTests\\": "../Drupal/KernelTests/",
"Drupal\\Tests\\": "../Drupal/Tests/"
}
},
"require": {}
}

View File

@ -0,0 +1,63 @@
<?php
// phpcs:ignoreFile
declare(strict_types=1);
namespace Drupal\Tests\Component\Foo {
use Drupal\BuildTests\Framework\BuildTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
final class FooTest extends TestCase {
}
final class UnitTest extends UnitTestCase {
}
final class BuildTest extends BuildTestBase {
}
final class KernelTest extends KernelTestBase {
}
final class FunctionalTest extends BrowserTestBase {
}
final class FunctionalJavascriptTest extends WebDriverTestBase {
}
}
namespace Drupal\Tests\Core\Foo {
use Drupal\BuildTests\Framework\BuildTestBase;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\TestCase;
final class FooTest extends TestCase {
}
final class UnitTest extends UnitTestCase {
}
final class BuildTest extends BuildTestBase {
}
final class KernelTest extends KernelTestBase {
}
final class FunctionalTest extends BrowserTestBase {
}
final class FunctionalJavascriptTest extends WebDriverTestBase {
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutChangesToGlobalState="true"
failOnWarning="true"
cacheResult="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<php>
<!-- Set error reporting to E_ALL. -->
<ini name="error_reporting" value="32767"/>
<!-- Do not limit the amount of memory tests take to run. -->
<ini name="memory_limit" value="-1"/>
</php>
<testsuites>
<testsuite name="PHPStan tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<!-- Settings for coverage reports. -->
<source>
<include>
<directory>Rules</directory>
</include>
</source>
</phpunit>

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
// cspell:ignore analyse
namespace Drupal\PHPStan\Tests;
use Drupal\PHPStan\Rules\ComponentTestDoesNotExtendCoreTest;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
/**
* Tests ComponentTestDoesNotExtendCoreTest rule.
*/
class ComponentTestDoesNotExtendCoreTestTest extends RuleTestCase {
/**
* {@inheritdoc}
*/
protected function getRule(): Rule {
return new ComponentTestDoesNotExtendCoreTest(
self::getContainer()->getByType(ReflectionProvider::class),
);
}
/**
* {@inheritdoc}
*/
public function testRule(): void {
$this->analyse(
[__DIR__ . '/../fixtures/component-tests.php'],
[
[
'Component tests should not extend Drupal\Tests\UnitTestCase.',
19,
],
[
'Component tests should not extend Drupal\BuildTests\Framework\BuildTestBase.',
22,
],
[
'Component tests should not extend Drupal\KernelTests\KernelTestBase.',
25,
],
[
'Component tests should not extend Drupal\Tests\BrowserTestBase.',
28,
],
[
'Component tests should not extend Drupal\Tests\BrowserTestBase.',
31,
],
]
);
}
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Drupal\PHPStan\Tests;
use PHPUnit\Framework\TestCase;
/**
* Tests that PHPStan version used for rules testing matches core.
*/
class EnsurePHPStanVersionsMatchTest extends TestCase {
public function testVersions(): void {
$test_composer = json_decode(file_get_contents(__DIR__ . '/../composer.json'), TRUE);
$drupal_composer = json_decode(file_get_contents(__DIR__ . '/../../../../composer/Metapackage/PinnedDevDependencies/composer.json'), TRUE);
$this->assertSame($test_composer['require-dev']['phpstan/phpstan'], $drupal_composer['require']['phpstan/phpstan']);
}
}