Diviner

Class ArcanistPhutilTestCase

Definedsrc/unit/engine/phutil/ArcanistPhutilTestCase.php:13
GroupUnit Test Runners

Base test case for the very simple libphutil test framework.

Tasks

Making Test Assertions

Exception Handling

Hooks for Setup and Teardown

Internals

Unspecified

Methods

final public this __construct()

returnthis

Construct a new test case. This method is final, use willRunTests() to provide test-wide setup logic.

final private assertCoverageAvailable()

returnwild
This method is not documented.

final protected void assertEqual($expect, $result, $message = null)

parameterswild$expectThe theoretically expected value, generated by careful reasoning about the properties of the system.
wild$resultThe empirically derived value, generated by executing the test.
string$messageA human-readable description of what these values represent, and particularly of what a discrepancy means.
returnvoid

Assert that two values are equal. The test fails if they are not.

NOTE: This method uses PHP's strict equality test operator ("===") to compare values. This means values and types must be equal, key order must be identical in arrays, and objects must be referentially identical.

final protected void assertException($expected_exception_class, $callable)

parametersexception$expected_exception_classThe expected exception.
callable$callableThe thing which throws the exception.
returnvoid

This simplest way to assert exceptions are thrown.

final protected void assertFailure($message)

parametersstring$messageHuman-readable description of the reason for test failure.
returnvoid

Assert an unconditional failure. This is just a convenience method that better indicates intent than using dummy values with assertEqual(). This causes test failure.

final protected void assertSkipped($message)

parametersstring$messageReason for skipping this test.
returnvoid

End this test by asserting that the test should be skipped for some reason.

final private beginCoverage()

returnwild
This method is not documented.

protected void didRunOneTest($test_method_name)

parametersstring$test_method_nameMethod name of the test which was invoked.
returnvoid

This hook is invoked once per test, after the test method is invoked.

public void didRunTestCases(array $test_cases)

parameterslist<ArcanistPhutilTestCase>$test_casesList of test cases that ran.
returnvoid

This hook is invoked once, after all test cases execute.

protected void didRunTests()

returnvoid

This hook is invoked once, after any tests in this class are run. It gives you an opportunity to perform teardown steps for the entire class.

final private endCoverage()

returnwild
This method is not documented.

final private void failTest($reason)

parametersstring$reasonHuman-readable description of problems.
returnvoid

Mark the currently-running test as a failure.

protected getLink($method)

parameterswild$method
returnwild
This method is not documented.

final private void passTest($reason)

parametersstring$reasonHuman-readable overstatement of satisfaction.
returnvoid

This was a triumph. I'm making a note here: HUGE SUCCESS.

final private resultTest($test_result, $reason)

parameterswild$test_result
wild$reason
returnwild
This method is not documented.

final public void run()

returnvoid

Execute the tests in this test case. You should not call this directly; use PhutilUnitTestEngine to orchestrate test execution.

final public setEnableCoverage($enable_coverage)

parameterswild$enable_coverage
returnwild
This method is not documented.

final public setPaths(array $paths)

parametersarray$paths
returnwild
This method is not documented.

final public setProjectRoot($project_root)

parameterswild$project_root
returnwild
This method is not documented.

public setRenderer(ArcanistUnitRenderer $renderer)

parametersArcanistUnitRenderer$renderer
returnwild
This method is not documented.

final private void skipTest($reason)

parametersstring$reasonDescription for why this test was skipped.
returnvoid

Mark the current running test as skipped.

final protected void tryTestCaseMap(array $map, $callable, $exception_class = 'Exception')

parametersmap$mapMap of scalar test inputs to expected success (true expects success, false expects an exception).
callable$callableCallback to invoke for each test case.
string$exception_classOptional exception class to catch, defaults to 'Exception'.
returnvoid

Convenience wrapper around tryTestCases() for cases where your inputs are scalar. For example:

public function testFruit() {
  $this->tryTestCaseMap(
    array(
      'apple' => true,
      'rock'  => false,
    ),
    array($this, 'tryIsAFruit'),
    'NotAFruitException');
}

protected function tryIsAFruit($input) {
  is_a_fruit($input);
}

For cases where your inputs are not scalar, use tryTestCases().

final protected void tryTestCases(array $inputs, array $expect, $callable, $exception_class = 'Exception')

parametersmap$inputsMap of test case labels to test case inputs.
list$expectList of expected results, true to indicate that the case is expected to succeed and false to indicate that the case is expected to throw.
callable$callableCallback to invoke for each test case.
string$exception_classOptional exception class to catch, defaults to 'Exception'.
returnvoid

Straightforward method for writing unit tests which check if some block of code throws an exception. For example, this allows you to test the exception behavior of is_a_fruit() on various inputs:

public function testFruit() {
  $this->tryTestCases(
    array(
      'apple is a fruit'    => new Apple(),
      'rock is not a fruit' => new Rock(),
    ),
    array(
      true,
      false,
    ),
    array($this, 'tryIsAFruit'),
    'NotAFruitException');
}

protected function tryIsAFruit($input) {
  is_a_fruit($input);
}

protected void willRunOneTest($test_method_name)

parametersstring$test_method_nameMethod name of the test which will be invoked.
returnvoid

This hook is invoked once per test, before the test method is invoked.

public void willRunTestCases(array $test_cases)

parameterslist<ArcanistPhutilTestCase>$test_casesList of test cases to be run.
returnvoid

This hook is invoked once, before any test cases execute. It gives you an opportunity to perform setup steps for the entire suite of test cases.

protected void willRunTests()

returnvoid

This hook is invoked once, before any tests in this class are run. It gives you an opportunity to perform setup steps for the entire class.