class PatternMatchingTest in Config Ignore 8.2
Test the pattern matching.
This is a unit test which tests the protected method, but it is much faster.
@group config_ignore_new
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\config_ignore\Unit\PatternMatchingTest
Expanded class hierarchy of PatternMatchingTest
File
- tests/
src/ Unit/ PatternMatchingTest.php, line 16
Namespace
Drupal\Tests\config_ignore\UnitView source
class PatternMatchingTest extends UnitTestCase {
/**
* Test the ignored config matching against names.
*
* @param array $patterns
* The config of ignored names.
* @param array $test
* An array with config names as keys and the expected outcome as value.
*
* @dataProvider patternProvider
*/
public function testPatternMatching(array $patterns, array $test) {
$filter = new IgnoreFilter([
'ignored' => $patterns,
], 'config_ignore', [], new MemoryStorage());
// In order to test much faster we access the protected method.
$method = new \ReflectionMethod(IgnoreFilter::class, 'matchConfigName');
$method
->setAccessible(TRUE);
foreach ($test as $name => $expected) {
static::assertEquals($expected, $method
->invoke($filter, $name), $name);
}
if (!in_array(TRUE, $test, TRUE) || !in_array(FALSE, $test, TRUE)) {
// Make sure there is always a positive and negative test.
$this
->markAsRisky();
}
}
/**
* Get the ignored config and test against the names.
*
* @return array
* The patterns and what should and shouldn't match.
*/
public function patternProvider() {
// For each pattern there needs to be a positive and a negative case.
return [
'system.site ignored' => [
[
'system.site',
],
[
'system.site' => TRUE,
'system.performance' => FALSE,
],
],
'system ignored' => [
[
'system.*',
],
[
'system.site' => TRUE,
'system.performance' => TRUE,
'node.site' => FALSE,
],
],
'site ignored' => [
[
'*.site',
],
[
'system.site' => TRUE,
'system.performance' => FALSE,
'other.site' => TRUE,
],
],
'node ignored' => [
[
'node.*',
],
[
'system.site' => FALSE,
'node.settings' => TRUE,
'node.settings.other' => TRUE,
],
],
'middle ignored' => [
[
'start.*.end',
],
[
'start.something' => FALSE,
'start.something.end' => TRUE,
'start.something.else.end' => TRUE,
'start.something.ending' => FALSE,
],
],
'enforced excluded' => [
[
'system.*',
'~system.site',
],
[
'system.site' => FALSE,
'system.performance' => TRUE,
],
],
'system sub-key ignored' => [
[
'system.*:foo',
],
[
'system.site' => TRUE,
'system.performance' => TRUE,
'node.foo' => FALSE,
],
],
];
}
/**
* Test the cases that are not allowed in testPatternMatching.
*/
public function testEverythingAndNothing() {
$method = new \ReflectionMethod(IgnoreFilter::class, 'matchConfigName');
$method
->setAccessible(TRUE);
$none = new IgnoreFilter([
'ignored' => [],
], 'config_ignore', [], new MemoryStorage());
$all = new IgnoreFilter([
'ignored' => [
'*',
],
], 'config_ignore', [], new MemoryStorage());
static::assertFalse($method
->invoke($none, $this
->randomMachineName()));
static::assertTrue($method
->invoke($all, $this
->randomMachineName()));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PatternMatchingTest:: |
public | function | Get the ignored config and test against the names. | |
PatternMatchingTest:: |
public | function | Test the cases that are not allowed in testPatternMatching. | |
PatternMatchingTest:: |
public | function | Test the ignored config matching against names. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |