Skip to content
Snippets Groups Projects
Commit 704b04ef authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

Merge branch 'dev#160166_getcwd' into 'master'

dev#160166 : adding getcwd to fileSystem

See merge request !55
parents dbf4e49c 214bb31b
Branches
1 merge request!55dev#160166 : adding getcwd to fileSystem
Pipeline #24856 passed with stage
in 39 seconds
......@@ -58,4 +58,5 @@ abstract class Storm_FileSystem_Abstract {
abstract public function fopen(string $filename, string $mode, bool $use_include_path=false, $context=null);
abstract public function getcwd() :string;
}
......@@ -35,6 +35,11 @@ class Storm_FileSystem_Disk extends Storm_FileSystem_Abstract {
}
public function getcwd() :string {
return getcwd();
}
public function fileExists($path) {
return file_exists($path);
}
......
......@@ -143,6 +143,19 @@ class Storm_FileSystem_Volatile extends Storm_FileSystem_Abstract {
}
public function getcwd() :string {
if (! $this->_current_directory->getParent())
return '/';
$directories = [ $this->_current_directory->getName()];
$parent_dir = $this->_current_directory;
while ($parent_dir = $parent_dir->getParent())
array_unshift ($directories, $parent_dir->getName());
return implode('/', $directories);
}
public function readfile(string $path) {
if (!$this->isReadable($path))
return false;
......@@ -322,6 +335,11 @@ abstract class Storm_FileSystem_Volatile_Entry {
}
public function getParent() :?self {
return $this->_parent;
}
public function getRoot() {
return $this->_parent ? $this->_parent->getRoot() : $this;
}
......
......@@ -134,4 +134,10 @@ class Storm_FileSystem_DiskBasicTest extends Storm_FileSystem_DiskTestCase {
$this->_fs->rmdir($this->_directory .'/'. $this->_subdirectory);
$this->assertFalse($this->_fs->fileExists($this->_directory .'/'. $this->_subdirectory));
}
/** @test */
public function getcwdShouldContainsBasenameToCurrentFile() {
$this->assertContains('storm', $this->_fs->getcwd());
}
}
......@@ -327,3 +327,20 @@ class Storm_FileSystem_VolatileReadfileTest extends Storm_FileSystem_VolatileTes
$this->assertEquals('>>>> Mega super content <<<<', $this->_buffer);
}
}
class Storm_FileSystem_VolatileGetcwdTest extends Storm_FileSystem_VolatileTestCase {
/** @test */
public function getcwdShouldReturnExpectedValue() {
$this->assertEquals('/', $this->_fs->getcwd());
}
/** @test */
public function withDirGetcwdShouldReturnDir() {
$this->_fs->mkdir('dir')->cd('dir');
$this->assertEquals('/dir', $this->_fs->getcwd());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment