Drupal 8  8.0.2
TestDiscovery Class Reference

Public Member Functions

 __construct ($class_loader, CacheBackendInterface $cache_backend=NULL)
 
 registerTestNamespaces ()
 
 getTestClasses ($extension=NULL)
 
 findAllClassFiles ($extension=NULL)
 

Static Public Member Functions

static scanDirectory ($namespace_prefix, $path)
 
static getTestInfo ($classname, $doc_comment=NULL)
 
static parseTestClassSummary ($doc_comment)
 
static parseTestClassAnnotations (\ReflectionClass $class)
 
static isUnitTest ($classname)
 

Protected Member Functions

 getExtensions ()
 

Protected Attributes

 $classLoader
 
 $cacheBackend
 
 $testNamespaces
 
 $availableExtensions
 

Detailed Description

Discovers available tests.

Constructor & Destructor Documentation

__construct (   $class_loader,
CacheBackendInterface  $cache_backend = NULL 
)

Constructs a new test discovery.

Parameters
$class_loaderThe class loader. Normally Composer's ClassLoader, as included by the front controller, but may also be decorated; e.g., .
\Drupal\Core\Cache\CacheBackendInterface$cache_backend(optional) Backend for caching discovery results.

Member Function Documentation

findAllClassFiles (   $extension = NULL)

Discovers all class files in all available extensions.

Parameters
string$extension(optional) The name of an extension to limit discovery to; e.g., 'node'.
Returns
array A classmap containing all discovered class files; i.e., a map of fully-qualified classnames to pathnames.

References TestDiscovery\registerTestNamespaces().

Referenced by TestDiscovery\getTestClasses().

Here is the call graph for this function:

Here is the caller graph for this function:

getExtensions ( )
protected

Returns all available extensions.

Returns
[] An array of Extension objects, keyed by extension name.

Referenced by TestDiscovery\registerTestNamespaces().

Here is the caller graph for this function:

getTestClasses (   $extension = NULL)

Discovers all available tests in all extensions.

Parameters
string$extension(optional) The name of an extension to limit discovery to; e.g., 'node'.
Returns
array An array of tests keyed by the first specified in each test's PHPDoc comment block, and then keyed by class names. For example:
$groups['block'] => array(
'Drupal\block\Tests\BlockTest' => array(
'name' => 'Drupal\block\Tests\BlockTest',
'description' => 'Tests block UI CRUD functionality.',
'group' => 'block',
),
);
Exceptions
\ReflectionExceptionIf a discovered test class does not match the expected class name.
Todo:
Remove singular grouping; retain list of groups in 'group' key.
See Also
https://www.drupal.org/node/2296615
Add base class groups 'Kernel' + 'Web', complementing 'PHPUnit'.

References MockFileFinder\create(), TestDiscovery\findAllClassFiles(), and Drupal\moduleHandler().

Here is the call graph for this function:

static getTestInfo (   $classname,
  $doc_comment = NULL 
)
static

Retrieves information about a test class for UI purposes.

Parameters
string$classThe test classname.
string$doc_comment(optional) The class PHPDoc comment. If not passed in reflection will be used but this is very expensive when parsing all the test classes.
Returns
array An associative array containing:
  • name: The test class name.
  • description: The test (PHPDoc) summary.
  • group: The test's first (parsed from PHPDoc annotations).
  • requires: An associative array containing test requirements parsed from PHPDoc annotations:
    • module: List of Drupal module extension names the test depends on.
Exceptions
\Drupal\simpletest\Exception\MissingGroupExceptionIf the class does not have a annotation.

Referenced by SimpletestResultsForm\addResultForm().

Here is the caller graph for this function:

static isUnitTest (   $classname)
static

Determines if the provided classname is a unit test.

Parameters
$classnameThe test classname.
Returns
bool TRUE if the class is a unit test. FALSE if not.

References Unicode\strtoupper(), and Unicode\substr().

Here is the call graph for this function:

static parseTestClassAnnotations ( \ReflectionClass  $class)
static

Parses annotations in the phpDoc of a test class.

Parameters
\ReflectionClass$classThe reflected test class.
Returns
array An associative array that contains all annotations on the test class; typically including:
  • group: A list of values.
  • requires: An associative array of values; e.g.:
    • module: A list of Drupal module dependencies that are required to exist.
See Also
PHPUnit_Util_Test::parseTestMethodAnnotations()
http://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.skipping-tests-using-requires
static parseTestClassSummary (   $doc_comment)
static

Parses the phpDoc summary line of a test class.

Parameters
string$doc_comment,.
Returns
string The parsed phpDoc summary line. An empty string is returned if no summary line can be parsed.
registerTestNamespaces ( )

Registers test namespaces of all available extensions.

Returns
array An associative array whose keys are PSR-4 namespace prefixes and whose values are directory names.

References TestDiscovery\getExtensions().

Referenced by TestDiscovery\findAllClassFiles().

Here is the call graph for this function:

Here is the caller graph for this function:

static scanDirectory (   $namespace_prefix,
  $path 
)
static

Scans a given directory for class files.

Parameters
string$namespace_prefixThe namespace prefix to use for discovered classes. Must contain a trailing namespace separator (backslash). For example: 'Drupal\node\Tests\'
string$pathThe directory path to scan. For example: '/path/to/drupal/core/modules/node/tests/src'
Returns
array An associative array whose keys are fully-qualified class names and whose values are corresponding filesystem pathnames.
Exceptions
\InvalidArgumentExceptionIf $namespace_prefix does not end in a namespace separator (backslash).
Todo:
Limit to '*Test.php' files (~10% less files to reflect/introspect).
See Also
https://www.drupal.org/node/2296635

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