Skip to content

Commit

Permalink
[Filesystem] Added unit tests for makePathRelative method.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Apr 6, 2012
1 parent 21860cb commit 2ee4b88
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Symfony/Component/Filesystem/Tests/FilesystemTest.php
Expand Up @@ -410,6 +410,37 @@ public function testSymlinkIsNotOverwrittenIfAlreadyCreated()
$this->assertEquals($file, readlink($link));
}

/**
* @dataProvider provideAbsolutePaths
*/
public function testMakePathRelative($endPath, $startPath, $expectedPath)
{
$path = $this->filesystem->makePathRelative($endPath, $startPath);

$this->assertEquals($expectedPath, $path);
}

/**
* @return array
*/
public function provideAbsolutePaths()
{
$paths = array(
array('/var/lib/symfony/src/Symfony/', '/var/lib/symfony/src/Symfony/Component', '../'),
array('var/lib/symfony/', 'var/lib/symfony/src/Symfony/Component', '../../../'),
array('/usr/lib/symfony/', '/var/lib/symfony/src/Symfony/Component', '../../../../../../usr/lib/symfony/')
);

// fix directory separator
foreach ($paths as $i => $pathItems) {
foreach ($pathItems as $k => $path) {
$paths[$i][$k] = str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}

return $paths;
}

/**
* Returns file permissions as three digits (i.e. 755)
*
Expand Down

0 comments on commit 2ee4b88

Please sign in to comment.