Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12240066
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tests/Reflection/CodeFileTest.php b/tests/Reflection/CodeFileTest.php
index 03c6caf..22500f2 100644
--- a/tests/Reflection/CodeFileTest.php
+++ b/tests/Reflection/CodeFileTest.php
@@ -1,45 +1,72 @@
<?php
declare(strict_types=1);
namespace Keruald\OmniTools\Tests\Reflection;
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;
/**
* @var CodeFile
*/
private $validCodeFile;
/**
* @var CodeFile
*/
private $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 {
+ $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 {
+ $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-diff
Expires
Sun, Oct 12, 02:25 (26 m, 2 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3064454
Default Alt Text
(2 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment