function ScanDirectoryTest::testOptionCallback

Same name in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testOptionCallback()
  2. 10 core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testOptionCallback()
  3. 11.x core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testOptionCallback()

Check that the callback function is called correctly.

@covers ::scanDirectory

File

core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php, line 78

Class

ScanDirectoryTest
Tests \Drupal\Core\File\FileSystem::scanDirectory.

Namespace

Drupal\KernelTests\Core\File

Code

public function testOptionCallback() {
    // When nothing is matched nothing should be passed to the callback.
    $all_files = $this->fileSystem
        ->scanDirectory($this->path, '/^NONEXISTINGFILENAME/', [
        'callback' => 'file_test_file_scan_callback',
    ]);
    $this->assertCount(0, $all_files, 'No files were found.');
    $results = file_test_file_scan_callback();
    file_test_file_scan_callback_reset();
    $this->assertCount(0, $results, 'No files were passed to the callback.');
    // Grab a listing of all the JavaScript files and check that they're
    // passed to the callback.
    $all_files = $this->fileSystem
        ->scanDirectory($this->path, '/^javascript-/', [
        'callback' => 'file_test_file_scan_callback',
    ]);
    $this->assertCount(2, $all_files, 'Found two, expected javascript files.');
    $results = file_test_file_scan_callback();
    file_test_file_scan_callback_reset();
    $this->assertCount(2, $results, 'Files were passed to the callback.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.