Class ArcanistPhutilTestCase
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()
Construct a new test case. This method is final, use willRunTests() to
provide test-wide setup logic.
final private assertCoverageAvailable()
This method is not documented.
final protected void assertEqual($expect, $result, $message = null)
| parameters | wild | $expect | The theoretically expected value, generated by careful reasoning about the properties of the system. |
| wild | $result | The empirically derived value, generated by executing the test. |
| string | $message | A human-readable description of what these values represent, and particularly of what a discrepancy means. |
| return | void | | |
Assert that two values are equal. The test fails if they are not.
final protected void assertException($expected_exception_class, $callable)
| parameters | exception | $expected_exception_class | The expected exception. |
| callable | $callable | The thing which throws the exception. |
| return | void | | |
This simplest way to assert exceptions are thrown.
final protected void assertFailure($message)
| parameters | string | $message | Human-readable description of the reason for test failure. |
| return | void | | |
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)
| parameters | string | $message | Reason for skipping this test. |
| return | void | | |
End this test by asserting that the test should be skipped for some
reason.
final private beginCoverage()
This method is not documented.
protected void didRunOneTest($test_method_name)
| parameters | string | $test_method_name | Method name of the test which was invoked. |
| return | void | | |
This hook is invoked once per test, after the test method is invoked.
public void didRunTestCases(array $test_cases)
| parameters | list<ArcanistPhutilTestCase> | $test_cases | List of test cases that ran. |
| return | void | | |
This hook is invoked once, after all test cases execute.
protected void didRunTests()
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()
This method is not documented.
final private void failTest($reason)
| parameters | string | $reason | Human-readable description of problems. |
| return | void | | |
Mark the currently-running test as a failure.
protected getLink($method)
| parameters | wild | $method | |
| return | wild | | |
This method is not documented.
final private void passTest($reason)
| parameters | string | $reason | Human-readable overstatement of satisfaction. |
| return | void | | |
This was a triumph. I'm making a note here: HUGE SUCCESS.
final private resultTest($test_result, $reason)
| parameters | wild | $test_result | |
| wild | $reason | |
| return | wild | | |
This method is not documented.
final public void run()
Execute the tests in this test case. You should not call this directly;
use PhutilUnitTestEngine to orchestrate test execution.
final public setEnableCoverage($enable_coverage)
| parameters | wild | $enable_coverage | |
| return | wild | | |
This method is not documented.
final public setPaths(array $paths)
| parameters | array | $paths | |
| return | wild | | |
This method is not documented.
final public setProjectRoot($project_root)
| parameters | wild | $project_root | |
| return | wild | | |
This method is not documented.
public setRenderer(ArcanistUnitRenderer $renderer)
| parameters | ArcanistUnitRenderer | $renderer | |
| return | wild | | |
This method is not documented.
final private void skipTest($reason)
| parameters | string | $reason | Description for why this test was skipped. |
| return | void | | |
Mark the current running test as skipped.
final protected void tryTestCaseMap(array $map, $callable, $exception_class = 'Exception')
| parameters | map | $map | Map of scalar test inputs to expected success (true expects success, false expects an exception). |
| callable | $callable | Callback to invoke for each test case. |
| string | $exception_class | Optional exception class to catch, defaults to 'Exception'. |
| return | void | | |
Convenience wrapper around tryTestCases() for cases where your
inputs are scalar. For example:
For cases where your inputs are not scalar, use tryTestCases().
final protected void tryTestCases(array $inputs, array $expect, $callable, $exception_class = 'Exception')
| parameters | map | $inputs | Map of test case labels to test case inputs. |
| list | $expect | List 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 | $callable | Callback to invoke for each test case. |
| string | $exception_class | Optional exception class to catch, defaults to 'Exception'. |
| return | void | | |
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:
protected void willRunOneTest($test_method_name)
| parameters | string | $test_method_name | Method name of the test which will be invoked. |
| return | void | | |
This hook is invoked once per test, before the test method is invoked.
public void willRunTestCases(array $test_cases)
| parameters | list<ArcanistPhutilTestCase> | $test_cases | List of test cases to be run. |
| return | void | | |
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()
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.