Page MenuHomeDevCentral

No OneTemporary

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

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)

Event Timeline