You are here

protected function TestBase::assert in SimpleTest 8.3

Internal helper: stores the assert.

Parameters

$status: Can be 'pass', 'fail', 'exception', 'debug'. TRUE is a synonym for 'pass', FALSE for 'fail'.

string|\Drupal\Component\Render\MarkupInterface $message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Render\FormattableMarkup to embed variables in the message text, not t(). If left blank, a default message will be displayed.

$group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Other'; most tests do not override this default.

$caller: By default, the assert comes from a function whose name starts with 'test'. Instead, you can specify where this assert originates from by passing in an associative array as $caller. Key 'file' is the name of the source file, 'line' is the line number and 'function' is the caller function itself.

13 calls to TestBase::assert()
TestBase::assertEqual in src/TestBase.php
Check to see if two values are equal.
TestBase::assertFalse in src/TestBase.php
Check to see if a value is false.
TestBase::assertIdentical in src/TestBase.php
Check to see if two values are identical.
TestBase::assertNotEqual in src/TestBase.php
Check to see if two values are not equal.
TestBase::assertNotIdentical in src/TestBase.php
Check to see if two values are not identical.

... See full list

File

src/TestBase.php, line 328

Class

TestBase
Base class for Drupal tests.

Namespace

Drupal\simpletest

Code

protected function assert($status, $message = '', $group = 'Other', array $caller = NULL) {
  if ($message instanceof MarkupInterface) {
    $message = (string) $message;
  }

  // Convert boolean status to string status.
  if (is_bool($status)) {
    $status = $status ? 'pass' : 'fail';
  }

  // Increment summary result counter.
  $this->results['#' . $status]++;

  // Get the function information about the call to the assertion method.
  if (!$caller) {
    $caller = $this
      ->getAssertionCall();
  }

  // Creation assertion array that can be displayed while tests are running.
  $assertion = [
    'test_id' => $this->testId,
    'test_class' => get_class($this),
    'status' => $status,
    'message' => $message,
    'message_group' => $group,
    'function' => $caller['function'],
    'line' => $caller['line'],
    'file' => $caller['file'],
  ];

  // Store assertion for display after the test has completed.
  $message_id = $this
    ->storeAssertion($assertion);
  $assertion['message_id'] = $message_id;
  $this->assertions[] = $assertion;

  // We do not use a ternary operator here to allow a breakpoint on
  // test failure.
  if ($status == 'pass') {
    return TRUE;
  }
  else {
    if ($this->dieOnFail && ($status == 'fail' || $status == 'exception')) {
      exit(1);
    }
    return FALSE;
  }
}