-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
186 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpxCore. | ||
* | ||
* Copyright (c) Lozovoy Vyacheslav <opxcore@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpxCore\Tests\Config; | ||
|
||
use OpxCore\Config\Config; | ||
use OpxCore\Config\Exceptions\ConfigException; | ||
use OpxCore\Tests\Config\Fixtures\BadRepo; | ||
use OpxCore\Tests\Config\Fixtures\CacheLoadException; | ||
use OpxCore\Tests\Config\Fixtures\CacheSaveException; | ||
use OpxCore\Tests\Config\Fixtures\Repo; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BadConfigTest extends TestCase | ||
{ | ||
public function testBadRepo(): void | ||
{ | ||
$config = new Config(new BadRepo()); | ||
|
||
$this->expectException(ConfigException::class); | ||
|
||
$config->load(); | ||
} | ||
|
||
public function testCacheReadError(): void | ||
{ | ||
$repo = new Repo(['app' => ['name' => 'test']]); | ||
$cache = new CacheLoadException(); | ||
$config = new Config($repo, $cache); | ||
|
||
$this->expectException(ConfigException::class); | ||
$config->load(); | ||
} | ||
public function testCacheWriteError(): void | ||
{ | ||
$repo = new Repo(['app' => ['name' => 'test']]); | ||
$cache = new CacheSaveException(); | ||
$config = new Config($repo, $cache); | ||
|
||
$this->expectException(ConfigException::class); | ||
$config->load(); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpxCore. | ||
* | ||
* Copyright (c) Lozovoy Vyacheslav <opxcore@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpxCore\Tests\Config\Fixtures; | ||
|
||
use Error; | ||
use Exception; | ||
use OpxCore\Config\Exceptions\ConfigRepositoryException; | ||
use OpxCore\Config\Interfaces\ConfigRepositoryInterface; | ||
|
||
class BadRepo implements ConfigRepositoryInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
* @throws ConfigRepositoryException | ||
*/ | ||
public function load(array &$config, $profile = null, $overrides = null): bool | ||
{ | ||
try { | ||
$config = require __DIR__ . DIRECTORY_SEPARATOR . 'bad.php'; | ||
} catch (Exception | Error $e) { | ||
throw new ConfigRepositoryException("Error reading configuration file {$e->getFile()}:{$e->getLine()} {$e->getMessage()}"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function save(array $config, $profile = null): bool | ||
{ | ||
return true; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpxCore. | ||
* | ||
* Copyright (c) Lozovoy Vyacheslav <opxcore@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpxCore\Tests\Config\Fixtures; | ||
|
||
use OpxCore\Config\Exceptions\ConfigCacheException; | ||
use OpxCore\Config\Interfaces\ConfigCacheInterface; | ||
|
||
class CacheLoadException implements ConfigCacheInterface | ||
{ | ||
public array $config = []; | ||
|
||
public bool $expired = false; | ||
public ?string $profile = null; | ||
public ?int $ttl = null; | ||
|
||
public function load(array &$config, $profile = null): bool | ||
{ | ||
throw new ConfigCacheException('Load rejected'); | ||
} | ||
|
||
public function save(array $config, $profile = null, $ttl = null): bool | ||
{ | ||
$this->config = $config; | ||
$this->profile = $profile; | ||
$this->ttl = $ttl; | ||
|
||
return true; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpxCore. | ||
* | ||
* Copyright (c) Lozovoy Vyacheslav <opxcore@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace OpxCore\Tests\Config\Fixtures; | ||
|
||
use OpxCore\Config\Exceptions\ConfigCacheException; | ||
use OpxCore\Config\Interfaces\ConfigCacheInterface; | ||
|
||
class CacheSaveException implements ConfigCacheInterface | ||
{ | ||
public function load(array &$config, $profile = null): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function save(array $config, $profile = null, $ttl = null): bool | ||
{ | ||
throw new ConfigCacheException('Save rejected'); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
/* | ||
* This file is part of the OpxCore. | ||
* | ||
* Copyright (c) Lozovoy Vyacheslav <opxcore@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
return [ | ||
'app' => 'bad', | ||
e | ||
]; |