Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/php-workshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none

- name: Install Dependencies
run: composer update --prefer-dist
Expand Down
19 changes: 19 additions & 0 deletions src/Utils/Path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace PhpSchool\PhpWorkshop\Utils;

class Path
{
public static function join(string $base, string ...$parts): string
{
return implode(
'/',
array_merge(
[rtrim($base, '/')],
array_map(function (string $part) {
return trim($part, '/');
}, $parts)
)
);
}
}
47 changes: 47 additions & 0 deletions test/Utils/PathTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace PhpSchool\PhpWorkshopTest\Util\s;

use PhpSchool\PhpWorkshop\Utils\Path;
use PHPUnit\Framework\TestCase;

class PathTest extends TestCase
{
public function testJoin(): void
{
$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path', 'some-folder/file.txt')
);

$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path/', 'some-folder/file.txt')
);

$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path', '/some-folder/file.txt')
);

$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path/', '/some-folder/file.txt')
);

$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path//', '//some-folder/file.txt')
);

$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path/', 'some-folder', 'file.txt')
);

$this->assertEquals(
'/some/path/some-folder/file.txt',
Path::join('/some/path/', '/some-folder/', '/file.txt')
);
}
}