Skip to content

Commit 01ee403

Browse files
Edit the helpers
1 parent 43778b9 commit 01ee403

4 files changed

Lines changed: 24 additions & 10 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"Hackphp\\Config\\": "src/"
99
},
1010
"files": [
11-
"tests/helpers.php"
11+
"src/helpers.php"
1212
]
1313
},
1414
"autoload-dev": {

src/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
*/
99
function configPath($path = null)
1010
{
11-
$dir = __DIR__ . "/config";
11+
$dir = __DIR__ . "/../config";
1212

1313
if ($path) {
1414
$dir .= "/" . $path;
1515
}
16-
16+
1717
return $dir;
1818
}
1919
}

tests/ConfigTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
namespace Hackphp\Config\Tests;
44

55
use Hackphp\Config\Config;
6-
use Hackphp\Config\Parsers\ArrayParser;
76
use PHPUnit\Framework\TestCase;
7+
use Hackphp\Config\Parsers\ArrayParser;
88

99
class ConfigTest extends TestCase
1010
{
11+
protected string $configPath;
12+
13+
protected function setUp(): void
14+
{
15+
$this->configPath = __DIR__ . "/config";
16+
}
17+
1118
/** @test */
1219
public function it_can_create_instance_with_default_configs()
1320
{
@@ -24,7 +31,7 @@ public function it_can_create_instance_with_default_configs()
2431
/** @test */
2532
public function it_loads_and_parse_all_directory_files_successfully()
2633
{
27-
$parser = new ArrayParser(configPath());
34+
$parser = new ArrayParser($this->configPath);
2835

2936
$config = new Config();
3037
$config->addParser($parser);
@@ -37,7 +44,7 @@ public function it_loads_and_parse_all_directory_files_successfully()
3744
/** @test */
3845
public function it_loads_the_default_value_if_the_key_not_found()
3946
{
40-
$parser = new ArrayParser(configPath());
47+
$parser = new ArrayParser($this->configPath);
4148

4249
$config = new Config();
4350
$config->addParser($parser);

tests/Parsers/ArrayParserTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22

33
namespace Hackphp\Config\Tests\Parsers;
44

5+
use PHPUnit\Framework\TestCase;
56
use Hackphp\Config\Contracts\Parser;
67
use Hackphp\Config\Parsers\ArrayParser;
7-
use PHPUnit\Framework\TestCase;
88

99
class ArrayParserTest extends TestCase
1010
{
11+
protected string $configPath;
12+
13+
protected function setUp(): void
14+
{
15+
$this->configPath = __DIR__ . "/../config";
16+
}
17+
1118
/** @test */
1219
public function it_must_be_instance_of_parser_interface()
1320
{
14-
$parser = new ArrayParser(configPath());
21+
$parser = new ArrayParser($this->configPath);
1522

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

1926
/** @test */
2027
public function it_parses_files_from_the_given_directory()
2128
{
22-
$parser = new ArrayParser(configPath("server"));
29+
$parser = new ArrayParser($this->configPath . "/server");
2330
$parsed = $parser->parse();
2431

2532
$expected = [
@@ -35,7 +42,7 @@ public function it_parses_files_from_the_given_directory()
3542
/** @test */
3643
public function it_can_parse_nested_files()
3744
{
38-
$parser = new ArrayParser(configPath());
45+
$parser = new ArrayParser($this->configPath);
3946
$parsed = $parser->parse();
4047

4148
$expected = [

0 commit comments

Comments
 (0)