Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
* 1.x:
  [Feature] Add options expansion to Add Lines Configuration
  • Loading branch information
fabpot committed Feb 5, 2024
2 parents 6b44ac7 + 6b46a00 commit bec213c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Configurator/AddLinesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function executeConfigure(Recipe $recipe, $config): void
}
$content = $patch['content'];

$file = $this->path->concatenate([$this->options->get('root-dir'), $patch['file']]);
$file = $this->path->concatenate([$this->options->get('root-dir'), $this->options->expandTargetDir($patch['file'])]);
$warnIfMissing = isset($patch['warn_if_missing']) && $patch['warn_if_missing'];
if (!is_file($file)) {
$this->write([
Expand Down Expand Up @@ -147,7 +147,7 @@ public function executeUnconfigure(Recipe $recipe, $config): void
// Ignore "requires": the target packages may have just become uninstalled.
// Checking for a "content" match is enough.

$file = $this->path->concatenate([$this->options->get('root-dir'), $patch['file']]);
$file = $this->path->concatenate([$this->options->get('root-dir'), $this->options->expandTargetDir($patch['file'])]);
if (!is_file($file)) {
continue;
}
Expand Down
42 changes: 42 additions & 0 deletions tests/Configurator/AddLinesConfiguratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ public function testLinesAddedToTopOfFile()
$actualContents);
}

public function testExpandTargetDirWhenConfiguring()
{
$this->saveFile('config/file.txt', 'FirstLine');

$this->runConfigure([
[
'file' => '%CONFIG_DIR%/file.txt',
'position' => 'top',
'content' => 'NewFirstLine',
],
]);
$actualContents = $this->readFile('config/file.txt');
$this->assertSame(<<<EOF
NewFirstLine
FirstLine
EOF
,
$actualContents);
}

public function testLinesAddedToBottomOfFile()
{
$this->saveFile('assets/app.js', <<<EOF
Expand Down Expand Up @@ -318,6 +338,28 @@ public function testUnconfigure(string $originalContents, string $value, string
$this->assertSame($expectedContents, $actualContents);
}

public function testExpandTargetDirWhenUnconfiguring()
{
$this->saveFile('config/file.txt',
<<<EOF
Line1
Line2
EOF
);

$this->runUnconfigure([
[
'file' => '%CONFIG_DIR%/file.txt',
'content' => 'Line1',
],
]);
$actualContents = $this->readFile('config/file.txt');
$this->assertSame(<<<EOF
Line2
EOF
, $actualContents);
}

public function getUnconfigureTests()
{
yield 'found_middle' => [
Expand Down

0 comments on commit bec213c

Please sign in to comment.