Skip to content

Commit 84dbc57

Browse files
committed
Fix bug that class does not bind in static double
1 parent 17d3234 commit 84dbc57

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/AspectMock/Core/Mocker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function stub(MethodInvocation $invocation, $params)
145145
$replacedMethod = $this->turnToClosure($replacedMethod);
146146

147147
if ($invocation->isStatic()) {
148-
\Closure::bind($replacedMethod, null, $invocation->getThis());
148+
$replacedMethod = \Closure::bind($replacedMethod, null, $invocation->getThis());
149149
} else {
150150
$replacedMethod = $replacedMethod->bindTo($invocation->getThis(), get_class($invocation->getThis()));
151151
}

tests/_data/demo/UserModel.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ class UserModel {
66
protected $name;
77
protected $info;
88

9+
private static $topSecret = 'awesome';
10+
11+
public static function getTopSecret()
12+
{
13+
throw new \PHPUnit_Framework_AssertionFailedError("I am not going to tell you");
14+
}
15+
916
static function tableName()
1017
{
1118
return "users";

tests/_helpers/_generated/CodeGuyActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php //[STAMP] 45d8efce83ec14d112c4dbd47a09e489
1+
<?php //[STAMP] 24dfed59965666295fe7d207e9aa4d08
22
namespace _generated;
33

44
// This class was automatically generated by build task

tests/unit/StubTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ public function testCallback()
3333

3434
}
3535

36+
public function testBindSelfCallback()
37+
{
38+
double::registerClass('\demo\UserModel', ['getTopSecret' => function () {
39+
return UserModel::$topSecret;
40+
}]);
41+
$topSecret = UserModel::getTopSecret();
42+
$this->assertEquals('awesome', $topSecret);
43+
}
44+
3645
public function testObjectInstance()
3746
{
3847
$user = new UserModel(['name' => 'davert']);

0 commit comments

Comments
 (0)