RelativePathComputerTest::testComputingToParent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Admingenerator\GeneratorBundle\Tests\Filesystem;
3
4
use Admingenerator\GeneratorBundle\Filesystem\RelativePathComputer;
5
6
/**
7
 * Class RelativePathComputerTest
8
 * @package Admingenerator\GeneratorBundle\Tests\Filesystem
9
 * @author Stéphane Escandell
10
 */
11
class RelativePathComputerTest extends \PHPUnit_Framework_TestCase
12
{
13
    public function testComputingToParent()
14
    {
15
        $referencePath = __FILE__;
16
17
        $computer = new RelativePathComputer($referencePath);
18
        $this->assertEquals(str_repeat('..' . DIRECTORY_SEPARATOR, 1), $computer->computeToParent(dirname($referencePath)));
19
        $this->assertEquals(str_repeat('..' . DIRECTORY_SEPARATOR, 3), $computer->computeToParent(dirname(dirname(dirname($referencePath)))));
20
21
        $referencePath = dirname($referencePath);
22
        $computer = new RelativePathComputer($referencePath);
23
        $this->assertEquals(str_repeat('..' . DIRECTORY_SEPARATOR, 1), $computer->computeToParent(dirname($referencePath)));
24
        $this->assertEquals(str_repeat('..' . DIRECTORY_SEPARATOR, 3), $computer->computeToParent(dirname(dirname(dirname($referencePath)))));
25
    }
26
27
    public function testExceptionThrowIfNotParent()
28
    {
29
        $computer = new RelativePathComputer(__FILE__);
30
        $this->setExpectedException('\LogicException');
31
32
        $computer->computeToParent(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fake');
33
    }
34
}
35