function FileManagedUnitTestBase::assertFileHooksCalled
Same name in other branches
- 9 core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::assertFileHooksCalled()
- 8.9.x core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::assertFileHooksCalled()
- 10 core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php \Drupal\Tests\file\Kernel\FileManagedUnitTestBase::assertFileHooksCalled()
Asserts that the specified file hooks were called only once.
Parameters
array $expected: Array with string containing with the hook name, e.g. 'load', 'save', 'insert', etc.
22 calls to FileManagedUnitTestBase::assertFileHooksCalled()
- CopyTest::testExistingError in core/
modules/ file/ tests/ src/ Kernel/ CopyTest.php - Tests that copying over an existing file fails when instructed to do so.
- CopyTest::testExistingRename in core/
modules/ file/ tests/ src/ Kernel/ CopyTest.php - Tests renaming when copying over a file that already exists.
- CopyTest::testExistingReplace in core/
modules/ file/ tests/ src/ Kernel/ CopyTest.php - Tests replacement when copying over a file that already exists.
- CopyTest::testNormal in core/
modules/ file/ tests/ src/ Kernel/ CopyTest.php - Tests file copying in the normal, base case.
- DeleteTest::testInUse in core/
modules/ file/ tests/ src/ Kernel/ DeleteTest.php - Tries deleting a file that is in use.
File
-
core/
modules/ file/ tests/ src/ Kernel/ FileManagedUnitTestBase.php, line 51
Class
- FileManagedUnitTestBase
- Provides a base class for testing file uploads and hook invocations.
Namespace
Drupal\Tests\file\KernelCode
public function assertFileHooksCalled($expected) {
\Drupal::state()->resetCache();
// Determine which hooks were called.
$actual = array_keys(array_filter(file_test_get_all_calls()));
// Determine if there were any expected that were not called.
$uncalled = array_diff($expected, $actual);
if (count($uncalled)) {
$this->assertTrue(FALSE, sprintf('Expected hooks %s to be called but %s was not called.', implode(', ', $expected), implode(', ', $uncalled)));
}
else {
$this->assertTrue(TRUE, sprintf('All the expected hooks were called: %s', empty($expected) ? '(none)' : implode(', ', $expected)));
}
// Determine if there were any unexpected calls.
$unexpected = array_diff($actual, $expected);
if (count($unexpected)) {
$this->assertTrue(FALSE, sprintf('Unexpected hooks were called: %s.', empty($unexpected) ? '(none)' : implode(', ', $unexpected)));
}
else {
$this->assertTrue(TRUE, 'No unexpected hooks were called.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.