Skip to content

Commit

Permalink
Edit the helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-samir907 committed Aug 21, 2021
1 parent 43778b9 commit 01ee403
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Hackphp\\Config\\": "src/"
},
"files": [
"tests/helpers.php"
"src/helpers.php"
]
},
"autoload-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
*/
function configPath($path = null)
{
$dir = __DIR__ . "/config";
$dir = __DIR__ . "/../config";

if ($path) {
$dir .= "/" . $path;
}

return $dir;
}
}
Expand Down
13 changes: 10 additions & 3 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
namespace Hackphp\Config\Tests;

use Hackphp\Config\Config;
use Hackphp\Config\Parsers\ArrayParser;
use PHPUnit\Framework\TestCase;
use Hackphp\Config\Parsers\ArrayParser;

class ConfigTest extends TestCase
{
protected string $configPath;

protected function setUp(): void
{
$this->configPath = __DIR__ . "/config";
}

/** @test */
public function it_can_create_instance_with_default_configs()
{
Expand All @@ -24,7 +31,7 @@ public function it_can_create_instance_with_default_configs()
/** @test */
public function it_loads_and_parse_all_directory_files_successfully()
{
$parser = new ArrayParser(configPath());
$parser = new ArrayParser($this->configPath);

$config = new Config();
$config->addParser($parser);
Expand All @@ -37,7 +44,7 @@ public function it_loads_and_parse_all_directory_files_successfully()
/** @test */
public function it_loads_the_default_value_if_the_key_not_found()
{
$parser = new ArrayParser(configPath());
$parser = new ArrayParser($this->configPath);

$config = new Config();
$config->addParser($parser);
Expand Down
15 changes: 11 additions & 4 deletions tests/Parsers/ArrayParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@

namespace Hackphp\Config\Tests\Parsers;

use PHPUnit\Framework\TestCase;
use Hackphp\Config\Contracts\Parser;
use Hackphp\Config\Parsers\ArrayParser;
use PHPUnit\Framework\TestCase;

class ArrayParserTest extends TestCase
{
protected string $configPath;

protected function setUp(): void
{
$this->configPath = __DIR__ . "/../config";
}

/** @test */
public function it_must_be_instance_of_parser_interface()
{
$parser = new ArrayParser(configPath());
$parser = new ArrayParser($this->configPath);

$this->assertInstanceOf(Parser::class, $parser);
}

/** @test */
public function it_parses_files_from_the_given_directory()
{
$parser = new ArrayParser(configPath("server"));
$parser = new ArrayParser($this->configPath . "/server");
$parsed = $parser->parse();

$expected = [
Expand All @@ -35,7 +42,7 @@ public function it_parses_files_from_the_given_directory()
/** @test */
public function it_can_parse_nested_files()
{
$parser = new ArrayParser(configPath());
$parser = new ArrayParser($this->configPath);
$parsed = $parser->parse();

$expected = [
Expand Down

0 comments on commit 01ee403

Please sign in to comment.