Skip to content

Commit

Permalink
Cast to bool only if Argument noValue is true
Browse files Browse the repository at this point in the history
  • Loading branch information
ElGigi authored and duncan3dc committed Oct 30, 2024
1 parent fb1409a commit b06b9b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Argument/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,11 @@ public function noValue()
*/
protected function setNoValue($noValue)
{
$this->setCastTo('bool');
$this->noValue = (bool) $noValue;

if ($this->noValue === true) {
$this->setCastTo('bool');
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/ArgumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ public function it_casts_to_bool_when_defined_only()
$this->assertEquals('bool', $argument->castTo());
}

/**
* @test
* @doesNotPerformAssertions
*/
public function it_casts_to_bool_when_defined_only_true()
{
$argument = Argument::createFromArray('invalid-cast-type', [
'noValue' => false,
]);

$this->assertNotEquals('bool', $argument->castTo());
}

/**
* @test
* @doesNotPerformAssertions
Expand Down

0 comments on commit b06b9b0

Please sign in to comment.