Skip to content

Commit 0a5f563

Browse files
bind created the instance object to onInstanceCreated parameter closure
1 parent e04efe9 commit 0a5f563

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/MockClassGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function generate(string $mockClassName, string $class, bool $overrideCon
3737
$mockCode .= " public function __construct(\$mockFactory) {\n";
3838
$mockCode .= $defineMockFactory;
3939
}
40-
$mockCode.="\$mockFactory->invokeMockedMethod('object.on.created',[\$this]);\n";
40+
$mockCode.="\$mockFactory->getMockMethod('object.on.created')(\$this,\$params=[]);\n";
4141
$mockCode .= " }\n";
4242

4343

src/MockInterfaceGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function generate(string $mockClassName, string $interface): string
2424
$mockCode .= " public function __construct({$this->mockMethodInterface} \$mockFactory)
2525
{
2626
\$this->mockFactory = \$mockFactory;
27-
\$mockFactory->invokeMockedMethod('object.on.created',[\$this]);
27+
\$mockFactory->getMockMethod('object.on.created')(\$this);
2828
}\n";
2929

3030
foreach ($reflection->getMethods() as $method) {

src/MockMethod.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@ public function mockMethod(string $methodName, Closure $closure): self
4949
$this->methods[$methodName] = $closure;
5050
return $this;
5151
}
52+
53+
/**
54+
* @param string $methodName
55+
* @return Closure
56+
*/
57+
public function getMockMethod(string $methodName): Closure
58+
{
59+
return $this->methods[$methodName];
60+
}
5261
}

src/MockMethodInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ public function invokeMockedMethod(string $methodName, array $arguments): mixed;
3131
* @return $this
3232
*/
3333
public function mockMethod(string $methodName, Closure $closure): MockMethod;
34+
35+
/**
36+
* @param string $methodName
37+
* @return Closure
38+
*/
39+
public function getMockMethod(string $methodName): Closure;
3440
}

0 commit comments

Comments
 (0)