mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-03 08:34:09 +02:00
fixup tests
This commit is contained in:
parent
b8bea69ea6
commit
1c6d18170e
7 changed files with 25 additions and 20 deletions
52
tests/DirectoryFilterTest.php
Normal file
52
tests/DirectoryFilterTest.php
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
|
||||
* This file is licensed under the Licensed under the MIT license:
|
||||
* http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Icewind\Streams\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DirectoryFilterTest extends TestCase {
|
||||
public function testFilterAcceptAll() {
|
||||
$this->filter(
|
||||
['a', 'b', 'c'],
|
||||
function () {
|
||||
return true;
|
||||
},
|
||||
['a', 'b', 'c']
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilterRejectAll() {
|
||||
$this->filter(
|
||||
['a', 'b', 'c'],
|
||||
function () {
|
||||
return false;
|
||||
},
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
public function testFilterRejectLong() {
|
||||
$this->filter(
|
||||
['a', 'bb', 'c'],
|
||||
function ($file) {
|
||||
return strlen($file) < 2;
|
||||
},
|
||||
['a', 'c']
|
||||
);
|
||||
}
|
||||
|
||||
private function filter(array $files, callable $filter, array $expected) {
|
||||
$source = \Icewind\Streams\IteratorDirectory::wrap($files);
|
||||
$filtered = \Icewind\Streams\DirectoryFilter::wrap($source, $filter);
|
||||
$result = [];
|
||||
while (($file = readdir($filtered)) !== false) {
|
||||
$result[] = $file;
|
||||
}
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue