findDriverAutoloadDirectory example

/** * Tests that updates fail if the database does not meet the minimum version. */
  public function testUpdate() {
    if (Database::getConnection()->driver() !== 'mysql') {
      $this->markTestSkipped('This test only works with the mysql driver');
    }

    // Use a database driver that reports a fake database version that does     // not meet requirements. Only change the necessary settings in the database     // settings array so that run-tests.sh continues to work.     $autoload = Database::findDriverAutoloadDirectory('Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion', \Drupal::root());
    $settings['databases']['default']['default']['driver'] = (object) [
      'value' => 'DrivertestMysqlDeprecatedVersion',
      'required' => TRUE,
    ];
    $settings['databases']['default']['default']['namespace'] = (object) [
      'value' => 'Drupal\\driver_test\\Driver\\Database\\DrivertestMysqlDeprecatedVersion',
      'required' => TRUE,
    ];
    $settings['databases']['default']['default']['autoload'] = (object) [
      'value' => $autoload,
      'required' => TRUE,
    ];
    include_once DRUPAL_ROOT . '/core/includes/install.inc';

    $driver = $form_state->getValue('driver');
    $database = $form_state->getValue($driver);
    $drivers = drupal_get_database_types();
    $reflection = new \ReflectionClass($drivers[$driver]);
    $install_namespace = $reflection->getNamespaceName();
    // Cut the trailing \Install from namespace.     $database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\'));
    $database['driver'] = $driver;
    // See default.settings.php for an explanation of the 'autoload' key.     if ($autoload = Database::findDriverAutoloadDirectory($database['namespace'], DRUPAL_ROOT)) {
      $database['autoload'] = $autoload;
    }

    $form_state->set('database', $database);
    foreach ($this->getDatabaseErrors($database$form_state->getValue('settings_file')) as $name => $message) {
      $form_state->setErrorByName($name$message);
    }
  }

  /** * Get any database errors and links them to a form element. * * @param array $database * An array of database settings. * @param string $settings_file * The settings file that contains the database settings. * * @return array * An array of form errors keyed by the element name and parents. */
->method('getParameter')
      ->with('site.path')
      ->willReturn('');
    \Drupal::setContainer($container);
  }

  /** * @covers ::findDriverAutoloadDirectory * @dataProvider providerFindDriverAutoloadDirectory */
  public function testFindDriverAutoloadDirectory($expected$namespace$include_test_drivers) {
    $this->assertSame($expected, Database::findDriverAutoloadDirectory($namespace$this->root, $include_test_drivers));
  }

  /** * Data provider for ::testFindDriverAutoloadDirectory(). * * @return array */
  public function providerFindDriverAutoloadDirectory() {
    return [
      'core mysql' => ['core/modules/mysql/src/Driver/Database/mysql/', 'Drupal\mysql\Driver\Database\mysql', FALSE],
      'D8 custom fake' => [FALSE, 'Drupal\Driver\Database\corefake', TRUE],
      
    // set.     if (!isset($query['module']) && in_array($driver['mysql', 'pgsql', 'sqlite'], TRUE)) {
      $query['module'] = $driver;
    }

    if (isset($query['module']) && $query['module']) {
      $module = $query['module'];
      // Set up an additional autoloader. We don't use the main autoloader as       // this method can be called before Drupal is installed and is never       // called during regular runtime.       $namespace = "Drupal\\$module\\Driver\\Database\\$driver";
      $psr4_base_directory = Database::findDriverAutoloadDirectory($namespace$root$include_test_drivers);
      $additional_class_loader = new ClassLoader();
      $additional_class_loader->addPsr4($namespace . '\\', $psr4_base_directory);
      $additional_class_loader->register(TRUE);
      $connection_class = $namespace . '\\Connection';
    }

    if (!$module) {
      // Determine the connection class to use. Discover if the URL has a valid       // driver scheme for a Drupal 8 style custom driver.       // @todo Remove this in Drupal 10.       $connection_class = "Drupal\\Driver\\Database\\{$driver}\\Connection";
    }
if ($connection_info['default']['driver'] !== 'mysql') {
      $this->markTestSkipped('This test relies on overriding the mysql driver');
    }

    // Use a database driver that reports a fake database version that does     // not meet requirements.     unset($connection_info['default']['pdo']);
    unset($connection_info['default']['init_commands']);
    $connection_info['default']['driver'] = 'DrivertestMysqlDeprecatedVersion';
    $namespace = 'Drupal\\driver_test\\Driver\\Database\\DrivertestMysqlDeprecatedVersion';
    $connection_info['default']['namespace'] = $namespace;
    $connection_info['default']['autoload'] = Database::findDriverAutoloadDirectory($namespace, \Drupal::root());

    $this->settings['databases']['default'] = (object) [
      'value' => $connection_info,
      'required' => TRUE,
    ];
  }

  /** * {@inheritdoc} */
  protected function setUpSettings() {
    
Home | Imprint | This part of the site doesn't use cookies.