Page MenuHomeDevCentral

No OneTemporary

diff --git a/tests/IO/FileTest.php b/tests/IO/FileTest.php
index 2a7be34..cd9e130 100644
--- a/tests/IO/FileTest.php
+++ b/tests/IO/FileTest.php
@@ -1,81 +1,86 @@
<?php
namespace Keruald\OmniTools\Tests\IO;
use Keruald\OmniTools\IO\File;
+use Keruald\OmniTools\OS\CurrentOS;
use PHPUnit\Framework\TestCase;
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());
}
///
/// 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'];
}
}
diff --git a/tests/Reflection/CodeFileTest.php b/tests/Reflection/CodeFileTest.php
index 67df93f..e941b87 100644
--- a/tests/Reflection/CodeFileTest.php
+++ b/tests/Reflection/CodeFileTest.php
@@ -1,85 +1,94 @@
<?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;
/**
* @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 {
+ 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

Mime Type
text/x-diff
Expires
Thu, Sep 18, 11:17 (11 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2990629
Default Alt Text
(5 KB)

Event Timeline