/
FilecontentFilterIteratorTest.php
90 lines (71 loc) · 2.13 KB
/
FilecontentFilterIteratorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Finder\Tests\Iterator;
use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
class FilecontentFilterIteratorTest extends IteratorTestCase
{
public function testAccept()
{
$inner = new ContentInnerNameIterator(array('test.txt'));
$iterator = new FilecontentFilterIterator($inner, array(), array());
$this->assertIterator(array('test.txt'), $iterator);
}
public function testDirectory()
{
$inner = new ContentInnerNameIterator(array('directory'));
$iterator = new FilecontentFilterIterator($inner, array('directory'), array());
$this->assertIterator(array(), $iterator);
}
public function testUnreadableFile()
{
$inner = new ContentInnerNameIterator(array('file r-'));
$iterator = new FilecontentFilterIterator($inner, array('file r-'), array());
$this->assertIterator(array(), $iterator);
}
/**
* @expectedException RuntimeException
*/
public function testFileGetContents()
{
$inner = new ContentInnerNameIterator(array('file r+'));
$iterator = new FilecontentFilterIterator($inner, array('file r+'), array());
$array = iterator_to_array($iterator);
}
}
class ContentInnerNameIterator extends \ArrayIterator
{
public function current()
{
return new \SplFileInfo(parent::current());
}
public function getFilename()
{
return parent::current();
}
public function isFile()
{
$name = parent::current();
return preg_match('/file/', $name);
}
public function isDir()
{
$name = parent::current();
return preg_match('/directory/', $name);
}
public function getRealpath()
{
return parent::current();
}
public function isReadable()
{
$name = parent::current();
return preg_match('/r\+/', $name);
}
}