-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make paths absolute before scanning (#301)
- Loading branch information
Showing
15 changed files
with
194 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\File; | ||
|
||
class FileHelper | ||
{ | ||
|
||
/** | ||
* @param string $path The path of an item. | ||
* @param string $basePath The absolute base path. | ||
* @return string The absolute path of the given item. | ||
*/ | ||
public static function toAbsolutePath(string $path, string $basePath): string | ||
{ | ||
$path = \trim($path); | ||
|
||
if (0 === \strpos($path, '/')) { | ||
return $path; | ||
} | ||
|
||
if ('\\' === $path[0] || (\strlen($path) >= 3 && \preg_match('#^[A-Z]\:[/\\\]#i', \substr($path, 0, 3)))) { | ||
return $path; | ||
} | ||
|
||
if (false !== \strpos($path, '://')) { | ||
return $path; | ||
} | ||
|
||
return $basePath . '/' . $path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Tests\Unit\Configuration; | ||
|
||
use Churn\Configuration\Config; | ||
use Churn\Configuration\Loader; | ||
use Churn\Tests\BaseTestCase; | ||
use InvalidArgumentException; | ||
|
||
class LoaderTest extends BaseTestCase | ||
{ | ||
/** @test */ | ||
public function it_returns_the_default_values_if_there_is_no_default_file() | ||
{ | ||
$config = Loader::fromPath('non-existing-config-file.yml', true); | ||
|
||
$this->assertEquals(Config::createFromDefaultValues(), $config); | ||
$this->assertNull($config->getPath()); | ||
} | ||
|
||
/** @test */ | ||
public function it_throws_if_the_chosen_file_is_missing() | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$config = Loader::fromPath('non-existing-config-file.yml', false); | ||
} | ||
} |
Oops, something went wrong.