-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
133 additions
and
114 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
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <kevin@herrera.io> | ||
* Théo Fidry <theo.fidry@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Console; | ||
|
||
use function file_exists; | ||
use KevinGH\Box\Configuration\NoConfigurationFound; | ||
use KevinGH\Box\NotInstantiable; | ||
use function realpath; | ||
|
||
/** | ||
* @private | ||
*/ | ||
final class ConfigurationLocator | ||
{ | ||
use NotInstantiable; | ||
|
||
private const FILE_NAME = 'box.json'; | ||
|
||
/** | ||
* @var list<non-empty-string> | ||
*/ | ||
private static array $candidates; | ||
|
||
public static function findDefaultPath(): string | ||
{ | ||
if (!isset(self::$candidates)) { | ||
self::$candidates = [ | ||
self::FILE_NAME, | ||
self::FILE_NAME.'.dist', | ||
]; | ||
} | ||
|
||
foreach (self::$candidates as $candidate) { | ||
if (file_exists($candidate)) { | ||
return realpath($candidate); | ||
} | ||
} | ||
|
||
throw new NoConfigurationFound(); | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <kevin@herrera.io> | ||
* Théo Fidry <theo.fidry@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Configuration; | ||
|
||
use function KevinGH\Box\FileSystem\dump_file; | ||
use function KevinGH\Box\FileSystem\touch; | ||
use KevinGH\Box\Test\FileSystemTestCase; | ||
|
||
/** | ||
* @covers \KevinGH\Box\Configuration\ConfigurationLoader | ||
*/ | ||
class ConfigurationLoaderTest extends FileSystemTestCase | ||
{ | ||
private ConfigurationLoader $loader; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->loader = new ConfigurationLoader(); | ||
} | ||
|
||
public function test_it_can_load_a_configuration(): void | ||
{ | ||
touch('index.php'); | ||
dump_file('box.json.dist', '{}'); | ||
|
||
$this->assertInstanceOf( | ||
Configuration::class, | ||
$this->loader->loadFile('box.json.dist'), | ||
); | ||
} | ||
|
||
public function test_it_can_load_a_configuration_without_a_file(): void | ||
{ | ||
touch('index.php'); | ||
|
||
$this->assertInstanceOf( | ||
Configuration::class, | ||
$this->loader->loadFile(null), | ||
); | ||
} | ||
} |
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
Oops, something went wrong.