Skip to content

Commit

Permalink
Fixes #1719 - treat literal string values in a token as ... literal s…
Browse files Browse the repository at this point in the history
…tring values
  • Loading branch information
mrook committed Aug 9, 2023
1 parent 9f6594b commit e6702dc
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 33 deletions.
13 changes: 2 additions & 11 deletions src/Phing/Filter/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,9 @@ public function setKey($key)
*
* @param string $value The value for this token. Must not be <code>null</code>.
*/
public function setValue($value)
public function setValue(string $value)
{
// special case for bool values
if (is_bool($value)) {
if ($value) {
$this->value = 'true';
} else {
$this->value = 'false';
}
} else {
$this->value = (string) $value;
}
$this->value = $value;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* <http://phing.info>.
*/

namespace Phing\Test\Regression;
namespace Phing\Test\Filter;

use Phing\Test\Support\BuildFileTest;

Expand All @@ -28,16 +28,27 @@
*
* @internal
*/
class ReplaceTokenBooleanTest extends BuildFileTest
class ReplaceTokensTest extends BuildFileTest
{
public function setUp(): void
{
$this->configureProject(PHING_TEST_BASE . '/etc/regression/376/build.xml');
$this->configureProject(PHING_TEST_BASE . '/etc/filters/replacetokens.xml');
}

public function testCustomTask(): void
public function tearDown(): void
{
$this->executeTarget('main');
$this->executeTarget('cleanup');
}

public function testLiteralBooleans(): void
{
$this->executeTarget('testLiteralBooleans');
$this->assertInLogs('Replaced "@TOKEN_KEY_TRUE@" with "true"');
}

public function testLiteralsThatShouldNotBeConvertedToBooleans(): void
{
$this->executeTarget('testLiteralsThatShouldNotBeConvertedToBooleans');
$this->assertInLogs('Replaced "@TOKEN_KEY_TRUE@" with "1"');
}
}
File renamed without changes.
30 changes: 30 additions & 0 deletions tests/etc/filters/replacetokens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>

<project name="ReplaceTokens" default="cleanup">
<target name="init">
<mkdir dir="result" />
</target>
<target name="cleanup">
<delete dir="result"/>
</target>
<target name="testLiteralBooleans">
<copy file="expected/replacetokens.test" todir="result" overwrite="true">
<filterchain>
<replacetokens>
<token key="TOKEN_KEY_TRUE" value="true"/>
<token key="TOKEN_KEY_FALSE" value="false"/>
</replacetokens>
</filterchain>
</copy>
</target>
<target name="testLiteralsThatShouldNotBeConvertedToBooleans">
<copy file="expected/replacetokens.test" todir="result" overwrite="true">
<filterchain>
<replacetokens>
<token key="TOKEN_KEY_TRUE" value="1"/>
<token key="TOKEN_KEY_FALSE" value="0"/>
</replacetokens>
</filterchain>
</copy>
</target>
</project>
17 changes: 0 additions & 17 deletions tests/etc/regression/376/build.xml

This file was deleted.

0 comments on commit e6702dc

Please sign in to comment.