Skip to content

Commit 937e975

Browse files
committed
Merge pull request #3 from nulpunkt/isset-unset
The Stub object now responds to isset and unset functions
2 parents 24d98fb + e89145d commit 937e975

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Nulpunkt/PhpStub/Stub.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public function __get($name)
4545
return null;
4646
}
4747

48+
public function __isset($property)
49+
{
50+
return isset($this->methods[$property]);
51+
}
52+
53+
public function __unset($property)
54+
{
55+
unset($this->methods[$property]);
56+
}
57+
4858
public function __toString()
4959
{
5060
return "";

test/Nulpunkt/PhpStub/StubTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ public function testCanAccessAsProperty()
2424
$this->assertSame(42, $stub->property);
2525
}
2626

27+
public function testPropertiesCanBeSeenByIsset()
28+
{
29+
$stub = new Stub(['property' => 42]);
30+
$this->assertTrue(isset($stub->property), 'Properies can be seen by isset');
31+
}
32+
33+
public function testPropertiesCanBeUnset()
34+
{
35+
$stub = new Stub(['property' => 42]);
36+
unset($stub->property);
37+
$this->assertFalse(isset($stub->property), 'Properies can be unset');
38+
}
39+
2740
public function testThatItWillCallAAnonomusCallable()
2841
{
2942
$identity = function ($argument) {

0 commit comments

Comments
 (0)