function TestSiteInstallCommand::getSetupClass
Same name in other branches
- 9 core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php \Drupal\TestSite\Commands\TestSiteInstallCommand::getSetupClass()
- 10 core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php \Drupal\TestSite\Commands\TestSiteInstallCommand::getSetupClass()
- 11.x 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
File
-
core/
tests/ Drupal/ TestSite/ Commands/ TestSiteInstallCommand.php, line 136
Class
- TestSiteInstallCommand
- Command to create a test Drupal site.
Namespace
Drupal\TestSite\CommandsCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.