Skip to content

Commit

Permalink
bind created the instance object to onInstanceCreated parameter closure
Browse files Browse the repository at this point in the history
  • Loading branch information
diloabininyeri committed Feb 25, 2025
1 parent e04efe9 commit 0a5f563
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MockClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function generate(string $mockClassName, string $class, bool $overrideCon
$mockCode .= " public function __construct(\$mockFactory) {\n";
$mockCode .= $defineMockFactory;
}
$mockCode.="\$mockFactory->invokeMockedMethod('object.on.created',[\$this]);\n";
$mockCode.="\$mockFactory->getMockMethod('object.on.created')(\$this,\$params=[]);\n";
$mockCode .= " }\n";


Expand Down
2 changes: 1 addition & 1 deletion src/MockInterfaceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function generate(string $mockClassName, string $interface): string
$mockCode .= " public function __construct({$this->mockMethodInterface} \$mockFactory)
{
\$this->mockFactory = \$mockFactory;
\$mockFactory->invokeMockedMethod('object.on.created',[\$this]);
\$mockFactory->getMockMethod('object.on.created')(\$this);
}\n";

foreach ($reflection->getMethods() as $method) {
Expand Down
9 changes: 9 additions & 0 deletions src/MockMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ public function mockMethod(string $methodName, Closure $closure): self
$this->methods[$methodName] = $closure;
return $this;
}

/**
* @param string $methodName
* @return Closure
*/
public function getMockMethod(string $methodName): Closure
{
return $this->methods[$methodName];
}
}
6 changes: 6 additions & 0 deletions src/MockMethodInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ public function invokeMockedMethod(string $methodName, array $arguments): mixed;
* @return $this
*/
public function mockMethod(string $methodName, Closure $closure): MockMethod;

/**
* @param string $methodName
* @return Closure
*/
public function getMockMethod(string $methodName): Closure;
}

0 comments on commit 0a5f563

Please sign in to comment.