-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathFilesystemTest.php
More file actions
129 lines (110 loc) · 3.63 KB
/
FilesystemTest.php
File metadata and controls
129 lines (110 loc) · 3.63 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
use Winter\Storm\Filesystem\Filesystem;
class FilesystemTest extends TestCase
{
protected ?Filesystem $filesystem = null;
public function setUp(): void
{
$this->filesystem = new Filesystem();
}
public function testUnique()
{
$cases = [
// File exists, make it unique
'winter_1.cms' => ['winter.cms', ['winter.cms', 'test_5']],
// File already unique, return original
'winter.cms' => ['winter.cms', ['winter_1.cms']],
// Last index available is incremented
'winter_4.cms' => ['winter.cms', ['winter_1.cms', 'test_5', 'winter_3.cms']],
'winter_98.cms' => ['winter.cms', ['winter_97.cms', 'test_5', 'winter_1.cms']],
// Separator as space
'winter 1.cms' => ['winter.cms', ['winter_1.cms', 'test_5', 'winter_3.cms'], ' '],
];
foreach ($cases as $output => $config) {
$this->assertSame($output, $this->filesystem->unique(...$config));
}
}
/**
* @dataProvider providePathsForIsAbsolutePath
* @see Symfony\Component\Filesystem\Tests\FilesystemTest::testIsAbsolutePath
*/
public function testIsAbsolutePath($path, $expectedResult)
{
$result = $this->filesystem->isAbsolutePath($path);
$this->assertEquals($expectedResult, $result);
}
public function providePathsForIsAbsolutePath()
{
return [
['/var/lib', true],
['c:\\\\var\\lib', true],
['\\var\\lib', true],
['var/lib', false],
['../var/lib', false],
['', false],
];
}
/**
* @dataProvider provideSizesForSizeToBytes
*/
public function testSizeToBytes($input, $expectedBytes)
{
$result = $this->filesystem->sizeToBytes($input);
$this->assertEquals($expectedBytes, $result);
}
public function provideSizesForSizeToBytes()
{
return [
['1 byte', '1'],
['1024 bytes', '1024'],
['1 KB', '1024'],
['1 MB', '1048576'],
['2.5 MB', '2621440'],
['1 GB', '1073741824'],
['1.5 GB', '1610612736'],
['2G', '2147483648'], // PHP shorthand
['512M', '536870912'], // PHP shorthand
['256K', '262144'], // PHP shorthand
];
}
/**
* @dataProvider provideBytesForSizeToString
*/
public function testSizeToString($bytes, $expectedString)
{
$result = $this->filesystem->sizeToString($bytes);
$this->assertEquals($expectedString, $result);
}
public function provideBytesForSizeToString()
{
return [
[1, '1 byte'],
[512, '512 bytes'],
[1024, '1.00 KB'],
[1536, '1.50 KB'],
[1048576, '1.00 MB'],
[1572864, '1.50 MB'],
[1073741824, '1.00 GB'],
[1610612736, '1.50 GB'],
];
}
/**
* @dataProvider provideInvalidSizesForSizeToBytes
*/
public function testSizeToBytesInvalidInput($input)
{
$this->expectException(\InvalidArgumentException::class);
$this->filesystem->sizeToBytes($input);
}
public function provideInvalidSizesForSizeToBytes()
{
return [
['-1G'], // Negative value
['abc MB'], // Invalid numeric value
['1.5 XB'], // Unsupported unit
['gigabyte'], // Unsupported unit without value
[''], // Empty string
['1.23.45 MB'], // Malformed input
];
}
}