File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed
tests/HelperFunctions/filesystem Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Symfony \Component \Filesystem \Filesystem ;
4+
5+ if (!function_exists ('relative_path ' )) {
6+ function relative_path ($ to , $ from )
7+ {
8+ return (new Filesystem )->makePathRelative (realpath ($ to ), realpath ($ from ));
9+ }
10+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Illuminated \Helpers \HelperFunctions \Tests \FileSystem ;
4+
5+ use Illuminated \Helpers \HelperFunctions \Tests \TestCase ;
6+
7+ class RelativePathTest extends TestCase
8+ {
9+ /** @test */
10+ public function it_returns_relative_path_for_two_folders ()
11+ {
12+ $ path1 = realpath (__DIR__ . '/../../../src/ ' );
13+ $ path2 = realpath (__DIR__ . '/../../../tests/HelperFunctions/filesystem ' );
14+
15+ $ this ->assertEquals ('../../../src/ ' , relative_path ($ path1 , $ path2 ));
16+ }
17+
18+ /** @test */
19+ public function it_correctly_works_with_params_which_are_relative_paths ()
20+ {
21+ $ path1 = __DIR__ . '/../../../src/ ' ;
22+ $ path2 = __DIR__ . '/../../../tests/HelperFunctions/filesystem ' ;
23+
24+ $ this ->assertEquals ('../../../src/ ' , relative_path ($ path1 , $ path2 ));
25+ }
26+
27+ /** @test */
28+ public function it_correctly_works_for_the_same_folder ()
29+ {
30+ $ path1 = __DIR__ ;
31+ $ path2 = __DIR__ ;
32+
33+ $ this ->assertEquals ('./ ' , relative_path ($ path1 , $ path2 ));
34+ }
35+
36+ /** @test */
37+ public function even_if_the_paths_are_relative_and_different ()
38+ {
39+ $ path1 = __DIR__ ;
40+ $ path2 = __DIR__ . '/../../../tests/HelperFunctions/filesystem ' ;
41+
42+ $ this ->assertEquals ('./ ' , relative_path ($ path1 , $ path2 ));
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments