function HookOrderTestTrait::assertSameCallList
Asserts that two lists of call strings are the same.
It is meant for strings produced with __FUNCTION__ or __METHOD__.
The assertion fails exactly when a regular ->assertSame() would fail, but it provides a more useful output on failure.
Parameters
list<string> $expected: Expected list of strings.
list<string> $actual: Actual list of strings.
string $message: Message to pass to ->assertSame().
5 calls to HookOrderTestTrait::assertSameCallList()
- HookAlterOrderTest::assertAlterCallOrder in core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookAlterOrderTest.php - Asserts the call order from an alter call.
- HookAlterOrderTest::testProceduralModuleImplementsAlterOrder in core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookAlterOrderTest.php - Tests procedural implementations of module implements alter ordering.
- HookOrderTest::testBothParametersHookOrder in core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookOrderTest.php - Tests hook order when both parameters are passed to RelativeOrderBase.
- HookOrderTest::testHookOrder in core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookOrderTest.php - Test hook implementation order.
- HookOrderTest::testSparseHookOrder in core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookOrderTest.php - Tests hook order when each module has either oop or procedural listeners.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Hook/ HookOrderTestTrait.php, line 27
Class
- HookOrderTestTrait
- @group Hook
Namespace
Drupal\KernelTests\Core\HookCode
protected function assertSameCallList(array $expected, array $actual, string $message = '') : void {
// Format without the numeric array keys, but in a way that can be easily
// copied into the test.
$format = function (array $strings) : string {
if (!$strings) {
return '[]';
}
$parts = array_map(static function (string $call_string) {
if (preg_match('@^(\\w+\\\\)*(\\w+)::(\\w+)@', $call_string, $matches)) {
[
,
,
$class_shortname,
$method,
] = $matches;
return $class_shortname . '::class . ' . var_export('::' . $method, TRUE);
}
return var_export($call_string, TRUE);
}, $strings);
return "[\n " . implode(",\n ", $parts) . ",\n]";
};
$this->assertSame($format($expected), $format($actual), $message);
// Finally, assert that array keys and the full class names are really the
// same, in a way that provides useful output on failure.
$this->assertSame($expected, $actual, $message);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.