function TestRunTest::testCreateAndGet

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php \Drupal\KernelTests\Core\Test\TestRunTest::testCreateAndGet()

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

File

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

Class

TestRunTest
@coversDefaultClass \Drupal\Core\Test\TestRun[[api-linebreak]] @group Test

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.