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 @@ 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; + } + }