insertLogEntry example

/** * Adds a test log entry. * * @param array $entry * The array of the log entry elements. * * @return bool * TRUE if the addition was successful, FALSE otherwise. */
  public function insertLogEntry(array $entry): bool {
    $this->testClass = $entry['test_class'];
    return $this->testRunResultsStorage->insertLogEntry($this$entry);
  }

  /** * Get test results for a test run, ordered by test class. * * @return array * Array of results ordered by test class and message id. */
  public function getLogEntriesByTestClass(): array {
    return $this->testRunResultsStorage->getLogEntriesByTestClass($this);
  }

  
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());
    

  public function testBuildEnvironmentKeepingExistingResults(): void {
    $schema = $this->connection->schema();

    // Initial build of the environment.     $this->testRunResultsStorage->buildTestingResultsEnvironment(FALSE);

    $this->assertEquals(1, $this->testRunResultsStorage->createNew());
    $test_run = TestRun::get($this->testRunResultsStorage, 1);
    $this->assertEquals(1, $this->testRunResultsStorage->insertLogEntry($test_run$this->getTestLogEntry('Test\GroundControl')));
    $this->assertEquals(1, $this->connection->select('simpletest')->countQuery()->execute()->fetchField());
    $this->assertEquals(1, $this->connection->select('simpletest_test_id')->countQuery()->execute()->fetchField());

    // Build the environment again, keeping results. Results should be kept.     $this->testRunResultsStorage->buildTestingResultsEnvironment(TRUE);
    $this->assertTrue($schema->tableExists('simpletest'));
    $this->assertTrue($schema->tableExists('simpletest_test_id'));
    $this->assertTrue($this->testRunResultsStorage->validateTestingResultsEnvironment());
    $this->assertEquals(1, $this->connection->select('simpletest')->countQuery()->execute()->fetchField());
    $this->assertEquals(1, $this->connection->select('simpletest_test_id')->countQuery()->execute()->fetchField());

    

  public function processPhpUnitResults(TestRun $test_run, array $phpunit_results): void {
    foreach ($phpunit_results as $result) {
      $test_run->insertLogEntry($result);
    }
  }

  /** * Tallies test results per test class. * * @param string[][] $results * Array of results in the {simpletest} schema. Can be the return value of * PhpUnitTestRunner::execute(). * * @return int[][] * Array of status tallies, keyed by test class name and status type. * * @internal */
Home | Imprint | This part of the site doesn't use cookies.