Drupal 8  8.0.2
Inspector Class Reference

Static Public Member Functions

static assertTraversable ($traversable)
 
static assertAll (callable $callable, $traversable)
 
static assertAllStrings ($traversable)
 
static assertAllStringable ($traversable)
 
static assertStringable ($string)
 
static assertAllArrays ($traversable)
 
static assertStrictArray ($array)
 
static assertAllStrictArrays ($traversable)
 
static assertAllHaveKey ()
 
static assertAllIntegers ($traversable)
 
static assertAllFloat ($traversable)
 
static assertAllCallable ($traversable)
 
static assertAllNotEmpty ($traversable)
 
static assertAllNumeric ($traversable)
 
static assertAllMatch ($pattern, $traversable, $case_sensitive=FALSE)
 
static assertAllRegularExpressionMatch ($pattern, $traversable)
 
static assertAllObjects ()
 

Detailed Description

Generic inspections for the assert() statement.

This is a static function collection for inspecting variable contents. All functions in this collection check a variable against an assertion about its structure.

Example call:

assert('Drupal\\Component\\Assertion\\Inspector::assertAllStrings($array)');

Member Function Documentation

static assertAll ( callable  $callable,
  $traversable 
)
static

Asserts callback returns TRUE for each member of a traversable.

This is less memory intensive than using array_filter() to build a second array and then comparing the arrays. Many of the other functions in this collection alias this function passing a specific callback to make the code more readable.

Parameters
callable$callableCallback function.
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and $callable returns TRUE on all members.
See Also
http://php.net/manual/language.types.callable.php
static assertAllArrays (   $traversable)
static

Asserts that all members are arrays.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are arrays.

Referenced by InspectorTest\testAssertAllArrays().

Here is the caller graph for this function:

static assertAllCallable (   $traversable)
static

Asserts that all members are callable.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are callable.

Referenced by InspectorTest\testAllCallable().

Here is the caller graph for this function:

static assertAllFloat (   $traversable)
static

Asserts that all members are float values.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are floating point numbers.

Referenced by InspectorTest\testAssertAllFloat().

Here is the caller graph for this function:

static assertAllHaveKey ( )
static

Asserts all given keys exist in every member array.

Drupal has several data structure arrays that require certain keys be set. You can overload this function to specify a list of required keys. All of the keys must be set for this method to return TRUE.

As an example, this assertion tests for the keys of a theme registry.

assert('Drupal\\Component\\Assertion\\Inspector::assertAllHaveKey(
$arrayToTest, "type", "theme path", "function", "template", "variables", "render element", "preprocess functions")');

Note: If a method requires certain keys to be present it will usually be specific about the data types for the values of those keys. Therefore it will be best to write a specific test for it. Such tests are either bound to the object that uses them, or are collected into one assertion set for the package.

Parameters
mixed$traversableVariable to be examined.
string... Keys to be searched for.
Returns
bool TRUE if $traversable can be traversed and all members have all keys.

Referenced by InspectorTest\testAssertAllHaveKey().

Here is the caller graph for this function:

static assertAllIntegers (   $traversable)
static

Asserts that all members are integer values.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are integers.

Referenced by InspectorTest\testAssertAllIntegers().

Here is the caller graph for this function:

static assertAllMatch (   $pattern,
  $traversable,
  $case_sensitive = FALSE 
)
static

Asserts that all members are strings that contain the specified string.

This runs faster than the regular expression equivalent.

Parameters
string$patternThe needle to find.
mixed$traversableVariable to examine.
bool$case_sensitiveTRUE to use strstr(), FALSE to use stristr() which is case insensitive.
Returns
bool TRUE if $traversable can be traversed and all members are strings containing $pattern.

Referenced by InspectorTest\testAssertAllMatch().

Here is the caller graph for this function:

static assertAllNotEmpty (   $traversable)
static

Asserts that all members are not empty.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members not empty.

Referenced by InspectorTest\testAllNotEmpty().

Here is the caller graph for this function:

static assertAllNumeric (   $traversable)
static

Asserts all members are numeric data types or strings castable to such.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are numeric.

Referenced by InspectorTest\testAssertAllNumeric().

Here is the caller graph for this function:

static assertAllObjects ( )
static

Asserts that all members are objects.

When testing if a collection is composed of objects those objects should be given a common interface to implement and the test should be written to search for just that interface. While this method will allow tests for just object status or for multiple classes and interfaces this was done to allow tests to be written for existing code without altering it. Only use this method in that manner when testing code from third party vendors.

Here are some examples:

// Just test all are objects, like a cache.
assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects(
$collection');
// Test if traversable objects (arrays won't pass this)
assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects(
$collection', \'\\Traversable\');
// Test for the Foo class or Bar\None interface
assert('Drupal\\Component\\Assertion\\Inspector::assertAllObjects(
$collection', \'\\Foo\', \'\\Bar\\None\'');
Parameters
mixed$traversableVariable to be examined.
string... Classes and interfaces to test objects against.
Returns
bool TRUE if $traversable can be traversed and all members are objects with at least one of the listed classes or interfaces.

Referenced by InspectorTest\testAssertAllObjects().

Here is the caller graph for this function:

static assertAllRegularExpressionMatch (   $pattern,
  $traversable 
)
static

Asserts that all members are strings matching a regular expression.

Parameters
string$patternRegular expression string to find.
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are strings matching $pattern.

Referenced by InspectorTest\testAssertAllRegularExpressionMatch().

Here is the caller graph for this function:

static assertAllStrictArrays (   $traversable)
static

Asserts all members are strict arrays.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are strict arrays.
See Also
::assertStrictArray

Referenced by InspectorTest\testAssertAllStrictArrays().

Here is the caller graph for this function:

static assertAllStringable (   $traversable)
static

Asserts all members are strings or objects with magic __toString() method.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are strings or objects with __toString().

Referenced by InspectorTest\testAssertAllStringable().

Here is the caller graph for this function:

static assertAllStrings (   $traversable)
static

Asserts that all members are strings.

Use this only if it is vital that the members not be objects, otherwise test with ::assertAllStringable().

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed and all members are strings.

Referenced by InspectorTest\testAssertAllStrings().

Here is the caller graph for this function:

static assertStrictArray (   $array)
static

Asserts that the array is strict.

What PHP calls arrays are more formally called maps in most other programming languages. A map is a datatype that associates values to keys. The term 'strict array' here refers to a 0-indexed array in the classic sense found in programming languages other than PHP.

Parameters
mixed$arrayVariable to be examined.
Returns
bool TRUE if $traversable is a 0-indexed array.
See Also
http://php.net/manual/language.types.array.php

Referenced by InspectorTest\testAssertStrictArray().

Here is the caller graph for this function:

static assertStringable (   $string)
static

Asserts argument is a string or an object castable to a string.

Use this instead of is_string() alone unless the argument being an object in any way will cause a problem.

Parameters
mixedstring Variable to be examined
Returns
bool TRUE if $string is a string or an object castable to a string.
static assertTraversable (   $traversable)
static

Asserts argument can be traversed with foreach.

Parameters
mixed$traversableVariable to be examined.
Returns
bool TRUE if $traversable can be traversed with foreach.

Referenced by InspectorTest\testAssertTraversable().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: