Skip to content

Commit bec213c

Browse files
committed
Merge branch '1.x' into 2.x
* 1.x: [Feature] Add options expansion to Add Lines Configuration
2 parents 6b44ac7 + 6b46a00 commit bec213c

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Configurator/AddLinesConfigurator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function executeConfigure(Recipe $recipe, $config): void
9797
}
9898
$content = $patch['content'];
9999

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

150-
$file = $this->path->concatenate([$this->options->get('root-dir'), $patch['file']]);
150+
$file = $this->path->concatenate([$this->options->get('root-dir'), $this->options->expandTargetDir($patch['file'])]);
151151
if (!is_file($file)) {
152152
continue;
153153
}

tests/Configurator/AddLinesConfiguratorTest.php

+42
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ public function testLinesAddedToTopOfFile()
6767
$actualContents);
6868
}
6969

70+
public function testExpandTargetDirWhenConfiguring()
71+
{
72+
$this->saveFile('config/file.txt', 'FirstLine');
73+
74+
$this->runConfigure([
75+
[
76+
'file' => '%CONFIG_DIR%/file.txt',
77+
'position' => 'top',
78+
'content' => 'NewFirstLine',
79+
],
80+
]);
81+
$actualContents = $this->readFile('config/file.txt');
82+
$this->assertSame(<<<EOF
83+
NewFirstLine
84+
FirstLine
85+
EOF
86+
,
87+
$actualContents);
88+
}
89+
7090
public function testLinesAddedToBottomOfFile()
7191
{
7292
$this->saveFile('assets/app.js', <<<EOF
@@ -318,6 +338,28 @@ public function testUnconfigure(string $originalContents, string $value, string
318338
$this->assertSame($expectedContents, $actualContents);
319339
}
320340

341+
public function testExpandTargetDirWhenUnconfiguring()
342+
{
343+
$this->saveFile('config/file.txt',
344+
<<<EOF
345+
Line1
346+
Line2
347+
EOF
348+
);
349+
350+
$this->runUnconfigure([
351+
[
352+
'file' => '%CONFIG_DIR%/file.txt',
353+
'content' => 'Line1',
354+
],
355+
]);
356+
$actualContents = $this->readFile('config/file.txt');
357+
$this->assertSame(<<<EOF
358+
Line2
359+
EOF
360+
, $actualContents);
361+
}
362+
321363
public function getUnconfigureTests()
322364
{
323365
yield 'found_middle' => [

0 commit comments

Comments
 (0)