|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* this file is part of magerun |
|
4
|
|
|
* |
|
5
|
|
|
* @author Tom Klingenberg <https://github.com/ktomk> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace N98\Util; |
|
9
|
|
|
|
|
10
|
|
|
use InvalidArgumentException; |
|
11
|
|
|
use PHPUnit_Framework_TestCase as TestCase; |
|
12
|
|
|
use RuntimeException; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class VerifyOrDieTest |
|
16
|
|
|
* |
|
17
|
|
|
* @package N98\Util |
|
18
|
|
|
*/ |
|
19
|
|
|
class VerifyOrDieTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @test a portable filename passes |
|
23
|
|
|
*/ |
|
24
|
|
|
public function portableFilename() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->assertSame("example.txt", VerifyOrDie::filename("example.txt")); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertSame(".hidden", VerifyOrDie::filename(".hidden")); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @test user-message for verification |
|
33
|
|
|
*/ |
|
34
|
|
|
public function userMessage() |
|
35
|
|
|
{ |
|
36
|
|
|
$message = sprintf('Database name %s is not portable', var_export('-fail', true)); |
|
37
|
|
|
try { |
|
38
|
|
|
VerifyOrDie::filename('-fail', $message); |
|
39
|
|
|
$this->fail('An expected exception has not been thrown.'); |
|
40
|
|
|
} catch (RuntimeException $e) { |
|
41
|
|
|
$this->assertSame($message, $e->getMessage()); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @test a filename must have at least one byte |
|
47
|
|
|
* @expectedException RuntimeException |
|
48
|
|
|
* @expectedExceptionMessage Filename is zero-length string |
|
49
|
|
|
*/ |
|
50
|
|
|
public function zeroLengthFilename() |
|
51
|
|
|
{ |
|
52
|
|
|
VerifyOrDie::filename(''); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
* @expectedException InvalidArgumentException |
|
58
|
|
|
* @expectedExceptionMessage Parameter basename must be of type string, NULL given |
|
59
|
|
|
*/ |
|
60
|
|
|
public function invalidArugment() |
|
61
|
|
|
{ |
|
62
|
|
|
VerifyOrDie::filename(null); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @test a filename must not start with a dash |
|
67
|
|
|
* @expectedException RuntimeException |
|
68
|
|
|
* @expectedExceptionMessage Filename '-rf' starts with a dash |
|
69
|
|
|
*/ |
|
70
|
|
|
public function startWithDashFilename() |
|
71
|
|
|
{ |
|
72
|
|
|
VerifyOrDie::filename('-rf'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @test |
|
77
|
|
|
* @dataProvider provideNonPortableFilenames |
|
78
|
|
|
* @expectedException RuntimeException |
|
79
|
|
|
* @expectedExceptionMessage is not portable |
|
80
|
|
|
*/ |
|
81
|
|
|
public function nonPortableFilenameThrowsException($filename) |
|
82
|
|
|
{ |
|
83
|
|
|
VerifyOrDie::filename($filename); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @see nonPortableFilenameThrowsException |
|
88
|
|
|
*/ |
|
89
|
|
|
public function provideNonPortableFilenames() |
|
90
|
|
|
{ |
|
91
|
|
|
return array( |
|
92
|
|
|
array('no-slash-/-in.there'), |
|
93
|
|
|
array('windoze-limits-<>:"/\\|?*'), |
|
94
|
|
|
array('lets-keep-spaces out'), |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|