PHP Класс lithium\test\Unit

Unit tests are used to check a small unit of functionality, such as if a method returns an expected result for a known input, or whether an adapter can successfully open a connection. Available assertions are (see assert methods for details): Equal, False, Identical, NoPattern, NotEqual, Null, Pattern, Tags, True. If an assertion is expected to produce an exception, the expectException method should be called before it.
Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_expected string The list of expected exceptions.
$_internalTypes array Internal types and how to test for them
$_reporter string The Reference to a test reporter class.
$_results string The list of test results.

Открытые методы

Метод Описание
assert ( boolean $expression, string | boolean $message = false, array $data = [] ) : boolean General assert method used by others for common output.
assertArrayHasKey ( $key, array $array, string | boolean $message = '{:message}' ) : boolean Assert that the result array has given key.
assertArrayNotHasKey ( $key, array $array, string | boolean $message = '{:message}' ) : boolean Assert that the result array does *not* have given key.
assertClassHasAttribute ( mixed $attributeName, string $class, string | boolean $message = '{:message}' ) : boolean Assert that a class has a given attribute.
assertClassHasStaticAttribute ( mixed $attributeName, string $class, string | boolean $message = '{:message}' ) : boolean Assert that a class does have a given _static_ attribute.
assertClassNotHasAttribute ( mixed $attributeName, string $class, string | boolean $message = '{:message}' ) : boolean Assert that a class does *not* have a given attribute.
assertClassNotHasStaticAttribute ( $attrName, string $class, string | boolean $message = '{:message}' ) : boolean Assert that a class does *not* have a given _static_ attribute.
assertContains ( string $needle, mixed $haystack, string | boolean $message = '{:message}' ) : boolean Assert that $haystack contains $needle as a value.
assertContainsOnly ( string $type, array | object $haystack, string | boolean $message = '{:message}' ) : boolean Assert that $haystack does only contain item of given type.
assertContainsOnlyInstancesOf ( string $class, array | object $haystack, string | boolean $message = '{:message}' ) : boolean Assert that $haystack contains only instances of given class.
assertCookie ( array $expected, array $headers = null ) : boolean Assert Cookie data is properly set in headers.
assertCount ( integer $expected, array $array, string | boolean $message = '{:message}' ) : boolean Assert that the passed result array has expected number of elements.
assertEmpty ( string $actual, string | boolean $message = '{:message}' ) : boolean Assert that given result is empty.
assertEqual ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean Assert that the actual result is equal, but not neccessarily identical, to the expected result.
assertException ( mixed $expected, Closure $closure, string $message = '{:message}' ) : boolean Assert that the code passed in a closure throws an exception or raises a PHP error. The first argument to this method specifies which class name or message the exception must have in order to make the assertion successful.
assertFalse ( mixed $result, string $message = '{:message}' ) : boolean Assert that the result strictly is false.
assertFileEquals ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean Assert that the file contents of $expected are equal to the contents of $actual.
assertFileExists ( string $actual, string | boolean $message = '{:message}' ) : boolean Assert that a file exists.
assertFileNotEquals ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean Assert that the file contents of $expected are *not* equal to the contents of $actual.
assertFileNotExists ( string $actual, string | boolean $message = '{:message}' ) : boolean Assert that a file does *not* exist.
assertGreaterThan ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean Assert that $expected is greater than $actual.
assertGreaterThanOrEqual ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean Assert that $expected is greater than or equal to $actual.
assertIdentical ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean Assert that the actual result and the expected result are identical using a strict comparison.
assertInstanceOf ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean Assert that $actual is an instance of $expected.
assertInternalType ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean Assert that $actual is of given type.
assertLessThan ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean Assert that $expected is less than $actual.
assertLessThanOrEqual ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean Assert that $expected is less than or equal to $actual.
assertNoCookie ( array $expected, array $headers = null ) : boolean Assert Cookie data is *not* set in headers.
assertNotContains ( string $needle, miexed $haystack, string | boolean $message = '{:message}' ) : boolean Assert that $haystack does *not* contain $needle as a value.
assertNotContainsOnly ( string $type, array | object $haystack, string | boolean $message = '{:message}' ) : boolean Assert that $haystack hasn't any items of given type.
assertNotCount ( integer $expected, array $array, string | boolean $message = '{:message}' ) : boolean Assert that the passed result array has *not* the expected number of elements.
assertNotEmpty ( string $actual, string | boolean $message = '{:message}' ) : boolean Assert that given result is *not* empty.
assertNotEqual ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean Assert that the actual result and the expected result are *not* equal to each other.
assertNotException ( mixed $expected, Closure $closure, string $message = '{:message}' ) : boolean Assert that the code passed in a closure does not throw an exception matching the passed expected exception.
assertNotIdentical ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean Assert that the actual result and the expected result are *not* identical using a strict comparison.
assertNotInstanceOf ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean Assert that $actual is *not* an instance of $expected.
assertNotInternalType ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean Assert that $actual is *not* of given type.
assertNotNull ( $actual, string $message = '{:message}' ) : boolean Assert that the result is *not* strictly null.
assertNotPattern ( mixed $expected, mixed $result, string $message = '{:message}' ) : boolean Assert that the regular expression $expected is *not* matched in the result.
assertNull ( mixed $result, string $message = '{:message}' ) : boolean Assert that the result is strictly null.
assertObjectHasAttribute ( string $attributeName, string $object, string | boolean $message = '{:message}' ) : boolean Assert that $object has given attribute.
assertObjectNotHasAttribute ( string $attributeName, string $object, string | boolean $message = '{:message}' ) : boolean Assert that $object does *not* have given attribute.
assertPattern ( mixed $expected, mixed $result, string $message = '{:message}' ) : boolean Assert that the regular expression $expected is matched in the result.
assertStringEndsWith ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean Assert given result string has given suffix.
assertStringMatchesFormat ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean Assert that given value matches the sprintf format.
assertStringNotMatchesFormat ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean Assert that given value does *not* matche the sprintf format.
assertStringStartsWith ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean Assert given result string has given prefix.
assertTags ( string $string, array $expected ) : boolean Takes an array $expected and generates a regex from it to match the provided $string.
assertTrue ( mixed $result, string $message = '{:message}' ) : boolean Assert that the result is strictly true.
expectException ( mixed $message = true ) : void Used before a call to assert*() if you expect the test assertion to generate an exception or PHP error. If no error or exception is thrown, a test failure will be reported. Can be called multiple times per assertion, if more than one error is expected.
fail ( string $message = false ) Generates a failed test with the given message.
get ( string $class ) : string Finds the test case for the corresponding class name.
methods ( ) : array Return test methods to run.
results ( ) : array Returns the current results.
run ( array $options = [] ) : array Runs the test methods in this test case, with the given options.
setUp ( ) : void Setup method run before every test method. Override in subclasses.
skip ( ) Subclasses should use this method to set conditions that, if failed, terminate further testing.
skipIf ( boolean $condition, string | boolean $message = false ) : mixed Skips test(s) if the condition is met.
subject ( ) : string Returns the class name that is the subject under test for this test case.
tearDown ( ) : void Teardown method run after every test method. Override in subclasses.

Защищенные методы

Метод Описание
_arrayPermute ( array $items, array $perms = [] ) : array Generates all permutation of an array $items and returns them in a new array.
_cleanUp ( string $path = null ) : void Removes everything from resources/tmp/tests directory. Call from inside of your test method or tearDown().
_compare ( string $type, mixed $expected, mixed $result = null, string $trace = null ) : array Compare the expected with the result. If $result is null $expected equals $type and $result equals $expected.
_cookieMatch ( array $expected, array $headers ) : boolean Match an $expected cookie with the given headers. If no headers are provided, then the value of headers_list() will be used.
_handleException ( mixed $exception, integer $lineFlag = null ) : void Normalizes Exception objects and PHP error data into a single array format then the error data is logged to the test results.
_message ( array &$data = [], string $message = null ) : string Returns a basic message for the data returned from _result().
_normalizeLineEndings ( mixed $expected, mixed $result ) : array Fixes some issues regarding the used EOL character(s).
_reportException ( array $exception, string $lineFlag = null ) : void Convert an exception object to an exception result array for test reporting.
_result ( string $type, array $info, array $options = [] ) : void Reports test result messages.
_runTestMethod ( string $method, array $options ) : mixed Runs an individual test method, collecting results and catching exceptions along the way.

Описание методов

_arrayPermute() защищенный Метод

Generates all permutation of an array $items and returns them in a new array.
protected _arrayPermute ( array $items, array $perms = [] ) : array
$items array An array of items
$perms array
Результат array

_cleanUp() защищенный Метод

Uses DIRECTORY_SEPARATOR as getPathname() is used in a a direct string comparison. The method may contain slashes and backslashes. If the file to unlink is readonly, it throws a exception (Permission denied) on Windows. So, the file is checked before an unlink is tried. (this will make the tests run slower but is prefered over a if (!unlink { chmod; unlink }. http://stringoftheseus.com/blog/2010/12/22/php-unlink-permisssion-denied-error-on-windows/
protected _cleanUp ( string $path = null ) : void
$path string Path to directory with contents to remove. If first character is NOT a slash (`/`) or a Windows drive letter (`C:`) prepends `Libraries::get(true, 'resources')/tmp/`.
Результат void

_compare() защищенный Метод

Compare the expected with the result. If $result is null $expected equals $type and $result equals $expected.
protected _compare ( string $type, mixed $expected, mixed $result = null, string $trace = null ) : array
$type string The type of comparison either `'identical'` or `'equal'` (default).
$expected mixed The expected value.
$result mixed An optional result value, defaults to `null`
$trace string An optional trace used internally to track arrays and objects, defaults to `null`.
Результат array Data with the keys `trace'`, `'expected'` and `'result'`.

_cookieMatch() защищенный Метод

Match an $expected cookie with the given headers. If no headers are provided, then the value of headers_list() will be used.
protected _cookieMatch ( array $expected, array $headers ) : boolean
$expected array
$headers array When empty, value of `headers_list()` will be used.
Результат boolean `true` if the assertion succeeded, `false` otherwise.

_handleException() защищенный Метод

Normalizes Exception objects and PHP error data into a single array format then the error data is logged to the test results.
См. также: lithium\test\Unit::_reportException()
protected _handleException ( mixed $exception, integer $lineFlag = null ) : void
$exception mixed An `Exception` object instance, or an array containing the following keys: `'message'`, `'file'`, `'line'`, `'trace'` (in `debug_backtrace()` format) and optionally `'code'` (error code number) and `'context'` (an array of variables relevant to the scope of where the error occurred).
$lineFlag integer A flag used for determining the relevant scope of the call stack. Set to the line number where test methods are called.
Результат void

_message() защищенный Метод

Returns a basic message for the data returned from _result().
См. также: lithium\test\Unit::assert()
См. также: lithium\test\Unit::_result()
protected _message ( array &$data = [], string $message = null ) : string
$data array The data to use for creating the message.
$message string The string prepended to the generate message in the current scope.
Результат string

_normalizeLineEndings() защищенный Метод

On linux EOL is LF, on Windows it is normally CRLF, but the latter may depend also on the git config core.autocrlf setting. As some tests use heredoc style (<<<) to specify multiline expectations, this EOL issue may cause tests to fail only because of a difference in EOL's used. in assertEqual, assertNotEqual, assertPattern and assertNotPattern this function is called to get rid of any EOL differences.
protected _normalizeLineEndings ( mixed $expected, mixed $result ) : array
$expected mixed
$result mixed
Результат array Array with the normalized elements i.e. `array($expected, $result)`.

_reportException() защищенный Метод

Convert an exception object to an exception result array for test reporting.
protected _reportException ( array $exception, string $lineFlag = null ) : void
$exception array The exception data to report on. Statistics are gathered and added to the reporting stack contained in `Unit::$_results`.
$lineFlag string
Результат void

_result() защищенный Метод

Reports test result messages.
protected _result ( string $type, array $info, array $options = [] ) : void
$type string The type of result being reported. Can be `'pass'`, `'fail'`, `'skip'` or `'exception'`.
$info array An array of information about the test result. At a minimum, this should contain a `'message'` key. Other possible keys are `'file'`, `'line'`, `'class'`, `'method'`, `'assertion'` and `'data'`.
$options array Currently unimplemented.
Результат void

_runTestMethod() защищенный Метод

Runs an individual test method, collecting results and catching exceptions along the way.
protected _runTestMethod ( string $method, array $options ) : mixed
$method string The name of the test method to run.
$options array
Результат mixed

assert() публичный Метод

General assert method used by others for common output.
public assert ( boolean $expression, string | boolean $message = false, array $data = [] ) : boolean
$expression boolean
$message string | boolean The message to output. If the message is not a string, then it will be converted to '{:message}'. Use '{:message}' in the string and it will use the `$data` to format the message with `String::insert()`.
$data array
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertArrayHasKey() публичный Метод

$this->assertArrayHasKey('bar', array('bar' => 'baz')); // succeeds $this->assertArrayHasKey('foo', array('bar' => 'baz')); // fails
См. также: lithium\test\Unit::assert()
public assertArrayHasKey ( $key, array $array, string | boolean $message = '{:message}' ) : boolean
$array array
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertArrayNotHasKey() публичный Метод

$this->assertArrayNotHasKey('foo', array('bar' => 'baz')); // succeeds $this->assertArrayNotHasKey('bar', array('bar' => 'baz')); // fails
См. также: lithium\test\Unit::assert()
public assertArrayNotHasKey ( $key, array $array, string | boolean $message = '{:message}' ) : boolean
$array array
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertClassHasAttribute() публичный Метод

$this->assertClassHasAttribute('__construct', 'ReflectionClass'); // succeeds $this->assertClassHasAttribute('name', 'ReflectionClass'); // fails
См. также: lithium\test\Unit::assert()
См. также: lithium\test\Unit::assertObjectHasAttribute()
public assertClassHasAttribute ( mixed $attributeName, string $class, string | boolean $message = '{:message}' ) : boolean
$attributeName mixed
$class string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertClassHasStaticAttribute() публичный Метод

$this->assertClassHasStaticAttribute('_methodFilters', '\lithium\core\StaticObject'); // succeeds $this->assertClassHasStaticAttribute('foobar', '\lithium\core\StaticObject'); // fails
См. также: lithium\test\Unit::assert()
public assertClassHasStaticAttribute ( mixed $attributeName, string $class, string | boolean $message = '{:message}' ) : boolean
$attributeName mixed
$class string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertClassNotHasAttribute() публичный Метод

$this->assertClassNotHasAttribute('name', 'ReflectionClass'); // succeeds $this->assertClassNotHasAttribute('__construct', 'ReflectionClass'); // fails
См. также: lithium\test\Unit::assert()
См. также: lithium\test\Unit::assertObjectHasAttribute()
public assertClassNotHasAttribute ( mixed $attributeName, string $class, string | boolean $message = '{:message}' ) : boolean
$attributeName mixed
$class string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertClassNotHasStaticAttribute() публичный Метод

$this->assertClassNotHasStaticAttribute('foobar', '\lithium\core\StaticObject'); // succeeds $this->assertClassNotHasStaticAttribute('_methodFilters', '\lithium\core\StaticObject'); // fails
См. также: lithium\test\Unit::assert()
public assertClassNotHasStaticAttribute ( $attrName, string $class, string | boolean $message = '{:message}' ) : boolean
$class string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertContains() публичный Метод

$this->assertContains('foo', array('foo', 'bar', 'baz')); // succeeds $this->assertContains(4, array(1,2,3)); // fails
См. также: lithium\test\Unit::assert()
public assertContains ( string $needle, mixed $haystack, string | boolean $message = '{:message}' ) : boolean
$needle string The needle you are looking for.
$haystack mixed An array, iterable object, or string.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertContainsOnly() публичный Метод

$this->assertContainsOnly('integer', array(1,2,3)); // succeeds $this->assertContainsOnly('integer', array('foo', 'bar', 'baz')); // fails
См. также: lithium\test\Unit::$_internalTypes
См. также: lithium\test\Unit::assert()
public assertContainsOnly ( string $type, array | object $haystack, string | boolean $message = '{:message}' ) : boolean
$type string
$haystack array | object Array or iterable object.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertContainsOnlyInstancesOf() публичный Метод

$this->assertContainsOnlyInstancesOf('stdClass', array(new \stdClass)); // succeeds $this->assertContainsOnlyInstancesOf('stdClass', array(new \lithium\test\Unit)); // fails
См. также: lithium\test\Unit::assert()
public assertContainsOnlyInstancesOf ( string $class, array | object $haystack, string | boolean $message = '{:message}' ) : boolean
$class string
$haystack array | object Array or iterable object.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertCookie() публичный Метод

The value passed to exepected is an array of the cookie data, with at least the key and value expected, but can support any of the following keys: - key: the expected key - value: the expected value - path: optionally specifiy a path - name: optionally specify the cookie name - expires: optionally assert a specific expire time
См. также: lithium\test\Unit::assert()
public assertCookie ( array $expected, array $headers = null ) : boolean
$expected array
$headers array When empty, value of `headers_list()` is used.
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertCount() публичный Метод

$this->assertCount(1, array('foo')); // succeeds $this->assertCount(2, array('foo', 'bar', 'bar')); // fails
См. также: lithium\test\Unit::assert()
public assertCount ( integer $expected, array $array, string | boolean $message = '{:message}' ) : boolean
$expected integer
$array array
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertEmpty() публичный Метод

$this->assertEmpty(''); // succeeds $this->assertEmpty(0); // succeeds $this->assertEmpty(0.0); // succeeds $this->assertEmpty('0'); // succeeds $this->assertEmpty(null); // succeeds $this->assertEmpty(false); // succeeds $this->assertEmpty(array()); // succeeds $this->assertEmpty(1); // fails
См. также: lithium\test\Unit::assert()
public assertEmpty ( string $actual, string | boolean $message = '{:message}' ) : boolean
$actual string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertEqual() публичный Метод

Assert that the actual result is equal, but not neccessarily identical, to the expected result.
См. также: lithium\test\Unit::assert()
public assertEqual ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean
$expected mixed
$result mixed
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertException() публичный Метод

Assert that the code passed in a closure throws an exception or raises a PHP error. The first argument to this method specifies which class name or message the exception must have in order to make the assertion successful.
См. также: lithium\test\Unit::assert()
public assertException ( mixed $expected, Closure $closure, string $message = '{:message}' ) : boolean
$expected mixed A string indicating what the error text is expected to be. This can be an exact string, a /-delimited regular expression, or true, indicating that any error text is acceptable.
$closure Closure A closure containing the code that should throw the exception.
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertFalse() публичный Метод

$this->assertFalse(false, 'Boolean false'); // succeeds $this->assertFalse('', 'String is empty'); // fails $this->assertFalse(0, 'Zero value'); // fails
См. также: lithium\test\Unit::assert()
public assertFalse ( mixed $result, string $message = '{:message}' ) : boolean
$result mixed
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertFileEquals() публичный Метод

$this->assertFileEquals('/tmp/foo.txt', '/tmp/foo.txt'); // succeeds $this->assertFileEquals('/tmp/foo.txt', '/tmp/bar.txt'); // fails
См. также: lithium\test\Unit::assert()
public assertFileEquals ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Absolute path to the expected file.
$actual string Absolute path to the actual file.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertFileExists() публичный Метод

$this->assertFileExists(__FILE__); // succeeds $this->assertFileExists('/tmp/bar.txt'); // fails
См. также: lithium\test\Unit::assert()
public assertFileExists ( string $actual, string | boolean $message = '{:message}' ) : boolean
$actual string Absolute path to the actual file.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertFileNotEquals() публичный Метод

$this->assertFileNotEquals('/tmp/foo.txt', '/tmp/bar.txt'); // succeeds $this->assertFileNotEquals('/tmp/foo.txt', '/tmp/foo.txt'); // fails
См. также: lithium\test\Unit::assert()
public assertFileNotEquals ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Absolute path to the expected file.
$actual string Absolute path to the actual file.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertFileNotExists() публичный Метод

$this->assertFileNotExists('/tmp/bar.txt'); // succeeds $this->assertFileNotExists(__FILE__); // fails
См. также: lithium\test\Unit::assert()
public assertFileNotExists ( string $actual, string | boolean $message = '{:message}' ) : boolean
$actual string Absolute path to the actual file.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertGreaterThan() публичный Метод

$this->assertGreaterThan(5, 3); // succeeds $this->assertGreaterThan(3, 5); // fails
См. также: lithium\test\Unit::assert()
public assertGreaterThan ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean
$expected float | integer
$actual float | integer
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertGreaterThanOrEqual() публичный Метод

$this->assertGreaterThanOrEqual(5, 5); // succeeds $this->assertGreaterThanOrEqual(3, 5); // fails
См. также: lithium\test\Unit::assert()
public assertGreaterThanOrEqual ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean
$expected float | integer
$actual float | integer
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertIdentical() публичный Метод

Assert that the actual result and the expected result are identical using a strict comparison.
См. также: lithium\test\Unit::assert()
public assertIdentical ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean
$expected mixed
$result mixed
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertInstanceOf() публичный Метод

$this->assertInstanceOf('stdClass', new stdClass); // succeeds $this->assertInstanceOf('ReflectionClass', new stdClass); // fails
См. также: lithium\test\Unit::assert()
public assertInstanceOf ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Fully namespaced expected class.
$actual object Object you are testing.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertInternalType() публичный Метод

$this->assertInternalType('string', 'foobar'); // succeeds $this->assertInternalType('integer', 'foobar'); // fails
См. также: lithium\test\Unit::$_internalTypes
См. также: lithium\test\Unit::assert()
public assertInternalType ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Internal type.
$actual object Object you are testing.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertLessThan() публичный Метод

$this->assertLessThan(3, 5); // succeeds $this->assertLessThan(5, 3); // fails
См. также: lithium\test\Unit::assert()
public assertLessThan ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean
$expected float | integer
$actual float | integer
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertLessThanOrEqual() публичный Метод

$this->assertLessThanOrEqual(5, 5); // succeeds $this->assertLessThanOrEqual(5, 3); // fails
См. также: lithium\test\Unit::assert()
public assertLessThanOrEqual ( float | integer $expected, float | integer $actual, string | boolean $message = '{:message}' ) : boolean
$expected float | integer
$actual float | integer
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNoCookie() публичный Метод

The value passed to expected is an array of the cookie data, with at least the key and value expected, but can support any of the following keys: - key: the expected key - value: the expected value - path: optionally specify a path - name: optionally specify the cookie name - expires: optionally assert a specific expire time
См. также: lithium\test\Unit::assert()
public assertNoCookie ( array $expected, array $headers = null ) : boolean
$expected array
$headers array When empty, value of `headers_list()` is used.
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotContains() публичный Метод

$this->assertNotContains(4, array(1,2,3)); // succeeds $this->assertNotContains('foo', array('foo', 'bar', 'baz')); // fails
См. также: lithium\test\Unit::assert()
public assertNotContains ( string $needle, miexed $haystack, string | boolean $message = '{:message}' ) : boolean
$needle string The needle you are looking for.
$haystack miexed Array or iterable object or a string.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotContainsOnly() публичный Метод

$this->assertNotContainsOnly('integer', array('foo', 'bar', 'baz')); // succeeds $this->assertNotContainsOnly('integer', array(1,2,3)); // fails
См. также: lithium\test\Unit::$_internalTypes
См. также: lithium\test\Unit::assert()
public assertNotContainsOnly ( string $type, array | object $haystack, string | boolean $message = '{:message}' ) : boolean
$type string
$haystack array | object Array or iterable object.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotCount() публичный Метод

$this->assertNotCount(2, array('foo', 'bar', 'bar')); // succeeds $this->assertNotCount(1, array('foo')); // fails
См. также: lithium\test\Unit::assert()
public assertNotCount ( integer $expected, array $array, string | boolean $message = '{:message}' ) : boolean
$expected integer
$array array
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotEmpty() публичный Метод

$this->assertNotEmpty(1); // succeeds $this->assertNotEmpty(array()); // fails
См. также: lithium\test\Unit::assert()
public assertNotEmpty ( string $actual, string | boolean $message = '{:message}' ) : boolean
$actual string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotEqual() публичный Метод

Assert that the actual result and the expected result are *not* equal to each other.
См. также: lithium\test\Unit::assert()
public assertNotEqual ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean
$expected mixed
$result mixed
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotException() публичный Метод

The value passed to exepected is either an exception class name or the expected message.
См. также: lithium\test\Unit::assert()
public assertNotException ( mixed $expected, Closure $closure, string $message = '{:message}' ) : boolean
$expected mixed A string indicating what the error text is not expected to be. This can be an exact string, a /-delimited regular expression, or true, indicating that any error text is acceptable.
$closure Closure A closure containing the code that should throw the exception.
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotIdentical() публичный Метод

Assert that the actual result and the expected result are *not* identical using a strict comparison.
См. также: lithium\test\Unit::assert()
public assertNotIdentical ( mixed $expected, mixed $result, string | boolean $message = '{:message}' ) : boolean
$expected mixed
$result mixed
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotInstanceOf() публичный Метод

$this->assertNotInstanceOf('ReflectionClass', new stdClass); // succeeds $this->assertNotInstanceOf('stdClass', new stdClass); // fails
См. также: lithium\test\Unit::assert()
public assertNotInstanceOf ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Fully namespaced expected class.
$actual object Object you are testing.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotInternalType() публичный Метод

$this->assertNotInternalType('integer', 'foobar'); // succeeds $this->assertNotInternalType('string', 'foobar'); // fails
См. также: lithium\test\Unit::$_internalTypes
См. также: lithium\test\Unit::assert()
public assertNotInternalType ( string $expected, object $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Internal type.
$actual object Object you are testing.
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotNull() публичный Метод

$this->assertNotNull(1); // succeeds $this->assertNotNull(null); // fails
См. также: lithium\test\Unit::assert()
public assertNotNull ( $actual, string $message = '{:message}' ) : boolean
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNotPattern() публичный Метод

Assert that the regular expression $expected is *not* matched in the result.
См. также: lithium\test\Unit::assert()
public assertNotPattern ( mixed $expected, mixed $result, string $message = '{:message}' ) : boolean
$expected mixed
$result mixed
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertNull() публичный Метод

Assert that the result is strictly null.
См. также: lithium\test\Unit::assert()
public assertNull ( mixed $result, string $message = '{:message}' ) : boolean
$result mixed
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertObjectHasAttribute() публичный Метод

$this->assertObjectHasAttribute('__construct', 'ReflectionClass'); // succeeds $this->assertObjectHasAttribute('name', 'ReflectionClass'); // fails
См. также: lithium\test\Unit::assert()
public assertObjectHasAttribute ( string $attributeName, string $object, string | boolean $message = '{:message}' ) : boolean
$attributeName string
$object string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertObjectNotHasAttribute() публичный Метод

$this->assertObjectNotHasAttribute('name', 'ReflectionClass'); // succeeds $this->assertObjectNotHasAttribute('__construct', 'ReflectionClass'); // fails
См. также: lithium\test\Unit::assert()
public assertObjectNotHasAttribute ( string $attributeName, string $object, string | boolean $message = '{:message}' ) : boolean
$attributeName string
$object string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertPattern() публичный Метод

Assert that the regular expression $expected is matched in the result.
См. также: lithium\test\Unit::assert()
public assertPattern ( mixed $expected, mixed $result, string $message = '{:message}' ) : boolean
$expected mixed
$result mixed
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertStringEndsWith() публичный Метод

$this->assertStringEndsWith('bar', 'foobar'); // succeeds $this->assertStringEndsWith('foo', 'foobar'); // fails
public assertStringEndsWith ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean
$expected string The suffix to check for.
$actual string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertStringMatchesFormat() публичный Метод

$this->assertStringMatchesFormat('%d', '10'); // succeeds $this->assertStringMatchesFormat('%d', '10.555'); // fails
См. также: lithium\test\Unit::assert()
public assertStringMatchesFormat ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Expected format using sscanf's format.
$actual string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertStringNotMatchesFormat() публичный Метод

$this->assertStringNotMatchesFormat('%d', '10.555'); // succeeds $this->assertStringNotMatchesFormat('%d', '10'); // fails
См. также: lithium\test\Unit::assert()
public assertStringNotMatchesFormat ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean
$expected string Expected format using sscanf's format.
$actual string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertStringStartsWith() публичный Метод

$this->assertStringStartsWith('foo', 'foobar'); // succeeds $this->assertStringStartsWith('bar', 'foobar'); // fails
public assertStringStartsWith ( string $expected, string $actual, string | boolean $message = '{:message}' ) : boolean
$expected string The prefix to check for.
$actual string
$message string | boolean
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertTags() публичный Метод

Samples for $expected: Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input': array('input' => array('name', 'id' => 'my-input')) Checks for two p elements with some text in them: array( array('p' => true), 'textA', '/p', array('p' => true), 'textB', '/p' ) You can also specify a pattern expression as part of the attribute values, or the tag being defined, if you prepend the value with preg: and enclose it with slashes, like so: array( array('input' => array('name', 'id' => 'preg:/FieldName\d+/')), 'preg:/My\s+field/' ) Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order. It will also allow whitespaces between specified tags.
См. также: lithium\test\Unit::assert()
public assertTags ( string $string, array $expected ) : boolean
$string string An HTML/XHTML/XML string
$expected array An array, see above
Результат boolean `true` if the assertion succeeded, `false` otherwise.

assertTrue() публичный Метод

$this->assertTrue(true, 'Boolean true'); // succeeds $this->assertTrue('false', 'String has content'); // fails $this->assertTrue(10, 'Non-Zero value'); // fails
См. также: lithium\test\Unit::assert()
public assertTrue ( mixed $result, string $message = '{:message}' ) : boolean
$result mixed
$message string
Результат boolean `true` if the assertion succeeded, `false` otherwise.

expectException() публичный Метод

Used before a call to assert*() if you expect the test assertion to generate an exception or PHP error. If no error or exception is thrown, a test failure will be reported. Can be called multiple times per assertion, if more than one error is expected.
Устаревший:
public expectException ( mixed $message = true ) : void
$message mixed A string indicating what the error text is expected to be. This can be an exact string, a /-delimited regular expression, or true, indicating that any error text is acceptable.
Результат void

fail() публичный Метод

Generates a failed test with the given message.
public fail ( string $message = false )
$message string

get() публичный статический Метод

Finds the test case for the corresponding class name.
public static get ( string $class ) : string
$class string A fully-namespaced class reference for which to find a test case.
Результат string Returns the class name of a test case for `$class`, or `null` if none exists.

methods() публичный Метод

Return test methods to run.
public methods ( ) : array
Результат array

results() публичный Метод

Returns the current results.
public results ( ) : array
Результат array The Results... currently.

run() публичный Метод

Installs a temporary error handler that will convert regular errors to exceptions in order to make both errors and exceptions be handled in a unified way. ErrorExceptions created like this, will get the error's code as their severity. As this comes closest to their meaning. The error handler honors the PHP error_level and will not convert errors to exceptions if they are masked by the error_level. This allows test methods to run assertions against i.e. deprecated functions. Usually the error_level is set by the test runner so that all errors are converted.
public run ( array $options = [] ) : array
$options array The options to use when running the test. Available options are: - `'methods'`: An arbitrary array of method names to execute. If unspecified, all methods starting with 'test' are run. - `'reporter'`: A closure which gets called after each test result, which may modify the results presented. - `'handler'`: A closure which gets registered as the temporary error handler.
Результат array

setUp() публичный Метод

Setup method run before every test method. Override in subclasses.
public setUp ( ) : void
Результат void

skip() публичный Метод

For example: public function skip() { $connection = Connections::get('test', array('config' => true)); $this->skipIf(!$connection, 'Test database is unavailable.'); }
public skip ( )

skipIf() публичный Метод

When used within a subclass' skip method, all tests are ignored if the condition is met, otherwise processing continues as normal. For other methods, only the remainder of the method is skipped, when the condition is met.
public skipIf ( boolean $condition, string | boolean $message = false ) : mixed
$condition boolean
$message string | boolean Message to pass if the condition is met.
Результат mixed

subject() публичный Метод

Returns the class name that is the subject under test for this test case.
public subject ( ) : string
Результат string

tearDown() публичный Метод

Teardown method run after every test method. Override in subclasses.
public tearDown ( ) : void
Результат void

Описание свойств

$_expected защищенное свойство

The list of expected exceptions.
Устаревший:
protected string $_expected
Результат string

$_internalTypes защищенное статическое свойство

Internal types and how to test for them
protected static array $_internalTypes
Результат array

$_reporter защищенное свойство

The Reference to a test reporter class.
protected string $_reporter
Результат string

$_results защищенное свойство

The list of test results.
protected string $_results
Результат string