From e6702dc66bfe3cbf3b461a7831a79310e3159fa3 Mon Sep 17 00:00:00 2001 From: Michiel Rook Date: Wed, 9 Aug 2023 20:34:04 +0200 Subject: [PATCH] Fixes #1719 - treat literal string values in a token as ... literal string values --- src/Phing/Filter/Token.php | 13 ++------ .../ReplaceTokensTest.php} | 21 +++++++++---- .../expected/replacetokens.test} | 0 tests/etc/filters/replacetokens.xml | 30 +++++++++++++++++++ tests/etc/regression/376/build.xml | 17 ----------- 5 files changed, 48 insertions(+), 33 deletions(-) rename tests/Phing/Test/{Regression/ReplaceTokenBooleanTest.php => Filter/ReplaceTokensTest.php} (68%) rename tests/etc/{regression/376/testfile => filters/expected/replacetokens.test} (100%) create mode 100644 tests/etc/filters/replacetokens.xml delete mode 100644 tests/etc/regression/376/build.xml diff --git a/src/Phing/Filter/Token.php b/src/Phing/Filter/Token.php index 6942fb115b..e278edfb3f 100644 --- a/src/Phing/Filter/Token.php +++ b/src/Phing/Filter/Token.php @@ -54,18 +54,9 @@ public function setKey($key) * * @param string $value The value for this token. Must not be null. */ - 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; } /** diff --git a/tests/Phing/Test/Regression/ReplaceTokenBooleanTest.php b/tests/Phing/Test/Filter/ReplaceTokensTest.php similarity index 68% rename from tests/Phing/Test/Regression/ReplaceTokenBooleanTest.php rename to tests/Phing/Test/Filter/ReplaceTokensTest.php index f1577c718a..444ab9b27b 100644 --- a/tests/Phing/Test/Regression/ReplaceTokenBooleanTest.php +++ b/tests/Phing/Test/Filter/ReplaceTokensTest.php @@ -18,7 +18,7 @@ * . */ -namespace Phing\Test\Regression; +namespace Phing\Test\Filter; use Phing\Test\Support\BuildFileTest; @@ -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"'); + } } diff --git a/tests/etc/regression/376/testfile b/tests/etc/filters/expected/replacetokens.test similarity index 100% rename from tests/etc/regression/376/testfile rename to tests/etc/filters/expected/replacetokens.test diff --git a/tests/etc/filters/replacetokens.xml b/tests/etc/filters/replacetokens.xml new file mode 100644 index 0000000000..89ae881705 --- /dev/null +++ b/tests/etc/filters/replacetokens.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/etc/regression/376/build.xml b/tests/etc/regression/376/build.xml deleted file mode 100644 index 453745ac22..0000000000 --- a/tests/etc/regression/376/build.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - -