Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #264 from lemberg/fix/no-config_update-3_6_0
Browse files Browse the repository at this point in the history
Trigger config update after 3.6.0
  • Loading branch information
T2L authored Jul 7, 2022
2 parents dc6c76f + 96be356 commit ee0ff2d
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
28 changes: 28 additions & 0 deletions src/Config/Update/Step/DefaultConfigUpdate30600.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Lemberg\Draft\Environment\Config\Update\Step;

use Lemberg\Draft\Environment\Config\Update\UpdateStepInterface;

/**
* Cleanup project for the 3.6.0.
*/
final class DefaultConfigUpdate30600 extends AbstractUpdateStep implements UpdateStepInterface {

/**
* {@inheritdoc}
*/
public function getWeight(): int {
return 13;
}

/**
* {@inheritdoc}
*/
public function update(array &$config): void {
// Empty update will trigger updating configuration.
}

}
6 changes: 3 additions & 3 deletions tests/Unit/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function writeConfigToTheFileDataProvider(): array {
return [
[
"# One\none:\n # Two\n two: two",
"# One\none:\n # Two\n two: 2",
"# One\none:\n # Two\n two: 2\n",
[
'one' => [
'two' => 2,
Expand All @@ -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',
Expand Down
121 changes: 121 additions & 0 deletions tests/Unit/Config/Update/Step/DefaultConfigUpdate30600Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

declare(strict_types=1);

namespace Lemberg\Tests\Unit\Draft\Environment\Config\Update\Step;

use Composer\Autoload\ClassLoader;
use Composer\Composer;
use Composer\Config as ComposerConfig;
use Composer\IO\IOInterface;
use Lemberg\Draft\Environment\Config\Config;
use Lemberg\Draft\Environment\Config\Manager\UpdateManager;
use Lemberg\Draft\Environment\Config\Update\Step\DefaultConfigUpdate30600;
use Lemberg\Draft\Environment\Utility\Filesystem;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;

/**
* Tests updating PHP configuration.
*
* @covers \Lemberg\Draft\Environment\Config\Update\Step\AbstractUpdateStep
* @covers \Lemberg\Draft\Environment\Config\Update\Step\DefaultConfigUpdate30600
*/
final class DefaultConfigUpdate30600Test extends TestCase {

/**
* @var \Composer\Composer
*/
protected $composer;

/**
* @var \Composer\IO\IOInterface
*/
protected $io;

/**
* @var string
*/
protected $root;

/**
* @var \Lemberg\Draft\Environment\Config\Manager\UpdateManagerInterface
*/
protected $configUpdateManager;

/**
* {@inheritdoc}
*/
protected function setUp(): void {
$this->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<string,mixed> $config
* @param array<string,mixed> $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<int,array<int,string|array<string,mixed>>>
*/
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',
],
],
],
],
];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ final public function updateDataProvider(): array {
# Comment Z
- z
aa: 34
EOT;

$configA = [
Expand Down Expand Up @@ -252,6 +253,7 @@ final public function updateDataProvider(): array {
bb:
cc: dd
new: new
EOT;

return [
Expand Down

0 comments on commit ee0ff2d

Please sign in to comment.