first commit

This commit is contained in:
2024-11-10 21:08:49 +01:00
commit 0d932ce5ee
14455 changed files with 2567501 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace FileUtil\Tests;
use PHPUnit\Framework\TestCase;
use FileUtil\FileExists;
use org\bovigo\vfs\vfsStream;
class FileExistsTest extends TestCase
{
public function testFileExists()
{
$this->assertTrue(FileExists::fileExists(__DIR__ . '/FileExistsTest.php'));
$this->assertFalse(FileExists::fileExists(__DIR__ . '/not-here.php'));
}
public function testFileExistsTryHarder()
{
if (function_exists('exec')) {
$this->assertTrue(FileExists::fileExistsTryHarder(__DIR__ . '/FileExistsTest.php'));
$this->assertFalse(FileExists::fileExistsTryHarder(__DIR__ . '/not-here.php'));
}
}
/*
public function testFileExistsNoReadPermission()
{
$root = vfsStream::setup();
$file = vfsStream::newFile('hello.txt')
->withContent('hello')
->at($root)
->chmod(0000);
// fopen should now fail...
//$this->expectException(\Exception::class);
$this->assertTrue(FileExists::fileExists($file->url()));
}
*/
}

View File

@@ -0,0 +1,18 @@
<?php
namespace FileUtil\Tests;
use PHPUnit\Framework\TestCase;
use FileUtil\FileExistsUsingExec;
class FileExistsUsingExecTest extends TestCase
{
public function testFileExists()
{
if (function_exists('exec')) {
$this->assertTrue(FileExistsUsingExec::fileExists(__DIR__ . '/FileExistsTest.php'));
$this->assertFalse(FileExistsUsingExec::fileExists(__DIR__ . '/not-here.php'));
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace FileUtil\Tests;
use PHPUnit\Framework\TestCase;
use FileUtil\PathValidator;
use org\bovigo\vfs\vfsStream;
class PathValidatorTest extends TestCase
{
public function testFilenameNotString()
{
$this->expectException(\Exception::class);
PathValidator::checkPath(10);
//$this->mimeSniff(10);
}
public function testFilenameHasNULChar()
{
$this->expectException(\Exception::class);
PathValidator::checkPath("a\0");
}
public function testFilenameHasControlChars()
{
$this->expectException(\Exception::class);
PathValidator::checkPath("..\1..");
}
public function testFilenameIsEmpty()
{
$this->expectException(\Exception::class);
PathValidator::checkPath("");
}
public function testFilenameIsPhar()
{
$this->expectException(\Exception::class);
PathValidator::checkPath('phar://aoeu');
}
public function testFileNotFound()
{
// why does this fail in PHP 7.2 ? (Uninitialized string offset: 0)
$this->expectException(\Exception::class);
PathValidator::checkFilePathIsRegularFile(__DIR__ . '/images/no-such-file.jpg');
}
public function testFileIsDir()
{
$this->expectException(\Exception::class);
PathValidator::checkFilePathIsRegularFile(__DIR__ . '/images');
}
public function testFileOnWebNotFound()
{
// why does this fail in PHP 7.2 ? (Uninitialized string offset: 0)
$this->expectException(\Exception::class);
PathValidator::checkFilePathIsRegularFile('http://aoeuhtaoeu.eau');
}
public function testPhPStreamWrapper()
{
$this->expectException(\Exception::class);
PathValidator::checkFilePathIsRegularFile('php://input');
}
}