function TestRunTest::testCreateAndGet

Tests create and get.

@legacy-covers ::createNew @legacy-covers ::get @legacy-covers ::id @legacy-covers ::insertLogEntry @legacy-covers ::setDatabasePrefix @legacy-covers ::getDatabasePrefix @legacy-covers ::getTestClass

File

core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php, line 61

Class

TestRunTest
Tests Drupal\Core\Test\TestRun.

Namespace

Drupal\KernelTests\Core\Test

Code

public function testCreateAndGet() : void {
  // Test ::createNew.
  $test_run = TestRun::createNew($this->testRunResultsStorage);
  $this->assertEquals(1, $test_run->id());
  $this->assertEquals(0, $this->connection
    ->select('simpletest')
    ->countQuery()
    ->execute()
    ->fetchField());
  $this->assertEquals(1, $this->connection
    ->select('simpletest_test_id')
    ->countQuery()
    ->execute()
    ->fetchField());
  $test_run->setDatabasePrefix('oddity1234');
  $this->assertEquals('oddity1234', $test_run->getDatabasePrefix());
  $this->assertEquals('oddity1234', $this->connection
    ->select('simpletest_test_id', 's')
    ->fields('s', [
    'last_prefix',
  ])
    ->execute()
    ->fetchField());
  $this->assertEquals(1, $test_run->insertLogEntry($this->getTestLogEntry('Test\\GroundControl')));
  $this->assertEquals('oddity1234', $test_run->getDatabasePrefix());
  $this->assertEquals('Test\\GroundControl', $test_run->getTestClass());
  $this->assertEquals(1, $this->connection
    ->select('simpletest')
    ->countQuery()
    ->execute()
    ->fetchField());
  $this->assertEquals(1, $this->connection
    ->select('simpletest_test_id')
    ->countQuery()
    ->execute()
    ->fetchField());
  // Explicitly void the $test_run variable.
  $test_run = NULL;
  // Test ::get.
  $test_run = TestRun::get($this->testRunResultsStorage, 1);
  $this->assertEquals(1, $test_run->id());
  $this->assertEquals('oddity1234', $test_run->getDatabasePrefix());
  $this->assertEquals('Test\\GroundControl', $test_run->getTestClass());
}

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