Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12870475
FileTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
FileTest.php
View Options
<?php
namespace
Keruald\OmniTools\Tests\IO
;
use
Keruald\OmniTools\IO\File
;
use
Keruald\OmniTools\OS\CurrentOS
;
use
PHPUnit\Framework\TestCase
;
use
TypeError
;
class
FileTest
extends
TestCase
{
///
/// Tests
///
/**
* @dataProvider provideFilesAndDirectories
*/
public
function
testGetDirectory
(
string
$filename
,
string
$expected
)
:
void
{
if
(
CurrentOS
::
isPureWindows
())
{
$this
->
markTestSkipped
(
"This test is intended for UNIX systems."
);
}
$this
->
assertSame
(
$expected
,
File
::
from
(
$filename
)->
getDirectory
());
}
/**
* @dataProvider provideFilesAndFileNames
*/
public
function
testGetFileName
(
string
$filename
,
string
$expected
)
:
void
{
$this
->
assertSame
(
$expected
,
File
::
from
(
$filename
)->
getFileName
());
}
/**
* @dataProvider provideFilesAndFileNamesWithoutExtension
*/
public
function
testGetFileNameWithoutExtension
(
string
$filename
,
string
$expected
)
:
void
{
$this
->
assertSame
(
$expected
,
File
::
from
(
$filename
)->
getFileNameWithoutExtension
());
}
/**
* @dataProvider provideFilesAndExtensions
*/
public
function
testGetExtension
(
string
$filename
,
string
$expected
)
:
void
{
$this
->
assertSame
(
$expected
,
File
::
from
(
$filename
)->
getExtension
());
}
///
/// Issues
///
/**
* @see https://devcentral.nasqueron.org/D2494
*/
public
function
testNullPathIsNotAllowed
()
:
void
{
$this
->
expectException
(
TypeError
::
class
);
$file
=
new
File
(
null
);
}
///
/// Data providers
///
public
function
provideFilesAndDirectories
()
:
iterable
{
yield
[
''
,
''
];
yield
[
'/'
,
'/'
];
yield
[
'/foo'
,
'/'
];
yield
[
'foo/bar'
,
'foo'
];
yield
[
'foo/'
,
'.'
];
yield
[
'/full/path/to/foo.php'
,
'/full/path/to'
];
}
public
function
provideFilesAndFileNames
()
:
iterable
{
yield
[
''
,
''
];
yield
[
'foo'
,
'foo'
];
yield
[
'foo'
,
'foo'
];
yield
[
'foo.php'
,
'foo.php'
];
yield
[
'/full/path/to/foo.php'
,
'foo.php'
];
}
public
function
provideFilesAndFileNamesWithoutExtension
()
:
iterable
{
yield
[
''
,
''
];
yield
[
'foo'
,
'foo'
];
yield
[
'foo.php'
,
'foo'
];
yield
[
'/full/path/to/foo.php'
,
'foo'
];
yield
[
'foo.tar.gz'
,
'foo.tar'
];
}
public
function
provideFilesAndExtensions
()
:
iterable
{
yield
[
''
,
''
];
yield
[
'foo'
,
''
];
yield
[
'foo.php'
,
'php'
];
yield
[
'/full/path/to/foo.php'
,
'php'
];
yield
[
'foo.tar.gz'
,
'gz'
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 17, 15:49 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3155610
Default Alt Text
FileTest.php (2 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment