Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Created February 14, 2013 14:50
Show Gist options
  • Select an option

  • Save mageekguy/4953283 to your computer and use it in GitHub Desktop.

Select an option

Save mageekguy/4953283 to your computer and use it in GitHub Desktop.
<?php
namespace tests\units;
require __DIR__ . '/../runner.php';
use
atoum,
path as testedClass
;
class path extends atoum
{
public function test__construct()
{
$this
->if($path = new testedClass($aPath = '/'))
->then
->castToString($path)->isEqualTo($aPath)
->if($path = new testedClass($aPath = '/' . uniqid()))
->then
->castToString($path)->isEqualTo($aPath)
->if($path = new testedClass(($aPath = '/' . uniqid()) . '/'))
->then
->castToString($path)->isEqualTo($aPath)
->if($path = new testedClass($aPath = uniqid()))
->then
->castToString($path)->isEqualTo(getcwd() . '/' . $aPath)
->if($path = new testedClass($aPath = uniqid() . '/' . uniqid()))
->then
->castToString($path)->isEqualTo(getcwd() . '/' . $aPath)
;
}
public function testGetRelativePathFrom()
{
$this
->if($path = new testedClass('/toto/tutu'))
->then
->string($path->getRelativePathFrom(clone $path))->isEqualTo('.')
->string($path->getRelativePathFrom(new testedClass('/toto')))->isEqualTo('./tutu')
->string($path->getRelativePathFrom(new testedClass('/toto/')))->isEqualTo('./tutu')
->string($path->getRelativePathFrom(new testedClass('/tata')))->isEqualTo('../toto/tutu')
->string($path->getRelativePathFrom(new testedClass('/tata/')))->isEqualTo('../toto/tutu')
->string($path->getRelativePathFrom(new testedClass('/tata/titi')))->isEqualTo('../../toto/tutu')
->string($path->getRelativePathFrom(new testedClass('/tata/titi/')))->isEqualTo('../../toto/tutu')
->string($path->getRelativePathFrom(new testedClass('/')))->isEqualTo('/toto/tutu')
->if($path = new testedClass('/toto/tutu/titi/webloc2.lan/framework/path.class.php'))
->then
->string($path->getRelativePathFrom(new testedClass('/toto/tutu/titi/webloc2.lan/private/cache')))->isEqualTo('../../framework/path.class.php')
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment