function TestBaseTest::testAssert

@covers ::assert
@dataProvider providerAssert

File

core/modules/simpletest/tests/src/Unit/TestBaseTest.php, line 171

Class

TestBaseTest
@requires extension curl @coversDefaultClass \Drupal\simpletest\TestBase[[api-linebreak]] @group simpletest @group TestBase

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, [
    $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']);
}

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