diff --git a/src/Drupal/Driver/DrupalDriver.php b/src/Drupal/Driver/DrupalDriver.php index 6ed0325d..a4aad63b 100644 --- a/src/Drupal/Driver/DrupalDriver.php +++ b/src/Drupal/Driver/DrupalDriver.php @@ -23,7 +23,7 @@ class DrupalDriver implements DrupalDriverInterface { /** * Drupal core object. */ - public CoreInterface $core; + protected CoreInterface $core; /** * System path to the Drupal installation. @@ -38,7 +38,7 @@ class DrupalDriver implements DrupalDriverInterface { /** * Drupal core version. */ - public int $version; + protected int $version; /** * Set Drupal root and URI. @@ -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. * @@ -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; + } + /** * {@inheritdoc} */ diff --git a/src/Drupal/Driver/DrupalDriverInterface.php b/src/Drupal/Driver/DrupalDriverInterface.php index 7d24cba2..a5d98e89 100644 --- a/src/Drupal/Driver/DrupalDriverInterface.php +++ b/src/Drupal/Driver/DrupalDriverInterface.php @@ -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. @@ -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; + } diff --git a/tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php b/tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php index 2f4b6786..055213ee 100644 --- a/tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php +++ b/tests/Drupal/Tests/Driver/Unit/CoreLookupTest.php @@ -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; } diff --git a/tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php b/tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php index 93c2aa04..ea656b07 100644 --- a/tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php +++ b/tests/Drupal/Tests/Driver/Unit/DrupalDriverDelegationTest.php @@ -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; }