-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathFileTest.php
More file actions
81 lines (68 loc) · 2.2 KB
/
Copy pathFileTest.php
File metadata and controls
81 lines (68 loc) · 2.2 KB
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
<?php
namespace Psecio\Parse;
use SplFileInfo;
use Mockery as m;
class FileTest extends \PHPUnit_Framework_TestCase
{
public function testExceptionOnInvalidPath()
{
$this->setExpectedException('RuntimeException');
new File(new SplFileInfo('this/really/does/not/exist/at/all'));
}
public function testGetPath()
{
$this->assertEquals(
__FILE__,
(new File(new SplFileInfo(__FILE__)))->getPath(),
'The correct path should be returned'
);
}
public function testIsPathMatch()
{
$this->assertTrue(
(new File(new SplFileInfo(__FILE__)))->isPathMatch('/.php$/'),
'Test should pass as the path of __FILE__ ends with .php'
);
}
public function testGetContent()
{
$this->assertRegExp(
'/public function testGetContent()/',
(new File(new SplFileInfo(__FILE__)))->getContents(),
'The contents from this file should be fetched correctly'
);
}
public function testFetchLines()
{
$filename = tempnam(sys_get_temp_dir(), 'psecio-parse-');
file_put_contents($filename, "line 1\nline 2\nline 3\nline 4");
$file = new File(new SplFileInfo($filename));
$this->assertSame(
["line 2"],
$file->fetchLines(2),
'A single argument to fetchLines should fetch only one line'
);
$this->assertSame(
["line 2", "line 3", "line 4"],
$file->fetchLines(2, 4),
'Two arguments to fetchLines should fetch the complete series of lines'
);
$this->assertSame(
["line 3"],
$file->fetchLines(3, 3),
'Specifying the same line twice should grab that line'
);
$this->assertSame(
["line 1", "line 2"],
$file->fetchNode(
m::mock('PhpParser\Node')
->shouldReceive('getAttributes')
->once()
->andReturn(['startLine' => 1, 'endLine' => 2])
->mock()
),
'fetchNode should fetch based on node attributes'
);
unlink($filename);
}
}