You are here

public function TestBaseTest::testAssert in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/tests/src/Unit/TestBaseTest.php \Drupal\Tests\simpletest\Unit\TestBaseTest::testAssert()

@covers ::assert @dataProvider providerAssert

File

core/modules/simpletest/tests/src/Unit/TestBaseTest.php, line 174
Contains \Drupal\Tests\simpletest\Unit\TestBaseTest.

Class

TestBaseTest
@coversDefaultClass \Drupal\simpletest\TestBase @group simpletest

Namespace

Drupal\Tests\simpletest\Unit

Code

public function testAssert($expected, $assertion_status, $status, $message, $group, $caller) {
  $test_id = 'luke_i_am_your_' . $assertion_status;
  $test_base = $this
    ->getTestBaseForAssertionTests($test_id);

  // Verify some startup values.
  $this
    ->assertAttributeEmpty('assertions', $test_base);
  if (is_string($status)) {
    $this
      ->assertEquals(0, $test_base->results['#' . $status]);
  }

  // assert() is protected so we have to make it accessible.
  $ref_assert = new \ReflectionMethod($test_base, 'assert');
  $ref_assert
    ->setAccessible(TRUE);

  // Call assert() from within our hall of mirrors.
  $this
    ->assertEquals($expected, $ref_assert
    ->invokeArgs($test_base, array(
    $status,
    $message,
    $group,
    $caller,
  )));

  // Check the side-effects of assert().
  if (is_string($status)) {
    $this
      ->assertEquals(1, $test_base->results['#' . $status]);
  }
  $this
    ->assertAttributeNotEmpty('assertions', $test_base);

  // Make a ReflectionProperty for the assertions property,
  // since it's protected.
  $ref_assertions = new \ReflectionProperty($test_base, 'assertions');
  $ref_assertions
    ->setAccessible(TRUE);
  $assertions = $ref_assertions
    ->getValue($test_base);
  $assertion = reset($assertions);
  $this
    ->assertEquals($assertion_status, $assertion['status']);
  $this
    ->assertEquals($test_id, $assertion['test_id']);
  $this
    ->assertEquals(get_class($test_base), $assertion['test_class']);
  $this
    ->assertEquals($message, $assertion['message']);
  $this
    ->assertEquals($group, $assertion['message_group']);
}