Skip to content

Commit b23fefb

Browse files
committedDec 2, 2018
Added __toString() method to Argument class. Added unit test
1 parent 8bb3cb8 commit b23fefb

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
 

‎src/CLILib/Argument.php

+9
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,13 @@ public function value()
3131
{
3232
return $this->value;
3333
}
34+
35+
/**
36+
* Returns the $value property when casting Argument to string
37+
*
38+
* @return string
39+
*/
40+
public function __toString() {
41+
return (string)$this->value;
42+
}
3443
}

‎tests/Argument/Test.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
use CLILib\Argument;
3+
use PHPUnit\Framework\TestCase;
4+
5+
class ArgumentTest extends TestCase
6+
{
7+
/**
8+
* Create Argument object and check Name and Value have been set correctly.
9+
*/
10+
public function testValidPassArgsToConstructor()
11+
{
12+
$a = new Argument("j", "something");
13+
14+
$this->assertEquals("something", $a->value());
15+
$this->assertEquals("j", $a->name());
16+
17+
// Test casting to a string
18+
$this->assertEquals("something", (string)$a);
19+
}
20+
}

0 commit comments

Comments
 (0)