You are here

protected function TestSiteInstallCommand::getSetupClass in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php \Drupal\TestSite\Commands\TestSiteInstallCommand::getSetupClass()

Gets the setup class.

Parameters

string|null $file: The file to get the setup class from.

Return value

string|null The setup class contained in the provided $file.

Throws

\InvalidArgumentException Thrown if the file does not exist, does not contain a class or the class does not implement \Drupal\TestSite\TestSetupInterface or \Drupal\TestSite\TestPreinstallInterface.

1 call to TestSiteInstallCommand::getSetupClass()
TestSiteInstallCommand::execute in core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php
Executes the current command.

File

core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php, line 136

Class

TestSiteInstallCommand
Command to create a test Drupal site.

Namespace

Drupal\TestSite\Commands

Code

protected function getSetupClass($file) {
  if ($file === NULL) {
    return;
  }
  if (!file_exists($file)) {
    throw new \InvalidArgumentException("The file {$file} does not exist.");
  }
  $classes = get_declared_classes();
  include_once $file;
  $new_classes = array_values(array_diff(get_declared_classes(), $classes));
  if (empty($new_classes)) {
    throw new \InvalidArgumentException("The file {$file} does not contain a class.");
  }
  $class = array_pop($new_classes);
  if (!is_subclass_of($class, TestSetupInterface::class) && !is_subclass_of($class, TestPreinstallInterface::class)) {
    throw new \InvalidArgumentException("The class {$class} contained in {$file} needs to implement \\Drupal\\TestSite\\TestSetupInterface or \\Drupal\\TestSite\\TestPreinstallInterface");
  }
  return $class;
}