function SimpleTestTest::setUp

Overrides WebTestBase::setUp

File

core/modules/simpletest/src/Tests/SimpleTestTest.php, line 69

Class

SimpleTestTest
Tests SimpleTest's web interface: check that the intended tests were run and ensure that test reports display the intended results. Also test SimpleTest's internal browser and APIs implicitly.

Namespace

Drupal\simpletest\Tests

Code

protected function setUp() {
    if (!$this->isInChildSite()) {
        $php = <<<'EOD'
<?php

# Make sure that the $test_class variable is defined when this file is included.
if ($test_class) {
}

# Define a function to be able to check that this file was loaded with
# function_exists().
if (!function_exists('simpletest_test_stub_settings_function')) {
  function simpletest_test_stub_settings_function() {}
}
EOD;
        file_put_contents($this->siteDirectory . '/' . 'settings.testing.php', $php);
        // @see \Drupal\system\Tests\DrupalKernel\DrupalKernelSiteTest
        $class = __CLASS__;
        $yaml = <<<EOD
services:
  # Add a new service.
  site.service.yml:
    class: {<span class="php-variable">$class</span>}
  # Swap out a core service.
  cache.backend.database:
    class: Drupal\\Core\\Cache\\MemoryBackendFactory
EOD;
        file_put_contents($this->siteDirectory . '/testing.services.yml', $yaml);
        $original_container = $this->originalContainer;
        parent::setUp();
        $this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'WebTestBase test creates a new container.');
        // Create and log in an admin user.
        $this->drupalLogin($this->drupalCreateUser([
            'administer unit tests',
        ]));
    }
    else {
        // This causes three of the five fails that are asserted in
        // confirmStubResults().
        self::$modules = [
            'non_existent_module',
        ];
        parent::setUp();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.