function TestRunTest::testCreateAndRemove

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

Tests create and remove.

@legacy-covers ::createNew @legacy-covers ::id @legacy-covers ::insertLogEntry @legacy-covers ::setDatabasePrefix

File

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

Class

TestRunTest
Tests Drupal\Core\Test\TestRun.

Namespace

Drupal\KernelTests\Core\Test

Code

public function testCreateAndRemove() : void {
  $test_run_1 = TestRun::createNew($this->testRunResultsStorage);
  $test_run_1->setDatabasePrefix('oddity1234');
  $test_run_1->insertLogEntry($this->getTestLogEntry('Test\\GroundControl'));
  $this->assertEquals(1, $test_run_1->id());
  $this->assertEquals(1, $this->connection
    ->select('simpletest')
    ->countQuery()
    ->execute()
    ->fetchField());
  $this->assertEquals(1, $this->connection
    ->select('simpletest_test_id')
    ->countQuery()
    ->execute()
    ->fetchField());
  $test_run_2 = TestRun::createNew($this->testRunResultsStorage);
  $test_run_2->setDatabasePrefix('oddity5678');
  $test_run_2->insertLogEntry($this->getTestLogEntry('Test\\PlanetEarth'));
  $this->assertEquals(2, $test_run_2->id());
  $this->assertEquals(2, $this->connection
    ->select('simpletest')
    ->countQuery()
    ->execute()
    ->fetchField());
  $this->assertEquals(2, $this->connection
    ->select('simpletest_test_id')
    ->countQuery()
    ->execute()
    ->fetchField());
  $this->assertEquals(1, $test_run_1->removeResults());
  $this->assertEquals(1, $this->connection
    ->select('simpletest')
    ->countQuery()
    ->execute()
    ->fetchField());
  $this->assertEquals(1, $this->connection
    ->select('simpletest_test_id')
    ->countQuery()
    ->execute()
    ->fetchField());
}

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