Skip to content

Commit 3ae1b71

Browse files
committed
Added test case for undefined option in EcapsulatedOptions.
1 parent 760ddc3 commit 3ae1b71

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/Options/EncapsulatedOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ final public function copy()
2121
}
2222

2323
/**
24-
* Gets the value for the specified option name. Returns the specified
25-
* default value if option name is not set.
24+
* Gets the value for the specified option name. When option name is not set the default value is retrieved, if
25+
* defined, otherwise null.
2626
*
2727
* @param string $option Option name.
2828
*
29-
* @return mixed Option value or default value.
29+
* @return mixed Option value, default value or null.
3030
*/
3131
final protected function get($option)
3232
{

test/Stubs/TestOptions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ public function removeFooKey($child)
2424
{
2525
unset($this->getReference('foo')[$child]);
2626
}
27+
28+
public function getBar()
29+
{
30+
return $this->get('bar');
31+
}
2732
}

test/Unit/Porter/Options/EncapsulatedOptionsTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33

44
use ScriptFUSIONTest\Stubs\TestOptions;
55

6+
/**
7+
* @see TestOptions
8+
*/
69
final class EncapsulatedOptionsTest extends \PHPUnit_Framework_TestCase
710
{
8-
/** @var TestOptions */
11+
/**
12+
* @var TestOptions
13+
*/
914
private $options;
1015

1116
protected function setUp()
@@ -49,4 +54,12 @@ public function testGetReference()
4954

5055
self::assertSame(['baz' => 'baz'], $this->options->getFoo());
5156
}
57+
58+
/**
59+
* Tests that getting a value that is neither set nor has a default defined returns null.
60+
*/
61+
public function testGetUnset()
62+
{
63+
self::assertNull($this->options->getBar());
64+
}
5265
}

0 commit comments

Comments
 (0)