Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12239001
CodeFileTest.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
CodeFileTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Tests\Reflection
;
use
Keruald\OmniTools\OS\CurrentOS
;
use
Keruald\OmniTools\OS\CurrentProcess
;
use
Keruald\OmniTools\Reflection\CodeFile
;
use
Keruald\OmniTools\Tests\WithData
;
use
PHPUnit\Framework\TestCase
;
use
Acme\MockLib\Bar
;
// a mock class in a mock namespace to test include
class
CodeFileTest
extends
TestCase
{
use
WithData
;
private
CodeFile
$validCodeFile
;
private
CodeFile
$notExistingCodeFile
;
public
function
setUp
()
:
void
{
$file
=
$this
->
getDataPath
(
"MockLib/Bar.php"
);
$this
->
validCodeFile
=
CodeFile
::
from
(
$file
);
$this
->
notExistingCodeFile
=
CodeFile
::
from
(
"/notexisting"
);
}
public
function
testCanInclude
()
:
void
{
$this
->
assertTrue
(
$this
->
validCodeFile
->
canBeIncluded
());
$this
->
assertFalse
(
$this
->
notExistingCodeFile
->
canBeIncluded
());
}
public
function
testCanBeIncludedWhenFileModeForbidsReading
()
:
void
{
if
(
CurrentOS
::
isPureWindows
())
{
$this
->
markTestSkipped
(
"This test is intended for UNIX systems."
);
}
if
(
CurrentProcess
::
isPrivileged
())
{
$this
->
markTestSkipped
(
"This test requires non-root access to run properly."
);
}
$file
=
$this
->
getNonReadableFile
();
$this
->
assertFalse
(
CodeFile
::
From
(
$file
)->
canBeIncluded
());
unlink
(
$file
);
}
public
function
testTryInclude
()
:
void
{
$this
->
assertTrue
(
$this
->
validCodeFile
->
tryInclude
());
$this
->
assertTrue
(
class_exists
(
Bar
::
class
));
$this
->
assertFalse
(
$this
->
notExistingCodeFile
->
tryInclude
());
}
public
function
testIsReadable
()
:
void
{
$this
->
assertTrue
(
$this
->
validCodeFile
->
isReadable
());
}
public
function
testIsReadableWhenFileModeForbidsReading
()
:
void
{
if
(
CurrentOS
::
isPureWindows
())
{
$this
->
markTestSkipped
(
"This test is intended for UNIX systems."
);
}
if
(
CurrentProcess
::
isPrivileged
())
{
$this
->
markTestSkipped
(
"This test requires non-root access to run properly."
);
}
$file
=
$this
->
getNonReadableFile
();
$this
->
assertFalse
(
CodeFile
::
From
(
$file
)->
isReadable
());
unlink
(
$file
);
}
private
function
getNonReadableFile
()
:
string
{
$file
=
tempnam
(
sys_get_temp_dir
(),
"testCodeFile"
);
chmod
(
$file
,
0
);
return
$file
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 11, 20:04 (8 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3063862
Default Alt Text
CodeFileTest.php (2 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment