Commit 3edf9bf3 authored by catch's avatar catch
Browse files

Issue #3129508 by Lal_, daffie, Suresh Prabhu Parkala: Change multiple...

Issue #3129508 by Lal_, daffie, Suresh Prabhu Parkala: Change multiple dirname()'s into a single dirname() with the use of the second parameter of dirname()

(cherry picked from commit 8f7f02c6)
parent bda5391e
......@@ -114,7 +114,7 @@
*
* This strips two levels of directories off the current directory.
*/
define('DRUPAL_ROOT', dirname(dirname(__DIR__)));
define('DRUPAL_ROOT', dirname(__DIR__, 2));
/**
* Returns and optionally sets the filename for a system resource.
......
......@@ -335,7 +335,7 @@ function install_begin_request($class_loader, &$install_state) {
}
$site_path = empty($install_state['site_path']) ? DrupalKernel::findSitePath($request, FALSE) : $install_state['site_path'];
Settings::initialize(dirname(dirname(__DIR__)), $site_path, $class_loader);
Settings::initialize(dirname(__DIR__, 2), $site_path, $class_loader);
// Ensure that procedural dependencies are loaded as early as possible,
// since the error/exception handlers depend on them.
......
......@@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
}
// Change the directory to the Drupal root.
chdir(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
chdir(dirname(__DIR__, 5));
// Check whether there is already an installation.
if ($this->isDrupalInstalled()) {
......
......@@ -222,7 +222,7 @@ public function getFormOptions(array $database) {
// @todo https:///www.drupal.org/node/3123240 Provide a better way to get
// the driver name.
$reflection = new \ReflectionClass($this);
$dir_parts = explode(DIRECTORY_SEPARATOR, dirname(dirname($reflection->getFileName())));
$dir_parts = explode(DIRECTORY_SEPARATOR, dirname($reflection->getFileName(), 2));
$driver = array_pop($dir_parts);
$form['database'] = [
......
......@@ -306,7 +306,7 @@ protected static function guessApplicationRoot() {
// - Removing the namespace directories from the path.
// - Getting the path to the directory two levels up from the path
// determined in the previous step.
return dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
return dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
}
/**
......
......@@ -91,7 +91,7 @@ public function phpUnitCommand() {
// reflection. We can determine the vendor directory based on that filename.
$autoloader = require $this->appRoot . '/autoload.php';
$reflector = new \ReflectionClass($autoloader);
$vendor_dir = dirname(dirname($reflector->getFileName()));
$vendor_dir = dirname($reflector->getFileName(), 2);
// The file in Composer's bin dir is a *nix link, which does not work when
// extracted from a tarball and generally not on Windows.
......
......@@ -42,7 +42,7 @@ public function setUp(): void {
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$module = $this->prophesize(Extension::class);
$module_path = dirname(dirname(dirname(dirname(__DIR__))));
$module_path = dirname(__DIR__, 4);
$module->getPath()->willReturn($module_path);
$module_handler->getModule('jsonapi')->willReturn($module->reveal());
$subscriber = new ResourceResponseValidator(
......
......@@ -21,7 +21,7 @@ protected function getPluginId() {
* {@inheritdoc}
*/
protected function getModuleAndPath() {
return ['path', dirname(dirname(dirname(dirname(__DIR__))))];
return ['path', dirname(__DIR__, 4)];
}
/**
......
......@@ -53,5 +53,5 @@
drupal_rebuild($autoloader, $request);
\Drupal::messenger()->addStatus('Cache rebuild complete.');
}
$base_path = dirname(dirname($request->getBaseUrl()));
$base_path = dirname($request->getBaseUrl(), 2);
header('Location: ' . $request->getSchemeAndHttpHost() . $base_path);
......@@ -19,7 +19,7 @@
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
......
......@@ -19,7 +19,7 @@
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
......
......@@ -20,7 +20,7 @@
$autoloader = require __DIR__ . '/../../autoload.php';
require_once __DIR__ . '/../includes/bootstrap.inc';
$request = Request::createFromGlobals();
Settings::initialize(dirname(dirname(__DIR__)), DrupalKernel::findSitePath($request), $autoloader);
Settings::initialize(dirname(__DIR__, 2), DrupalKernel::findSitePath($request), $autoloader);
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod')->boot();
// Run the database dump command.
......
......@@ -84,7 +84,7 @@ protected function configure() {
protected function execute(InputInterface $input, OutputInterface $output) {
// Determines and validates the setup class prior to installing a database
// to avoid creating unnecessary sites.
$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$root = dirname(__DIR__, 5);
chdir($root);
$class_name = $this->getSetupClass($input->getOption('setup-file'));
// Ensure we can install a site in the sites/simpletest directory.
......
......@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
*/
protected function tearDown(TestDatabase $test_database, $db_url): void {
// Connect to the test database.
$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$root = dirname(__DIR__, 5);
$database = Database::convertDbUrlToConnectionInfo($db_url, $root);
$database['prefix'] = ['default' => $test_database->getDatabasePrefix()];
Database::addConnectionInfo(__CLASS__, 'default', $database);
......
......@@ -42,7 +42,7 @@ protected function configure() {
* @throws \Symfony\Component\Console\Exception\InvalidArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
$root = dirname(__DIR__, 5);
chdir($root);
$this->classLoader = require 'autoload.php';
......
......@@ -38,7 +38,7 @@ public static function mutateTestBase($autoloader) {
}
// Inspired by Symfony's simple-phpunit remove typehints from TestCase.
$reflector = new \ReflectionClass($autoloader);
$vendor_dir = dirname(dirname($reflector->getFileName()));
$vendor_dir = dirname($reflector->getFileName(), 2);
// Mutate TestCase code to make it compatible with Drupal 8 and 9 tests.
$alteredCode = file_get_contents($alteredFile = $vendor_dir . '/phpunit/phpunit/src/Framework/TestCase.php');
$alteredCode = preg_replace('/^ ((?:protected|public)(?: static)? function \w+\(\)): void/m', ' $1', $alteredCode);
......
......@@ -416,7 +416,7 @@ protected function setUp() {
*/
protected function setUpAppRoot(): void {
if ($this->root === NULL) {
$this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
$this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
}
}
......
......@@ -55,7 +55,7 @@ public function updatedTestData() {
*/
public function testUpdated($builderClass, $path) {
// Create a DrupalCoreComposer for the System Under Test (current repo)
$repositoryRoot = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
$repositoryRoot = dirname(__DIR__, 6);
$drupalCoreInfo = DrupalCoreComposer::createFromPath($repositoryRoot);
// Rebuild the metapackage for the composer.json / composer.lock of
......
......@@ -53,7 +53,7 @@ public function setUp(): void {
parent::setUp();
$php_executable_finder = new PhpExecutableFinder();
$this->php = $php_executable_finder->find();
$this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
$this->root = dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)), 2);
chdir($this->root);
if (!is_writable("{$this->root}/sites/simpletest")) {
$this->markTestSkipped('This test requires a writable sites/simpletest directory');
......
......@@ -40,7 +40,7 @@ protected function setUp(): void {
$this->additionalClassloader->register();
// Mock the container so we don't need to mock drupal_valid_test_ua().
// @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
$this->root = dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))));
$this->root = dirname(__DIR__, 6);
$container = $this->createMock(ContainerInterface::class);
$container->expects($this->any())
->method('has')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment