ConfigDouble
extends Config
in package
Config class for use in the tests.
The PHP_CodeSniffer Config class contains a number of static properties. As the value of these static properties will be retained between instantiations of the class, config values set in one test can influence the results for another test, which makes tests unstable.
This class is a "double" of the Config class which prevents this from happening. In most cases, tests should be using this class instead of the "normal" Config, with the exception of select tests for the PHPCS Config class itself.
Tags
Table of Contents
Methods
- __construct() : void
- Creates a clean Config object and populates it with command line values.
- __destruct() : void
- Ensures the static properties in the Config class are reset to their default values when the ConfigDouble is no longer used.
- getStaticConfigProperty() : mixed
- Helper function to retrieve the value of a private static property on the Config class.
- setCommandLineValues() : void
- Sets the command line values and optionally prevents a file system search for a custom ruleset.
- setStaticConfigProperty() : void
- Helper function to set the value of a private static property on the Config class.
Methods
__construct()
Creates a clean Config object and populates it with command line values.
public
__construct([array<string|int, string> $cliArgs = [] ][, bool $skipSettingStandard = false ][, bool $skipSettingReportWidth = false ]) : void
Parameters
- $cliArgs : array<string|int, string> = []
-
An array of values gathered from CLI args.
- $skipSettingStandard : bool = false
-
Whether to skip setting a standard to prevent the Config class trying to auto-discover a ruleset file. Should only be set to
true
for tests which actually test the ruleset auto-discovery. Note: there is no need to set this totrue
when a standard is being passed via the$cliArgs
. Those settings will always respected. Defaults tofalse
. Will result in the standard being set to "PSR1" if not provided via$cliArgs
. - $skipSettingReportWidth : bool = false
-
Whether to skip setting a report-width to prevent the Config class trying to auto-discover the screen width. Should only be set to
true
for tests which actually test the screen width auto-discovery. Note: there is no need to set this totrue
when a report-width is being passed via the$cliArgs
. Those settings will always respected. Defaults tofalse
. Will result in the reportWidth being set to "80" if not provided via$cliArgs
.
Tags
__destruct()
Ensures the static properties in the Config class are reset to their default values when the ConfigDouble is no longer used.
public
__destruct() : void
Tags
getStaticConfigProperty()
Helper function to retrieve the value of a private static property on the Config class.
public
getStaticConfigProperty(string $name) : mixed
Note: As of PHPCS 4.0, the "overriddenDefaults" property is no longer static, but this method will still handle this property.
Parameters
- $name : string
-
The name of the property to retrieve.
Tags
setCommandLineValues()
Sets the command line values and optionally prevents a file system search for a custom ruleset.
public
setCommandLineValues(array<string|int, string> $args) : void
Parameters
- $args : array<string|int, string>
-
An array of command line arguments to set.
Tags
setStaticConfigProperty()
Helper function to set the value of a private static property on the Config class.
public
setStaticConfigProperty(string $name, mixed $value) : void
Note: As of PHPCS 4.0, the "overriddenDefaults" property is no longer static, but this method will still handle this property.
Parameters
- $name : string
-
The name of the property to set.
- $value : mixed
-
The value to set the property to.