-
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.
Merge pull request #2 from sirn-se/v1.2
V1.2
- Loading branch information
Showing
16 changed files
with
177 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Phrity\Config; | ||
|
||
class DataReader implements ReaderInterface | ||
{ | ||
protected string $class; | ||
|
||
public function __construct(string $class = Configuration::class) | ||
{ | ||
$this->class = $class; | ||
} | ||
|
||
public function createConfiguration(object|array|null $data = null): ConfigurationInterface | ||
{ | ||
return new $this->class($data ?? []); | ||
} | ||
} |
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
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phrity\Config; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Phrity\Config\Test\TestConfiguration; | ||
|
||
class DataReaderTest extends TestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$GLOBALS['class_exists'] = true; | ||
$GLOBALS['is_readable'] = true; | ||
} | ||
|
||
public function testDataReader(): void | ||
{ | ||
$reader = new DataReader(); | ||
$this->assertInstanceOf(DataReader::class, $reader); | ||
$this->assertInstanceOf(ReaderInterface::class, $reader); | ||
|
||
$config = $reader->createConfiguration(); | ||
$this->assertInstanceOf(Configuration::class, $config); | ||
} | ||
|
||
public function testDataReaderParse(): void | ||
{ | ||
$json = '{"A": "A", "B": "B"}'; | ||
$reader = new DataReader(); | ||
$config = $reader->createConfiguration(data: ['a' => 'A', 'b' => 'B']); | ||
$this->assertEquals((object)[ | ||
'a' => 'A', | ||
'b' => 'B' | ||
], $config->jsonSerialize()); | ||
} | ||
|
||
public function testDataReaderClass(): void | ||
{ | ||
$reader = new DataReader(class: TestConfiguration::class); | ||
$config = $reader->createConfiguration(); | ||
$this->assertInstanceOf(TestConfiguration::class, $config); | ||
} | ||
} |
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
Oops, something went wrong.