File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,13 @@ $stub = new Stub([
18
18
'answer' => 42,
19
19
'callMe' => function($a) { return $a; } # Anything which is a callable
20
20
]);
21
+ $stub->foo = 'bar';
22
+ $stub->myMethod = function() { return 50; };
21
23
echo $stub->answer(); # => 42
22
24
echo $stub->answer; # => 42
23
25
echo $stub->callMe('maybe'); # => 'maybe'
26
+ echo $stub->foo; # => 'bar'
27
+ echo $stub->myMethod(); # => 50
24
28
echo $stub->lol()->hey(); # => $stub
25
29
26
30
// Different configurations
Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ public function __get($name)
44
44
}
45
45
return null ;
46
46
}
47
+
48
+ public function __set ($ name , $ value )
49
+ {
50
+ $ this ->methods [$ name ] = $ value ;
51
+ }
47
52
48
53
public function __isset ($ property )
49
54
{
Original file line number Diff line number Diff line change @@ -12,6 +12,20 @@ public function testThatAStubRespondToDefinedMethods()
12
12
$ this ->assertSame (42 , $ stub ->getId ());
13
13
}
14
14
15
+ public function testThatMethodsCanBeAssignedAfterInstantiation ()
16
+ {
17
+ $ stub = new Stub ();
18
+ $ stub ->myMethod = function () { return 42 ; };
19
+ $ this ->assertSame (42 , $ stub ->myMethod ());
20
+ }
21
+
22
+ public function testThatPropertiesCanBeAssignedAfterInstantiation ()
23
+ {
24
+ $ stub = new Stub ();
25
+ $ stub ->foo = 'bar ' ;
26
+ $ this ->assertSame ('bar ' , $ stub ->foo );
27
+ }
28
+
15
29
public function testThatItHasAllProperties ()
16
30
{
17
31
$ stub = new Stub ();
You can’t perform that action at this time.
0 commit comments