|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | +namespace Helhum\TYPO3\ConfigHandling\Tests\Unit; |
| 4 | + |
| 5 | +use Helhum\TYPO3\ConfigHandling\ConfigDumper; |
| 6 | +use Helhum\TYPO3\ConfigHandling\Processor\RemoveSettingsProcessor; |
| 7 | +use org\bovigo\vfs\vfsStream; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class ConfigDumperTest extends TestCase |
| 11 | +{ |
| 12 | + /** |
| 13 | + * @test |
| 14 | + */ |
| 15 | + public function dumpingEmptyArrayProducesYamlWithEmptyArray(): void |
| 16 | + { |
| 17 | + vfsStream::setup(); |
| 18 | + $root = vfsStream::url('root'); |
| 19 | + $settingsFile = $root . '/settings.yaml'; |
| 20 | + $configDumper = new ConfigDumper(); |
| 21 | + $configDumper->dumpToFile( |
| 22 | + [], |
| 23 | + $settingsFile |
| 24 | + ); |
| 25 | + self::assertSame( |
| 26 | + '{ }', |
| 27 | + file_get_contents($settingsFile), |
| 28 | + ); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @test |
| 33 | + */ |
| 34 | + public function dumpingConfigWithOnlyProcessorConfigDoesProduceValidYaml(): void |
| 35 | + { |
| 36 | + vfsStream::setup(); |
| 37 | + $root = vfsStream::url('root'); |
| 38 | + $settingsFile = $root . '/settings.yaml'; |
| 39 | + $configDumper = new ConfigDumper(); |
| 40 | + $configDumper->dumpToFile( |
| 41 | + [ |
| 42 | + 'processors' => [ |
| 43 | + 'foo' => [ |
| 44 | + 'class' => RemoveSettingsProcessor::class, |
| 45 | + 'paths' => [ |
| 46 | + '"SYS"."sqlDebug"', |
| 47 | + ], |
| 48 | + ], |
| 49 | + ], |
| 50 | + ], |
| 51 | + $settingsFile |
| 52 | + ); |
| 53 | + self::assertSame( |
| 54 | + 'processors:' . chr(10) . ' foo: { class: Helhum\TYPO3\ConfigHandling\Processor\RemoveSettingsProcessor, paths: [\'"SYS"."sqlDebug"\'] }' . chr(10) . chr(10), |
| 55 | + file_get_contents($settingsFile), |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @test |
| 61 | + */ |
| 62 | + public function dumpingConfigWithOnlyImportConfigDoesProduceValidYaml(): void |
| 63 | + { |
| 64 | + vfsStream::setup(); |
| 65 | + $root = vfsStream::url('root'); |
| 66 | + $settingsFile = $root . '/settings.yaml'; |
| 67 | + $configDumper = new ConfigDumper(); |
| 68 | + $configDumper->dumpToFile( |
| 69 | + [ |
| 70 | + 'imports' => [ |
| 71 | + [ |
| 72 | + 'resource' => 'foo.yaml', |
| 73 | + ], |
| 74 | + ], |
| 75 | + ], |
| 76 | + $settingsFile |
| 77 | + ); |
| 78 | + self::assertSame( |
| 79 | + 'imports:' . chr(10) . ' - { resource: foo.yaml }' . chr(10) . chr(10), |
| 80 | + file_get_contents($settingsFile), |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @test |
| 86 | + */ |
| 87 | + public function dumpingConfigWithImportAndProcessorsProduceNiceOutput(): void |
| 88 | + { |
| 89 | + vfsStream::setup(); |
| 90 | + $root = vfsStream::url('root'); |
| 91 | + $settingsFile = $root . '/settings.yaml'; |
| 92 | + $configDumper = new ConfigDumper(); |
| 93 | + $configDumper->dumpToFile( |
| 94 | + [ |
| 95 | + 'processors' => [ |
| 96 | + 'foo' => [ |
| 97 | + 'class' => RemoveSettingsProcessor::class, |
| 98 | + 'paths' => [ |
| 99 | + '"SYS"."sqlDebug"', |
| 100 | + ], |
| 101 | + ], |
| 102 | + ], |
| 103 | + 'imports' => [ |
| 104 | + [ |
| 105 | + 'resource' => 'foo.yaml', |
| 106 | + ], |
| 107 | + ], |
| 108 | + 'foo' => 'bar' |
| 109 | + ], |
| 110 | + $settingsFile |
| 111 | + ); |
| 112 | + self::assertSame( |
| 113 | + 'imports:' . chr(10) . ' - { resource: foo.yaml }' . chr(10) . |
| 114 | + 'processors:' . chr(10) . ' foo: { class: Helhum\TYPO3\ConfigHandling\Processor\RemoveSettingsProcessor, paths: [\'"SYS"."sqlDebug"\'] }' . chr(10) . chr(10) . |
| 115 | + 'foo: bar' . chr(10), |
| 116 | + file_get_contents($settingsFile), |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * @test |
| 122 | + */ |
| 123 | + public function commentBlockIsAddedProperly(): void |
| 124 | + { |
| 125 | + vfsStream::setup(); |
| 126 | + $root = vfsStream::url('root'); |
| 127 | + $settingsFile = $root . '/settings.yaml'; |
| 128 | + $configDumper = new ConfigDumper(); |
| 129 | + $configDumper->dumpToFile( |
| 130 | + [ |
| 131 | + 'processors' => [ |
| 132 | + 'foo' => [ |
| 133 | + 'class' => RemoveSettingsProcessor::class, |
| 134 | + 'paths' => [ |
| 135 | + '"SYS"."sqlDebug"', |
| 136 | + ], |
| 137 | + ], |
| 138 | + ], |
| 139 | + 'imports' => [ |
| 140 | + [ |
| 141 | + 'resource' => 'foo.yaml', |
| 142 | + ], |
| 143 | + ], |
| 144 | + 'foo' => 'bar' |
| 145 | + ], |
| 146 | + $settingsFile, |
| 147 | + 'MY COMMENT' |
| 148 | + ); |
| 149 | + self::assertSame( |
| 150 | + '# MY COMMENT' . chr(10) . |
| 151 | + 'imports:' . chr(10) . ' - { resource: foo.yaml }' . chr(10) . |
| 152 | + 'processors:' . chr(10) . ' foo: { class: Helhum\TYPO3\ConfigHandling\Processor\RemoveSettingsProcessor, paths: [\'"SYS"."sqlDebug"\'] }' . chr(10) . chr(10) . |
| 153 | + 'foo: bar' . chr(10), |
| 154 | + file_get_contents($settingsFile), |
| 155 | + ); |
| 156 | + } |
| 157 | +} |
0 commit comments