Skip to content
Merged
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
39 changes: 11 additions & 28 deletions src/Drupal/Driver/DrupalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DrupalDriver implements DrupalDriverInterface {
/**
* Drupal core object.
*/
public CoreInterface $core;
protected CoreInterface $core;

/**
* System path to the Drupal installation.
Expand All @@ -38,7 +38,7 @@ class DrupalDriver implements DrupalDriverInterface {
/**
* Drupal core version.
*/
public int $version;
protected int $version;

/**
* Set Drupal root and URI.
Expand Down Expand Up @@ -93,36 +93,12 @@ public function processBatch(): void {
}

/**
* Determine major Drupal version.
*
* @return int
* The major Drupal version.
*
* @throws \Drupal\Driver\Exception\BootstrapException
* Thrown when the Drupal version could not be determined.
*
* @see drush_drupal_version()
* {@inheritdoc}
*/
public function getDrupalVersion(): int {
return $this->version;
}

/**
* Injects the active Core implementation.
*
* Consumers override the driver's default Core lookup by passing any
* class that implements 'CoreInterface' - the class name and namespace
* do not matter. Typically called in a test bootstrap when the project
* ships its own Core subclass (e.g. one that registers additional field
* handlers in its 'registerDefaultFieldHandlers()' override).
*
* @param \Drupal\Driver\Core\CoreInterface $core
* The Core instance the driver should delegate to.
*/
public function setCore(CoreInterface $core): void {
$this->core = $core;
}

/**
* Automatically set the core from the current version.
*
Expand Down Expand Up @@ -155,12 +131,19 @@ public function setCoreFromVersion(): void {
}

/**
* Return current core.
* {@inheritdoc}
*/
public function getCore(): CoreInterface {
return $this->core;
}

/**
* {@inheritdoc}
*/
public function setCore(CoreInterface $core): void {
$this->core = $core;
}
Comment on lines +143 to +145
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Reset bootstrapped state when replacing core.

On Line 143-144, replacing the core without resetting bootstrapped can leave the driver in an inconsistent state (new core, old bootstrap flag), causing bootstrap to be skipped incorrectly.

Proposed fix
   public function setCore(CoreInterface $core): void {
     $this->core = $core;
+    $this->bootstrapped = FALSE;
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Drupal/Driver/DrupalDriver.php` around lines 143 - 145, The
setCore(CoreInterface $core) method currently replaces $this->core without
resetting the driver's bootstrapped flag; update setCore to assign the new core
and also set $this->bootstrapped = false (and clear any related
bootstrap-specific state if present) so the driver will re-run bootstrap for the
new core; modify the setCore function in DrupalDriver to reset the bootstrapped
property after assigning $this->core.


/**
* {@inheritdoc}
*/
Expand Down
33 changes: 33 additions & 0 deletions src/Drupal/Driver/DrupalDriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Drupal\Driver\Capability\RoleCapabilityInterface;
use Drupal\Driver\Capability\UserCapabilityInterface;
use Drupal\Driver\Capability\WatchdogCapabilityInterface;
use Drupal\Driver\Core\CoreInterface;

/**
* Contract for the full-featured Drupal driver.
Expand All @@ -40,4 +41,36 @@ interface DrupalDriverInterface extends
UserCapabilityInterface,
WatchdogCapabilityInterface {

/**
* Return current core.
*/
public function getCore(): CoreInterface;

/**
* Injects the active Core implementation.
*
* Consumers override the driver's default Core lookup by passing any
* class that implements 'CoreInterface' - the class name and namespace
* do not matter. Typically called in a test bootstrap when the project
* ships its own Core subclass (e.g. one that registers additional field
* handlers in its 'registerDefaultFieldHandlers()' override).
*
* @param \Drupal\Driver\Core\CoreInterface $core
* The Core instance the driver should delegate to.
*/
public function setCore(CoreInterface $core): void;

/**
* Returns the major Drupal version detected at construction time.
*
* The version is captured once when the driver is instantiated; the
* detection itself may throw BootstrapException, but this getter does not.
*
* @return int
* The major Drupal version.
*
* @see drush_drupal_version()
*/
public function getDrupalVersion(): int;

}
3 changes: 2 additions & 1 deletion tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ protected function createDriverWithVersion(int $version): DrupalDriver {
$uri_prop = $reflection->getProperty('uri');
$uri_prop->setValue($driver, 'default');

$driver->version = $version;
$version_property = $reflection->getProperty('version');
$version_property->setValue($driver, $version);

return $driver;
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ protected function createDriverWithCore(CoreInterface $core, int $version = 11):
$uri = $reflection->getProperty('uri');
$uri->setValue($driver, 'default');

$driver->version = $version;
$driver->core = $core;
$version_property = $reflection->getProperty('version');
$version_property->setValue($driver, $version);

$driver->setCore($core);

return $driver;
}
Expand Down
Loading