Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,12 @@ jobs:
fail-fast: false
matrix:
include:
- php_version: '8.2'
drupal_version: '10'
deps: 'normal'
- php_version: '8.2'
drupal_version: '10'
deps: 'lowest'
- php_version: '8.3'
drupal_version: '10'
deps: 'normal'
- php_version: '8.3'
drupal_version: '10'
deps: 'lowest'
- php_version: '8.3'
drupal_version: '11'
deps: 'normal'
- php_version: '8.3'
drupal_version: '11'
deps: 'lowest'
- php_version: '8.4'
drupal_version: '10'
deps: 'normal'
- php_version: '8.4'
drupal_version: '10'
deps: 'lowest'
- php_version: '8.4'
drupal_version: '11'
deps: 'normal'
Expand Down Expand Up @@ -117,10 +99,6 @@ jobs:
- name: Add Drupal core dependency
run: composer require --no-interaction --dev --no-update drupal/core-recommended:^${DRUPAL_VERSION} drupal/core-composer-scaffold:^${DRUPAL_VERSION}

- name: Pin Drupal 10 tooling
if: ${{ matrix.drupal_version == '10' }}
run: composer require --no-interaction --dev --no-update mglaman/phpstan-drupal:^1.1.25 phpstan/phpstan:^1.10 phpunit/phpunit:^9.6 symfony/phpunit-bridge:^6.4

- name: Install Composer dependencies
run: |
if [[ "${{ matrix.deps }}" == "lowest" ]]; then
Expand All @@ -131,7 +109,6 @@ jobs:

- name: Migrate PHPUnit configuration
run: vendor/bin/phpunit --migrate-configuration || true
if: "${{ matrix.drupal_version == '11'}}"

- name: Test with coverage
if: ${{ matrix.coverage }}
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This repository tests the drivers and field handlers:
## Setting up the local environment

Testing is performed automatically in GitHub Actions when a PR is
submitted. To execute tests locally, ensure you have PHP 8.2+
submitted. To execute tests locally, ensure you have PHP 8.3+
installed:

```shell
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ A collection of lightweight drivers with a common interface for
interacting with [Drupal](https://www.drupal.org). These are generally
intended for testing and are not meant to be API-complete.

> **Note:** v3 supports Drupal 10 and 11 on PHP 8.2+. Sites that
> need Drupal 7 or PHP 8.1 should pin to the
> [`2.x` branch](https://github.com/jhedstrom/DrupalDriver/tree/2.x).
> See [UPGRADING.md](UPGRADING.md) for the v2 to v3 migration
> guide.
## Supported versions

| Version | Drupal | PHP | Support |
| --- | --- | --- | --- |
| 4.x | 11 | 8.3, 8.4 | Active development |
| 3.x | 10, 11 | 8.2, 8.3, 8.4 | Security fixes only until 1 July 2027. 3.4 is the final release. |
| 2.x | 8, 9, 10, 11 | 7.4+ | Unsupported |

See [UPGRADING.md](UPGRADING.md) for migration guides.

## Drivers

Expand Down
16 changes: 14 additions & 2 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Upgrading

## From v3 to v4

### Platform requirements

- PHP `^8.3` (was `^8.2`).
- Drupal `^11` (was `^10 || ^11`). `DrupalDriver::detectMajorVersion()` throws a
`BootstrapException` when it detects Drupal < 11, and
`DrupalDriver::setCoreFromVersion()` stops walking the `Drupal\Driver\Core{N}\Core`
lookup chain at `Core11`.
- Sites on Drupal 10 or PHP 8.2 should pin to `^3.4`, which receives security
fixes only. See the support table in [README.md](README.md).

## From v2 to v3

v3 reworks the driver contract into a set of composable capability interfaces,
Expand All @@ -16,8 +28,8 @@ updating.
detects Drupal < 10.
- Symfony `^6.4 || ^7` for `dependency-injection`, `process`, and
`phpunit-bridge`.
- Sites that need to stay on PHP 8.1 or Drupal 9 should pin to the 2.x line,
now maintained on the `2.x` branch. `master` is the active 3.x branch.
- Sites that need to stay on PHP 8.1 or Drupal 9 have no supported option: the
2.x line is unsupported.

### Namespace and source layout changes

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
],
"homepage": "http://github.com/jhedstrom/DrupalDriver",
"require": {
"php": "^8.2",
"drupal/core-utility": "^10 || ^11",
"php": "^8.3",
"drupal/core-utility": "^11",
"symfony/dependency-injection": "^6.4 || ^7",
"symfony/process": "^6.4 || ^7"
},
Expand All @@ -46,7 +46,7 @@
"ergebnis/composer-normalize": "^2.50",
"mglaman/phpstan-drupal": "^2.0",
"mikey179/vfsstream": "^1.6.11",
"palantirnet/drupal-rector": "^0.21.1",
"palantirnet/drupal-rector": "^1.1.3",
"php-parallel-lint/php-parallel-lint": "^1.0",
"phpspec/prophecy-phpunit": "^2",
"phpstan/extension-installer": "^1.4",
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ parameters:
path: src/*
-
# entity_test_create_bundle() is deprecated in Drupal 11.2 in favour of
# EntityTestHelper::createBundle(); kept as a fallback for Drupal 10 and
# earlier 11.x where the helper class does not yet exist.
# EntityTestHelper::createBundle(); kept as a fallback for 11.x before
# 11.2, where the helper class does not yet exist.
message: '#Call to deprecated function entity_test_create_bundle\(\).*#'
paths:
- tests/Drupal/Tests/Driver/Kernel/Core/Field/FieldHandlerKernelTestBase.php
Expand Down
18 changes: 14 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
declare(strict_types=1);

use DrupalFinder\DrupalFinderComposerRuntime;
use DrupalRector\Set\Drupal10SetList;
use DrupalRector\Rector\Deprecation\FunctionToStaticRector;
use DrupalRector\Rector\PHPUnit\PhpUnitAddRunTestsInSeparateProcessesAttributeRector;
use DrupalRector\Set\Drupal11SetList;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
Expand All @@ -30,6 +31,7 @@
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
Expand Down Expand Up @@ -59,21 +61,23 @@
earlyReturn: TRUE,
)
->withSets([
Drupal10SetList::DRUPAL_10,
Drupal11SetList::DRUPAL_11,
])
->withRules([
DeclareStrictTypesRector::class,
YieldDataProviderRector::class,
])
->withSkip([
// Rules added by Rector's rule sets.
// Overridden methods already carry an '{@inheritdoc}' docblock, which
// the Drupal coding standard requires; the attribute repeats it.
AddOverrideAttributeToOverriddenMethodsRector::class,
CatchExceptionNameMatchingTypeRector::class,
ChangeSwitchToMatchRector::class,
// Constructor property promotion mangles existing docblocks for the
// promoted parameter and trips PHPCS multi-line declaration sniffs.
ClassPropertyAssignToConstructorPromotionRector::class,
CompleteDynamicPropertiesRector::class,
CountArrayToEmptyArrayComparisonRector::class,
DisallowedEmptyRuleFixerRector::class,
InlineArrayReturnAssignRector::class,
NewlineAfterStatementRector::class,
Expand All @@ -86,6 +90,12 @@
RenameVariableToMatchMethodCallReturnTypeRector::class,
RenameVariableToMatchNewTypeRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
// Wraps a call that is already guarded by 'class_exists()' in a second
// version check, so the version is tested twice for one call.
FunctionToStaticRector::class,
// Isolating every kernel test in its own process multiplies the suite
// runtime; the tests share no mutable global state.
PhpUnitAddRunTestsInSeparateProcessesAttributeRector::class,
// Breaks 'drupal_static()' caching in 'Core::getAllPermissions()':
// assigning into the static reference is required for subsequent
// calls to hit the cache, so the intermediate variable is not dead
Expand Down
14 changes: 6 additions & 8 deletions src/Drupal/Driver/Core/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\RouteObjectInterface;
use Drupal\Driver\Capability\CreationAliasCapabilityInterface;
use Drupal\Driver\Core\Field\DefaultHandler;
use Drupal\Driver\Core\Field\FieldClassifier;
Expand Down Expand Up @@ -222,7 +223,7 @@ protected function deriveFieldType(string $short_class_name): string {
*
* Subclasses override this method when they ship a version-specific
* classifier. The default returns the base 'FieldClassifier' which covers
* Drupal 10 and 11.
* Drupal 11.
*/
protected function createFieldClassifier(): FieldClassifierInterface {
return new FieldClassifier($this->getEntityFieldManager());
Expand All @@ -244,7 +245,7 @@ public function getFieldClassifier(): FieldClassifierInterface {
*
* Subclasses override this method when they ship a version-specific value
* shape classifier. The default returns the base 'FieldShapeClassifier' which
* covers Drupal 10 and 11.
* covers Drupal 11.
*/
protected function createFieldShapeClassifier(): FieldShapeClassifierInterface {
return new FieldShapeClassifier();
Expand Down Expand Up @@ -446,12 +447,9 @@ public function bootstrap(): void {
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
// A route is required for route matching. In order to support Drupal 10
// along with 8/9, we use the hardcoded values of RouteObjectInterface
// constants ROUTE_NAME and ROUTE_OBJECT.
// @see https://www.drupal.org/node/3151009
$request->attributes->set('_route_object', new Route('<none>'));
$request->attributes->set('_route', '<none>');
// Route matching requires a route on the request.
$request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, new Route('<none>'));
$request->attributes->set(RouteObjectInterface::ROUTE_NAME, '<none>');

$kernel->preHandle($request);

Expand Down
2 changes: 1 addition & 1 deletion src/Drupal/Driver/Core/Field/FieldClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Drupal\field\Entity\FieldStorageConfig;

/**
* Default Drupal 10/11 field classifier.
* Default Drupal 11 field classifier.
*
* See 'src/Drupal/Driver/Core/Field/README.md' for the full truth table.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Drupal/Driver/Core/Field/FieldShapeClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Drupal\Core\TypedData\ListDataDefinitionInterface;

/**
* Default Drupal 10/11 value-shape classifier.
* Default Drupal 11 value-shape classifier.
*
* See 'src/Drupal/Driver/Core/Field/README.md' for the value-shape axis and how
* 'Core' consumes it during handler selection.
Expand Down
8 changes: 4 additions & 4 deletions src/Drupal/Driver/DrupalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function setCoreFromVersion(): void {
$version = $this->getDrupalVersion();
$candidates = [];

for ($n = $version; $n >= 10; $n--) {
for ($n = $version; $n >= 11; $n--) {
$candidates[] = sprintf('Drupal\\Driver\\Core%d\\Core', $n);
}

Expand Down Expand Up @@ -441,8 +441,8 @@ protected function detectMajorVersion(): int {
throw new BootstrapException(sprintf('Unable to extract major Drupal core version from version string %s.', $version_string));
}

if ((int) $major < 10) {
throw new BootstrapException(sprintf('Unsupported Drupal core version %s. Drupal 10 or higher is required.', $version_string));
if ((int) $major < 11) {
throw new BootstrapException(sprintf('Unsupported Drupal core version %s. Drupal 11 or higher is required.', $version_string));
}

return (int) $major;
Expand All @@ -452,7 +452,7 @@ protected function detectMajorVersion(): int {
* Reads the Drupal VERSION constant.
*
* Subclasses override this to return a synthetic version for testing the
* non-numeric and sub-10 branches of 'detectMajorVersion()'.
* non-numeric and sub-11 branches of 'detectMajorVersion()'.
*/
protected function readVersionConstant(): string {
return \Drupal::VERSION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('user');
$this->installEntitySchema('block_content');
// Only 'system' config is installed. Installing 'block_content' config
// on Drupal 10 / Drupal 11-lowest pulls in
// 'field.storage.block_content.body', whose schema references the 'text'
// module - unnecessary surface for this test, which creates its own
// body-less 'block_content_type' inline.
// Only 'system' config is installed. Installing 'block_content' config on
// Drupal 11-lowest pulls in 'field.storage.block_content.body', whose
// schema references the 'text' module - unnecessary surface for this test,
// which creates its own body-less 'block_content_type' inline.
$this->installConfig(['system']);
\Drupal::service('theme_installer')->install(['stark']);
$this->core = new Core($this->root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testConstructorDetectsVersion(): void {

$version = $driver->getDrupalVersion();

$this->assertGreaterThanOrEqual(10, $version, 'Driver should detect Drupal 10 or higher.');
$this->assertGreaterThanOrEqual(11, $version, 'Driver should detect Drupal 11 or higher.');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Drupal/Tests/Driver/Unit/DrupalDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public function testDetectMajorVersionRejectsNonNumeric(): void {
}

/**
* Tests that 'detectMajorVersion()' rejects pre-10 versions.
* Tests that 'detectMajorVersion()' rejects pre-11 versions.
*/
public function testDetectMajorVersionRejectsPre10(): void {
public function testDetectMajorVersionRejectsPre11(): void {
$this->expectException(BootstrapException::class);
$this->expectExceptionMessageMatches('/Unsupported Drupal core version/');

FakeVersionDrupalDriver::$nextVersion = '9.5.0';
FakeVersionDrupalDriver::$nextVersion = '10.4.0';
new FakeVersionDrupalDriver(__DIR__, 'default');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* The parent constructor calls 'detectMajorVersion()' which in turn calls
* 'readVersionConstant()'. Overriding the latter lets tests exercise the
* malformed-version and sub-10 branches without mutating '\Drupal::VERSION'.
* malformed-version and sub-11 branches without mutating '\Drupal::VERSION'.
*/
class FakeVersionDrupalDriver extends DrupalDriver {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: 'Driver field test'
type: module
description: 'Provides custom field types with no driver handler, for kernel tests.'
package: Testing
core_version_requirement: ^10 || ^11
core_version_requirement: ^11
Loading