|
15 | 15 | */ |
16 | 16 | class LoadYamlConfigurationTest extends TestCase |
17 | 17 | { |
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() |
19 | 48 | { |
20 | | - $this->assertSame('HydePHP', config('hyde.name')); |
21 | 49 | $this->file('hyde.yml', 'name: Foo'); |
22 | | - $this->app->bootstrapWith([LoadYamlConfiguration::class]); |
| 50 | + $this->runBootstrapper(); |
| 51 | + |
23 | 52 | $this->assertSame('Foo', config('hyde.name')); |
24 | 53 | } |
25 | 54 |
|
26 | | - public function test_changes_in_yaml_file_override_changes_in_site_config() |
| 55 | + public function testChangesInYamlFileOverrideChangesInHydeConfig() |
27 | 56 | { |
28 | | - $this->assertSame('HydePHP', Config::get('hyde.name')); |
29 | 57 | $this->file('hyde.yml', 'name: Foo'); |
30 | | - $this->app->bootstrapWith([LoadYamlConfiguration::class]); |
| 58 | + $this->runBootstrapper(); |
| 59 | + |
31 | 60 | $this->assertSame('Foo', Config::get('hyde.name')); |
32 | 61 | } |
33 | 62 |
|
34 | | - public function test_changes_in_yaml_file_override_changes_in_site_config_when_using_yaml_extension() |
| 63 | + public function testChangesInYamlFileOverrideChangesInHydeConfigWhenUsingYamlExtension() |
35 | 64 | { |
36 | | - $this->assertSame('HydePHP', Config::get('hyde.name')); |
37 | 65 | $this->file('hyde.yaml', 'name: Foo'); |
38 | | - $this->app->bootstrapWith([LoadYamlConfiguration::class]); |
| 66 | + $this->runBootstrapper(); |
| 67 | + |
39 | 68 | $this->assertSame('Foo', Config::get('hyde.name')); |
40 | 69 | } |
41 | 70 |
|
42 | | - public function test_service_gracefully_handles_missing_file() |
| 71 | + public function testServiceGracefullyHandlesMissingFile() |
43 | 72 | { |
44 | | - $this->app->bootstrapWith([LoadYamlConfiguration::class]); |
| 73 | + $this->runBootstrapper(); |
| 74 | + |
45 | 75 | $this->assertSame('HydePHP', Config::get('hyde.name')); |
46 | 76 | } |
47 | 77 |
|
48 | | - public function test_service_gracefully_handles_empty_file() |
| 78 | + public function testServiceGracefullyHandlesEmptyFile() |
49 | 79 | { |
50 | 80 | $this->file('hyde.yml', ''); |
51 | | - $this->app->bootstrapWith([LoadYamlConfiguration::class]); |
| 81 | + $this->runBootstrapper(); |
| 82 | + |
52 | 83 | $this->assertSame('HydePHP', Config::get('hyde.name')); |
53 | 84 | } |
| 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 | + } |
54 | 111 | } |
0 commit comments