-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
7773a0d
commit 01e36ed
Showing
3 changed files
with
88 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GacelaTest\Unit\Framework\Container; | ||
|
||
use Gacela\Framework\Config; | ||
use Gacela\Framework\Config\ConfigReaderInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ConfigTest extends TestCase | ||
{ | ||
private Config $config; | ||
|
||
public function setUp(): void | ||
{ | ||
Config::resetInstance(); | ||
$this->config = Config::getInstance(); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
Config::resetInstance(); | ||
} | ||
|
||
public function test_get_undefined_key(): void | ||
{ | ||
$this->expectExceptionMessageMatches('/Could not find config key "key"/'); | ||
$this->config->get('key'); | ||
} | ||
|
||
public function test_get_default_value_from_undefined_key(): void | ||
{ | ||
self::assertSame('default', $this->config->get('key', 'default')); | ||
} | ||
|
||
public function test_get_using_custom_reader(): void | ||
{ | ||
$this->config->setConfigReaders([ | ||
Config\GacelaJsonConfigItem::DEFAULT_TYPE => new class() implements ConfigReaderInterface { | ||
public function read(string $absolutePath): array | ||
{ | ||
return ['key' => 'value']; | ||
} | ||
|
||
public function canRead(string $absolutePath): bool | ||
{ | ||
return true; | ||
} | ||
}, | ||
]); | ||
|
||
$this->config->init(); | ||
|
||
self::assertSame('value', $this->config->get('key')); | ||
} | ||
} |