Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Analyzers/ConfigAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ public function replaceNodeValue($key, Node $node, $completeReplace = false)

return;
} elseif ($currentNode->value instanceof FuncCall) {
if ($node instanceof FuncCall) {
$currentNode->value = $node;

return;
}

if ($this->shouldProceedWithFunctionRewrite($key, $currentCheckValue)) {
$this->functionHandler->handle($currentNode->value, $currentNode, $node, $key);
}
Expand Down
1 change: 1 addition & 0 deletions src/LaravelConfigWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public function getUpdater($namespace)
}

$configUpdater = new ConfigUpdater();
$configUpdater->setIgnoreFunctions($this->ignoreFunctions);
$configUpdater->open($file);

return $configUpdater;
Expand Down
63 changes: 63 additions & 0 deletions tests/FuncCallReplacementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Stillat\Proteus\Tests;

use ReflectionObject;
use Stillat\Proteus\ConfigUpdater;
use Stillat\Proteus\Document\Transformer;
use Stillat\Proteus\LaravelConfigWriter;
use Stillat\Proteus\Writers\FunctionWriter;

class FuncCallReplacementTest extends ProteusTestCase
{
/**
* Replacing one FuncCall with a different FuncCall should work with the
* default ignoreFunctions=true, since the caller is making an explicit
* replacement (not a bulk update where function preservation makes sense).
*/
public function testReplacingExistingFuncCallWithDifferentFuncCall(): void
{
$f = new FunctionWriter();

$updater = new ConfigUpdater(); // ignoreFunctions=true by default
$updater->open(__DIR__.'/configs/funcall_replacement.php');
$updater->update(['path' => $f->basePath('content/revisions')]);

$expected = Transformer::normalizeLineEndings(
file_get_contents(__DIR__.'/expected/funcall_replacement.php')
);

$this->assertEquals($expected, $updater->getDocument());
}

/**
* LaravelConfigWriter::getUpdater() must propagate the ignoreFunctions
* setting to the ConfigUpdater it creates, so that
* ConfigWriter::ignoreFunctionCalls(false) actually takes effect when
* going through the edit()->set()->save() path.
*/
public function testGetUpdaterPassesIgnoreFunctionsToConfigUpdater(): void
{
// Copy the fixture before constructing LaravelConfigWriter — it scans configPath() on construction.
$configPath = $this->app->configPath();
$fixture = $configPath.'/funcall_replacement.php';
copy(__DIR__.'/configs/funcall_replacement.php', $fixture);

try {
$writer = new LaravelConfigWriter($this->app, $this->app['config']);
$writer->ignoreFunctionCalls(false);

$updater = $writer->getUpdater('funcall_replacement');

$updaterRef = new ReflectionObject($updater);
$updaterProp = $updaterRef->getProperty('ignoreFunctions');

$this->assertFalse(
$updaterProp->getValue($updater),
'getUpdater() should propagate ignoreFunctions=false to the returned ConfigUpdater'
);
} finally {
@unlink($fixture);
}
}
}
5 changes: 5 additions & 0 deletions tests/configs/funcall_replacement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'path' => storage_path('revisions'),
];
5 changes: 5 additions & 0 deletions tests/expected/funcall_replacement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'path' => base_path('content/revisions'),
];