function ScanDirectoryTest::testReturn

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

Check the format of the returned values.

@covers ::scanDirectory

File

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

Class

ScanDirectoryTest
Tests <a href="/api/drupal/core%21lib%21Drupal%21Core%21File%21FileSystem.php/class/FileSystem/11.x" title="Provides helpers to operate on files and stream wrappers." class="local">\Drupal\Core\File\FileSystem</a>::scanDirectory.

Namespace

Drupal\KernelTests\Core\File

Code

public function testReturn() : void {
    // 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-/');
    ksort($all_files);
    $this->assertCount(2, $all_files, 'Found two, expected javascript files.');
    // Check the first file.
    $file = reset($all_files);
    $this->assertEquals(key($all_files), $file->uri, 'Correct array key was used for the first returned file.');
    $this->assertEquals($this->path . '/javascript-1.txt', $file->uri, 'First file name was set correctly.');
    $this->assertEquals('javascript-1.txt', $file->filename, 'First basename was set correctly');
    $this->assertEquals('javascript-1', $file->name, 'First name was set correctly.');
    // Check the second file.
    $file = next($all_files);
    $this->assertEquals(key($all_files), $file->uri, 'Correct array key was used for the second returned file.');
    $this->assertEquals($this->path . '/javascript-2.script', $file->uri, 'Second file name was set correctly.');
    $this->assertEquals('javascript-2.script', $file->filename, 'Second basename was set correctly');
    $this->assertEquals('javascript-2', $file->name, 'Second name was set correctly.');
}

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