Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90780590
FilesystemTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 4, 16:54
Size
1 KB
Mime Type
text/x-php
Expires
Wed, Nov 6, 16:54 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22133614
Attached To
rPHU libphutil
FilesystemTestCase.php
View Options
<?php
/**
* @group testcase
*/
final
class
FilesystemTestCase
extends
PhutilTestCase
{
public
function
testBinaryExists
()
{
// Test for the `which` binary on Linux, and the `where` binary on Windows,
// because `which which` is cute.
if
(
phutil_is_windows
())
{
$exists
=
'where'
;
}
else
{
$exists
=
'which'
;
}
$this
->
assertEqual
(
true
,
Filesystem
::
binaryExists
(
$exists
));
// We don't expect to find this binary on any system.
$this
->
assertEqual
(
false
,
Filesystem
::
binaryExists
(
'halting-problem-decider'
));
}
public
function
testResolveBinary
()
{
// Test to make sure resolveBinary() returns the full path to the `which`
// and `where` binaries.
if
(
phutil_is_windows
())
{
$binary
=
'where'
;
}
else
{
$binary
=
'which'
;
}
$path
=
Filesystem
::
resolveBinary
(
$binary
);
$this
->
assertFalse
(
null
===
$path
);
$this
->
assertTrue
(
file_exists
(
$path
));
$this
->
assertFalse
(
is_dir
(
$path
));
$this
->
assertEqual
(
null
,
Filesystem
::
resolveBinary
(
'halting-problem-decider'
));
}
public
function
testWriteUniqueFile
()
{
$tmp
=
new
TempFile
();
$dir
=
dirname
(
$tmp
);
// Writing an empty file should work.
$f
=
Filesystem
::
writeUniqueFile
(
$dir
,
''
);
$this
->
assertEqual
(
''
,
Filesystem
::
readFile
(
$f
));
// File name should be unique.
$g
=
Filesystem
::
writeUniqueFile
(
$dir
,
'quack'
);
$this
->
assertTrue
(
$f
!=
$g
);
}
public
function
testReadRandomBytes
()
{
$number_of_bytes
=
1024
;
$data
=
Filesystem
::
readRandomBytes
(
$number_of_bytes
);
$this
->
assertTrue
(
strlen
(
$data
)
==
$number_of_bytes
);
$data1
=
Filesystem
::
readRandomBytes
(
128
);
$data2
=
Filesystem
::
readRandomBytes
(
128
);
$this
->
assertFalse
(
$data1
==
$data2
);
$caught
=
null
;
try
{
Filesystem
::
readRandomBytes
(
0
);
}
catch
(
Exception
$ex
)
{
$caught
=
$ex
;
}
$this
->
assertTrue
(
$caught
instanceof
Exception
);
}
}
Event Timeline
Log In to Comment