diff --git a/CHANGELOG.md b/CHANGELOG.md index 705dd80..42cc6fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Draft Environment (Unreleased) + +- Trigger config update after version 3.6.0 + ## Draft Environment 3.6.0 (2022-07-07) - [GH-259](https://github.com/lemberg/draft-environment/pull/259) - Drop PHP7.3 and Composer 1 support; add support for 8.1; default to 8.0 diff --git a/src/Config/Config.php b/src/Config/Config.php index 66bd713..6367f01 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -183,7 +183,7 @@ public function writeConfigToTheFile(string $source, string $target, array $conf $commentManager = new Comments(); $commentManager->collect(explode("\n", $originalContent)); $alteredWithComments = $commentManager->inject(explode("\n", $alteredContent)); - $this->getFilesystem()->dumpFile($target, implode("\n", $alteredWithComments)); + $this->getFilesystem()->dumpFile($target, implode("\n", $alteredWithComments) . "\n"); } } diff --git a/src/Config/Update/Step/DefaultConfigUpdate30600.php b/src/Config/Update/Step/DefaultConfigUpdate30600.php new file mode 100644 index 0000000..ccf4600 --- /dev/null +++ b/src/Config/Update/Step/DefaultConfigUpdate30600.php @@ -0,0 +1,28 @@ + [ 'two' => 2, @@ -170,14 +170,14 @@ public function writeConfigToTheFileDataProvider(): array { ], [ "# One\none:\n # Two\n two: two", - "# One\none: one", + "# One\none: one\n", [ 'one' => 'one', ], ], [ "# One\none:\n # Two\n two: two", - "# One\none:\n # Two\n two: two\nthree: 3", + "# One\none:\n # Two\n two: two\nthree: 3\n", [ 'one' => [ 'two' => 'two', diff --git a/tests/Unit/Config/Update/Step/DefaultConfigUpdate30600Test.php b/tests/Unit/Config/Update/Step/DefaultConfigUpdate30600Test.php new file mode 100644 index 0000000..4b310b1 --- /dev/null +++ b/tests/Unit/Config/Update/Step/DefaultConfigUpdate30600Test.php @@ -0,0 +1,121 @@ +composer = new Composer(); + $this->composer->setConfig(new ComposerConfig()); + $this->io = $this->createMock(IOInterface::class); + + // Mock source and target configuration directories. + $this->root = vfsStream::setup()->url(); + $fs = new Filesystem(); + $fs->mkdir(["$this->root/source", "$this->root/target"]); + + $configObject = new Config("$this->root/source", "$this->root/target"); + $classLoader = new ClassLoader(); + $this->configUpdateManager = new UpdateManager($this->composer, $this->io, $configObject, $classLoader); + } + + /** + * Tests step weight getter. + */ + public function testGetWeight(): void { + $step = new DefaultConfigUpdate30600($this->composer, $this->io, $this->configUpdateManager); + self::assertSame(13, $step->getWeight()); + } + + /** + * Tests update step execution. + * + * @param array $config + * @param array $expectedConfig + * + * @dataProvider updateDataProvider + */ + public function testUpdate(array $config, array $expectedConfig): void { + $step = new DefaultConfigUpdate30600($this->composer, $this->io, $this->configUpdateManager); + + $step->update($config); + self::assertSame($expectedConfig, $config); + } + + /** + * Data provider for the ::testUpdate(). + * + * @return array>> + */ + public function updateDataProvider(): array { + return [ + [ + [], + [], + ], + [ + [ + 'ansible' => [], + 'virtualbox' => [], + 'php_extensions_configuration' => [ + 'opcache' => [ + 'opcache.error_log' => '/var/log/draft/php_opcache_error.log', + ], + ], + ], + [ + 'ansible' => [], + 'virtualbox' => [], + 'php_extensions_configuration' => [ + 'opcache' => [ + 'opcache.error_log' => '/var/log/draft/php_opcache_error.log', + ], + ], + ], + ], + ]; + } + +} diff --git a/tests/Unit/Config/Update/Step/ExportAllAvailableConfigurationTest.php b/tests/Unit/Config/Update/Step/ExportAllAvailableConfigurationTest.php index 05d3be5..d60d5d5 100644 --- a/tests/Unit/Config/Update/Step/ExportAllAvailableConfigurationTest.php +++ b/tests/Unit/Config/Update/Step/ExportAllAvailableConfigurationTest.php @@ -157,6 +157,7 @@ final public function updateDataProvider(): array { # Comment Z - z aa: 34 + EOT; $configA = [ @@ -252,6 +253,7 @@ final public function updateDataProvider(): array { bb: cc: dd new: new + EOT; return [