Skip to content

Commit c63ee87

Browse files
authored
Merge pull request #1352 from hydephp/clean-up-and-refactor-internal-bootstrapper-class
Clean up and refactor the internal LoadYamlConfiguration test
2 parents 8f046ed + bbf476d commit c63ee87

File tree

2 files changed

+73
-14
lines changed

2 files changed

+73
-14
lines changed

packages/framework/src/Foundation/Internal/LoadYamlConfiguration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
use function file_exists;
1414

1515
/**
16-
* @internal
16+
* @internal Bootstrap service that loads the YAML configuration file.
17+
*
18+
* @see docs/digging-deeper/customization.md#yaml-configuration
1719
*/
1820
class LoadYamlConfiguration
1921
{

packages/framework/tests/Feature/LoadYamlConfigurationTest.php

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,97 @@
1515
*/
1616
class LoadYamlConfigurationTest extends TestCase
1717
{
18-
public function test_bootstrapper_applies_yaml_configuration_when_present()
18+
public function testCanDefineHydeConfigSettingsInHydeYmlFile()
19+
{
20+
config(['hyde' => []]);
21+
22+
$this->file('hyde.yml', <<<'YAML'
23+
name: HydePHP
24+
url: "http://localhost"
25+
pretty_urls: false
26+
generate_sitemap: true
27+
rss:
28+
enabled: true
29+
filename: feed.xml
30+
description: HydePHP RSS Feed
31+
language: en
32+
output_directory: _site
33+
YAML);
34+
$this->runBootstrapper();
35+
36+
$this->assertSame('HydePHP', Config::get('hyde.name'));
37+
$this->assertSame('http://localhost', Config::get('hyde.url'));
38+
$this->assertSame(false, Config::get('hyde.pretty_urls'));
39+
$this->assertSame(true, Config::get('hyde.generate_sitemap'));
40+
$this->assertSame(true, Config::get('hyde.rss.enabled'));
41+
$this->assertSame('feed.xml', Config::get('hyde.rss.filename'));
42+
$this->assertSame('HydePHP RSS Feed', Config::get('hyde.rss.description'));
43+
$this->assertSame('en', Config::get('hyde.language'));
44+
$this->assertSame('_site', Config::get('hyde.output_directory'));
45+
}
46+
47+
public function testBootstrapperAppliesYamlConfigurationWhenPresent()
1948
{
20-
$this->assertSame('HydePHP', config('hyde.name'));
2149
$this->file('hyde.yml', 'name: Foo');
22-
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
50+
$this->runBootstrapper();
51+
2352
$this->assertSame('Foo', config('hyde.name'));
2453
}
2554

26-
public function test_changes_in_yaml_file_override_changes_in_site_config()
55+
public function testChangesInYamlFileOverrideChangesInHydeConfig()
2756
{
28-
$this->assertSame('HydePHP', Config::get('hyde.name'));
2957
$this->file('hyde.yml', 'name: Foo');
30-
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
58+
$this->runBootstrapper();
59+
3160
$this->assertSame('Foo', Config::get('hyde.name'));
3261
}
3362

34-
public function test_changes_in_yaml_file_override_changes_in_site_config_when_using_yaml_extension()
63+
public function testChangesInYamlFileOverrideChangesInHydeConfigWhenUsingYamlExtension()
3564
{
36-
$this->assertSame('HydePHP', Config::get('hyde.name'));
3765
$this->file('hyde.yaml', 'name: Foo');
38-
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
66+
$this->runBootstrapper();
67+
3968
$this->assertSame('Foo', Config::get('hyde.name'));
4069
}
4170

42-
public function test_service_gracefully_handles_missing_file()
71+
public function testServiceGracefullyHandlesMissingFile()
4372
{
44-
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
73+
$this->runBootstrapper();
74+
4575
$this->assertSame('HydePHP', Config::get('hyde.name'));
4676
}
4777

48-
public function test_service_gracefully_handles_empty_file()
78+
public function testServiceGracefullyHandlesEmptyFile()
4979
{
5080
$this->file('hyde.yml', '');
51-
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
81+
$this->runBootstrapper();
82+
5283
$this->assertSame('HydePHP', Config::get('hyde.name'));
5384
}
85+
86+
public function testCanAddArbitraryConfigKeys()
87+
{
88+
$this->file('hyde.yml', 'foo: bar');
89+
$this->runBootstrapper();
90+
91+
$this->assertSame('bar', Config::get('hyde.foo'));
92+
}
93+
94+
public function testConfigurationOptionsAreMerged()
95+
{
96+
config(['hyde' => [
97+
'foo' => 'bar',
98+
'baz' => 'qux',
99+
]]);
100+
101+
$this->file('hyde.yml', 'baz: hat');
102+
$this->runBootstrapper();
103+
104+
$this->assertSame('bar', Config::get('hyde.foo'));
105+
}
106+
107+
protected function runBootstrapper(): void
108+
{
109+
$this->app->bootstrapWith([LoadYamlConfiguration::class]);
110+
}
54111
}

0 commit comments

Comments
 (0)