Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Tests/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,35 @@ public function testUploadToNestedDirectory()
File::upload($this->testPath . '/' . $name . '.txt', $this->testPath . '/' . $name . '/' . $uploadedFileName)
);
}

/**
* Test exists method.
*/
public function testExistsForExistingFile()
{
$name = 'tempFile';
$data = 'Lorem ipsum dolor sit amet';

if (!File::write($this->testPath . '/' . $name, $data)) {
$this->markTestSkipped('The test file could not be created.');
}

$this->assertTrue(
File::exists($this->testPath . '/' . $name),
'The file exists.'
);
}

/**
* Test exists method.
*/
public function testExistsForNonexistingFile()
{
$name = 'nonExistingTempFile';

$this->assertFalse(
File::exists($this->testPath . '/' . $name),
'The file does not exists.'
);
}
}
31 changes: 31 additions & 0 deletions Tests/FolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,35 @@ public function testMakeSafe()
Folder::makeSafe('test1/testdirectory')
);
}


/**
* Test exists method.
*/
public function testExistsForExistingFolder()
{
$name = 'tempFolder';

if (!Folder::create($this->testPath . '/' . $name)) {
$this->markTestSkipped('The test directory could not be created.');
}

$this->assertTrue(
Folder::exists($this->testPath . '/' . $name),
'The folder exists.'
);
}

/**
* Test exists method.
*/
public function testExistsForNonexistingFolder()
{
$name = 'nonExistingTempFolder';

$this->assertFalse(
Folder::exists($this->testPath . '/' . $name),
'The folder does not exists.'
);
}
}
13 changes: 13 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,17 @@ public static function invalidateFileCache($file)
opcache_invalidate($file, true);
}
}

/**
* Wrapper for the standard file_exists function
*
* @param string $file File path
*
* @return boolean True if path is a file
*
*/
public static function exists(string $file): bool
{
return is_file(Path::clean($file));
}
}
12 changes: 12 additions & 0 deletions src/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,4 +547,16 @@ public static function makeSafe($path)

return preg_replace($regex, '', $path);
}

/**
* Wrapper for the standard is_dir function
*
* @param string $path Folder path
*
* @return boolean True if path is a folder
*/
public static function exists(string $path): bool
{
return is_dir(Path::clean($path));
}
}
Loading