Skip to content

Commit cfcda29

Browse files
committed
Merge branch '3.x-dev' into 4.x-dev
2 parents 787a588 + be6917c commit cfcda29

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

Tests/FileTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,4 +571,35 @@ public function testUploadToNestedDirectory()
571571
File::upload($this->testPath . '/' . $name . '.txt', $this->testPath . '/' . $name . '/' . $uploadedFileName)
572572
);
573573
}
574+
575+
/**
576+
* Test exists method.
577+
*/
578+
public function testExistsForExistingFile()
579+
{
580+
$name = 'tempFile';
581+
$data = 'Lorem ipsum dolor sit amet';
582+
583+
if (!File::write($this->testPath . '/' . $name, $data)) {
584+
$this->markTestSkipped('The test file could not be created.');
585+
}
586+
587+
$this->assertTrue(
588+
File::exists($this->testPath . '/' . $name),
589+
'The file exists.'
590+
);
591+
}
592+
593+
/**
594+
* Test exists method.
595+
*/
596+
public function testExistsForNonexistingFile()
597+
{
598+
$name = 'nonExistingTempFile';
599+
600+
$this->assertFalse(
601+
File::exists($this->testPath . '/' . $name),
602+
'The file does not exists.'
603+
);
604+
}
574605
}

Tests/FolderTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,4 +921,35 @@ public function testMakeSafe()
921921
Folder::makeSafe('test1/testdirectory')
922922
);
923923
}
924+
925+
926+
/**
927+
* Test exists method.
928+
*/
929+
public function testExistsForExistingFolder()
930+
{
931+
$name = 'tempFolder';
932+
933+
if (!Folder::create($this->testPath . '/' . $name)) {
934+
$this->markTestSkipped('The test directory could not be created.');
935+
}
936+
937+
$this->assertTrue(
938+
Folder::exists($this->testPath . '/' . $name),
939+
'The folder exists.'
940+
);
941+
}
942+
943+
/**
944+
* Test exists method.
945+
*/
946+
public function testExistsForNonexistingFolder()
947+
{
948+
$name = 'nonExistingTempFolder';
949+
950+
$this->assertFalse(
951+
Folder::exists($this->testPath . '/' . $name),
952+
'The folder does not exists.'
953+
);
954+
}
924955
}

src/File.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,17 @@ public static function invalidateFileCache($file)
372372
opcache_invalidate($file, true);
373373
}
374374
}
375+
376+
/**
377+
* Wrapper for the standard file_exists function
378+
*
379+
* @param string $file File path
380+
*
381+
* @return boolean True if path is a file
382+
*
383+
*/
384+
public static function exists(string $file): bool
385+
{
386+
return is_file(Path::clean($file));
387+
}
375388
}

src/Folder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,16 @@ public static function makeSafe($path)
547547

548548
return preg_replace($regex, '', $path);
549549
}
550+
551+
/**
552+
* Wrapper for the standard is_dir function
553+
*
554+
* @param string $path Folder path
555+
*
556+
* @return boolean True if path is a folder
557+
*/
558+
public static function exists(string $path): bool
559+
{
560+
return is_dir(Path::clean($path));
561+
}
550562
}

0 commit comments

Comments
 (0)