chdir example

    'config_test.dynamic.system',
  ];

  /** * {@inheritdoc} */
  public static function setUpBeforeClass(): void {
    parent::setUpBeforeClass();
    VarDumper::setHandler(TestVarDumper::class D '::cliHandler');

    // Change the current dir to DRUPAL_ROOT.     chdir(static::getDrupalRoot());
  }

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Allow tests to compare MarkupInterface objects via assertEquals().     $this->registerComparator(new MarkupInterfaceComparator());

    

  protected function prepareEnvironment() {
    // Bootstrap Drupal so we can use Drupal's built in functions.     $this->classLoader = require __DIR__ . '/../../../../../autoload.php';
    $request = Request::createFromGlobals();
    $kernel = TestRunnerKernel::createFromRequest($request$this->classLoader);
    // TestRunnerKernel expects the working directory to be DRUPAL_ROOT.     chdir(DRUPAL_ROOT);
    $kernel->boot();
    $kernel->preHandle($request);
    $this->prepareDatabasePrefix();

    $this->originalSite = $kernel->findSitePath($request);

    // Create test directory ahead of installation so fatal errors and debug     // information can be logged during installation process.     \Drupal::service('file_system')->prepareDirectory($this->siteDirectory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);

    // Prepare filesystem directory paths.


    abstract protected function getGuesser(): MimeTypeGuesserInterface;

    public function testGuessWithLeadingDash()
    {
        if (!$this->getGuesser()->isGuesserSupported()) {
            $this->markTestSkipped('Guesser is not supported');
        }

        $cwd = getcwd();
        chdir(__DIR__.'/Fixtures/mimetypes');
        try {
            $this->assertEquals('image/gif', $this->getGuesser()->guessMimeType('-test'));
        } finally {
            chdir($cwd);
        }
    }

    public function testGuessImageWithoutExtension()
    {
        if (!$this->getGuesser()->isGuesserSupported()) {
            $this->markTestSkipped('Guesser is not supported');
        }
->addUsage('custom_theme --name "Custom Theme" --description "Custom theme generated from a starterkit theme" --path themes')
      ->addUsage('custom_theme --name "Custom Theme" --starterkit mystarterkit');
  }

  /** * {@inheritdoc} */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    $io = new SymfonyStyle($input$output);

    // Change the directory to the Drupal root.     chdir($this->root);

    // Path where the generated theme should be placed.     $destination_theme = $input->getArgument('machine-name');
    $default_destination = 'themes';
    $destination = trim($input->getOption('path') ?: $default_destination, '/') . '/' . $destination_theme;

    if (is_dir($destination)) {
      $io->getErrorStyle()->error("Theme could not be generated because the destination directory $destination exists already.");
      return 1;
    }

    
$newResource = unserialize(serialize($resource));

        $p = new \ReflectionProperty($resource, 'globBrace');

        $this->assertEquals($p->getValue($resource)$p->getValue($newResource));
    }

    public function testPhar()
    {
        $s = \DIRECTORY_SEPARATOR;
        $cwd = getcwd();
        chdir(\dirname(__DIR__).'/Fixtures');
        try {
            $resource = new GlobResource('phar://some.phar', '*', true);
            $files = array_keys(iterator_to_array($resource));
            $this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", "phar://some.phar{$s}schema{$s}project-1.0.xsd"]$files);

            $resource = new GlobResource("phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php", '', true);
            $files = array_keys(iterator_to_array($resource));
            $this->assertSame(["phar://some.phar{$s}ProjectWithXsdExtensionInPhar.php"]$files);
        } finally {
            chdir($cwd);
        }
    }
if (isset(self::$darwinCache[$real])) {
            $kDir = $real;
        } else {
            $kDir = strtolower($real);

            if (isset(self::$darwinCache[$kDir])) {
                $real = self::$darwinCache[$kDir][0];
            } else {
                $dir = getcwd();

                if (!@chdir($real)) {
                    return $real.$file;
                }

                $real = getcwd().'/';
                chdir($dir);

                $dir = $real;
                $k = $kDir;
                $i = \strlen($dir) - 1;
                while (!isset(self::$darwinCache[$k])) {
                    self::$darwinCache[$k] = [$dir[]];
                    
->addUsage('--install-profile demo_umami --langcode fr')
      ->addUsage('--base-url "http://example.com" --db-url "mysql://username:password@localhost/databasename#table_prefix"');
  }

  /** * {@inheritdoc} */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    // Determines and validates the setup class prior to installing a database     // to avoid creating unnecessary sites.     $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.     $this->ensureDirectory($root);

    $db_url = $input->getOption('db-url');
    $base_url = $input->getOption('base-url');
    putenv("SIMPLETEST_DB=$db_url");
    putenv("SIMPLETEST_BASE_URL=$base_url");

    // Manage site fixture.     $this->setup($input->getOption('install-profile')$class_name$input->getOption('langcode'));

    
PHP_VERSION
    );

    exit($message);
}

// Path to the front controller (this file) define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR);

// Ensure the current directory is pointing to the front controller's directory if (getcwd() . DIRECTORY_SEPARATOR !== FCPATH) {
    chdir(FCPATH);
}

/* *--------------------------------------------------------------- * BOOTSTRAP THE APPLICATION *--------------------------------------------------------------- * This process sets up the path constants, loads and registers * our autoloader, along with Composer's, loads our constants * and fires up an environment-specific bootstrapping. */

<?php
/** * @file * Initiates a browser-based installation of Drupal. */

use Drupal\Component\Utility\OpCodeCache;

// Change the directory to the Drupal root. chdir('..');
// Store the Drupal root path. $root_path = realpath('');

/** * Global flag to indicate the site is in installation mode. * * The constant is defined using define() instead of const so that PHP * versions prior to 5.3 can display proper PHP requirements instead of causing * a fatal error. */
define('MAINTENANCE_MODE', 'install');

/** * {@inheritdoc} */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    $io = new SymfonyStyle($input$output);
    if (!extension_loaded('pdo_sqlite')) {
      $io->getErrorStyle()->error('You must have the pdo_sqlite PHP extension installed. See core/INSTALL.sqlite.txt for instructions.');
      return 1;
    }

    // Change the directory to the Drupal root.     chdir(dirname(__DIR__, 5));

    // Check whether there is already an installation.     if ($this->isDrupalInstalled()) {
      // Do not fail if the site is already installed so this command can be       // chained with ServerCommand.       $output->writeln('<info>Drupal is already installed.</info> If you want to reinstall, remove sites/default/files and sites/default/settings.php.');
      return 0;
    }

    $install_profile = $input->getArgument('install-profile');
    if ($install_profile && !$this->validateProfile($install_profile$io)) {
      
->addArgument('uid', InputArgument::REQUIRED, 'The ID of the user for whom the link will be generated')
      ->addOption('site-path', NULL, InputOption::VALUE_REQUIRED, 'The path for the test site.');
  }

  /** * {@inheritdoc} * * @throws \Symfony\Component\Console\Exception\InvalidArgumentException */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    $root = dirname(__DIR__, 5);
    chdir($root);

    $this->classLoader = require 'autoload.php';
    $kernel = new DrupalKernel('prod', $this->classLoader, FALSE);
    $kernel::bootEnvironment();
    $kernel->setSitePath($input->getOption('site-path'));
    Settings::initialize($kernel->getAppRoot()$kernel->getSitePath()$this->classLoader);

    $request = Request::createFromGlobals();

    $kernel->boot();
    $kernel->preHandle($request);

    
use Drupal\Core\DrupalKernel;
use Drupal\Core\Form\EnforcedResponseException;
use Drupal\Core\Url;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\Site\Settings;
use Drupal\Core\Routing\RouteObjectInterface;
use Symfony\Component\Routing\Route;

// Change the directory to the Drupal root. chdir('..');

$autoloader = require_once 'autoload.php';

/** * Global flag to identify update.php and authorize.php runs. * * Identifies update.php and authorize.php runs, avoiding unwanted operations * such as css/js preprocessing and translation, and solves some theming issues. * The flag is checked in other places in Drupal code (not just authorize.php). */
const MAINTENANCE_MODE = 'update';


function centered(string $text)
{
    $padding = (int) ((LINE_WIDTH - strlen($text)) / 2);

    return str_repeat(' ', $padding).$text;
}

function cd(string $dir): void
{
    if (false === chdir($dir)) {
        bailout("Could not switch to directory $dir.");
    }
}

function run(string $command): void
{
    exec($command$output$status);

    if (0 !== $status) {
        $output = implode("\n", $output);
        echo "Error while running:\n ".getcwd().'$ '.$command."\nOutput:\n".LINE."$output\n".LINE;

        
$prevCacheDir = false;
    }
}
$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : ''));
$SYMFONY_PHPUNIT_REQUIRE = $getEnvVar('SYMFONY_PHPUNIT_REQUIRE', '');
$configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__)$SYMFONY_PHPUNIT_REMOVE$SYMFONY_PHPUNIT_REQUIRE(int) $PHPUNIT_REMOVE_RETURN_TYPEHINT]));
$PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION$PHPUNIT_REMOVE_RETURN_TYPEHINT);
if (!file_exists("$PHPUNIT_DIR/$PHPUNIT_VERSION_DIR/phpunit") || $configurationHash !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION_DIR.md5")) {
    // Build a standalone phpunit without symfony/yaml nor prophecy by default
    @mkdir($PHPUNIT_DIR, 0777, true);
    chdir($PHPUNIT_DIR);
    if (file_exists("$PHPUNIT_VERSION_DIR")) {
        passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s 2> NUL' : 'rm -rf %s', escapeshellarg("$PHPUNIT_VERSION_DIR.old")));
        rename("$PHPUNIT_VERSION_DIR", "$PHPUNIT_VERSION_DIR.old");
        passthru(sprintf('\\' === \DIRECTORY_SEPARATOR ? 'rmdir /S /Q %s' : 'rm -rf %s', escapeshellarg("$PHPUNIT_VERSION_DIR.old")));
    }

    $info = [];
    foreach (explode("\n", `$COMPOSER info --no-ansi -a -n phpunit/phpunit "$PHPUNIT_VERSION.*"`) as $line) {
        $line = rtrim($line);

        if (!$info && preg_match('/^versions +: /', $line)) {
            

  protected $root;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $php_executable_finder = new PhpExecutableFinder();
    $this->php = $php_executable_finder->find();
    $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');
    }
    // Get a lock and a valid site path.     $this->testDb = new TestDatabase();
  }

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