Skip to content

Commit

Permalink
When you expect value null to be returned, fake functions was not inv…
Browse files Browse the repository at this point in the history
…oked. Fixed check if mock function registered.
  • Loading branch information
m committed Oct 11, 2024
1 parent bec82f5 commit dd3a8d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AspectMock/Core/Mocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function fakeFunctionAndRegisterCalls($namespace, $function, $args)
$fullFuncName = sprintf('%s\%s', $namespace, $function);
Registry::registerFunctionCall($fullFuncName, $args);

if (isset($this->funcMap[$fullFuncName])) {
if (array_key_exists($fullFuncName, $this->funcMap)) {
$func = $this->funcMap[$fullFuncName];
$result = is_callable($func) ? call_user_func_array($func, $args) : $func;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/FunctionInjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public function testReimplementFunc()
verify(strlen('hello'))->equals(10);
}

public function testFuncReturnsNull()
{
test::func('demo', 'strlen', null);
verify(strlen('hello'))->equals(null);
}

public function testVerifier()
{
$func = test::func('demo', 'strlen', 10);
Expand Down

0 comments on commit dd3a8d9

Please sign in to comment.