Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SwitchTask] Added test case for numeric case values #1899

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/Phing/Task/System/CaseTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class CaseTask extends SequentialTask
private $value;

/**
* @param mixed $value
* @param string $value
*/
public function setValue($value): void
public function setValue(string $value): void
{
$this->value = $value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phing/Task/System/SwitchTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function main()
foreach ($this->cases as $case) {
$cValue = $case->getValue();

if (empty($cValue)) {
if ($cValue === null || $cValue === '') {
throw new BuildException('Value is required for case.');
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Phing/Test/Task/System/SwitchTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function testSwitchCase(): void
$this->expectLogContaining(__FUNCTION__, 'The value of property foo is bar');
}

public function testSwitchCaseNumbers(): void
{
$this->expectLogContaining(__FUNCTION__, 'The value of property foo is 1');
}

public function testSwitchDefault(): void
{
$this->expectLogContaining(__FUNCTION__, 'The value of property bar is not sensible');
Expand Down
14 changes: 14 additions & 0 deletions tests/etc/tasks/system/SwitchTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@
</default>
</switch>
</target>
<target name="testSwitchCaseNumbers">
<property name="foo" value="1"/>
<switch value="${foo}">
<case value="0">
<echo message="The value of property foo is 0" />
</case>
<case value="1">
<echo message="The value of property foo is 1" />
</case>
<default>
<echo message="The value of property foo is not sensible" />
</default>
</switch>
</target>
<target name="testSwitchDefault">
<property name="bar" value="test"/>
<switch value="${bar}">
Expand Down
Loading