function FileManagedUnitTestBase::assertFileHookCalled
Same name in other branches
- 9 core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::assertFileHookCalled()
- 8.9.x core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::assertFileHookCalled()
- 10 core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::assertFileHookCalled()
Assert that a hook_file_* hook was called a certain number of times.
Parameters
string $hook: String with the hook name, e.g. 'load', 'save', 'insert', etc.
int $expected_count: Optional integer count.
string $message: Optional translated string message.
3 calls to FileManagedUnitTestBase::assertFileHookCalled()
- LoadTest::testMultiple in core/
modules/ file/ tests/ src/ Kernel/ LoadTest.php - This will test loading file data from the database.
- LoadTest::testSingleValues in core/
modules/ file/ tests/ src/ Kernel/ LoadTest.php - Load a single file and ensure that the correct values are returned.
- LoadTest::testUuidValues in core/
modules/ file/ tests/ src/ Kernel/ LoadTest.php - Loads a single file and ensure that the correct values are returned.
File
-
core/
modules/ file/ tests/ src/ Kernel/ FileManagedUnitTestBase.php, line 86
Class
- FileManagedUnitTestBase
- Provides a base class for testing file uploads and hook invocations.
Namespace
Drupal\Tests\file\KernelCode
public function assertFileHookCalled($hook, $expected_count = 1, $message = NULL) {
$actual_count = count(FileTestHelper::getCalls($hook));
if (!isset($message)) {
if ($actual_count == $expected_count) {
$message = "hook_file_{$hook} was called correctly.";
}
elseif ($expected_count == 0) {
$message = "hook_file_{$hook} was not expected to be called but was actually called {$actual_count} time(s).";
}
else {
$message = "hook_file_{$hook} was expected to be called {$expected_count} time(s) but was called {$actual_count} time(s).";
}
}
$this->assertEquals($expected_count, $actual_count, $message);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.