box / box/shmock

Setting dont_preserve_original_methods interferes with mocking __call methods

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
34
Forks
7
PR merge metrics
No merged PRs in 30d

Description

e.g.

```

class MagicMethodTest
{
/**
* @param string $methodName
* @param array $argument
*
* @return string
*/
public function __call($methodName, array $argument)
{
return $methodName;
}
}

class MagicMethodUsage
{
/**
* @param \Box\PHPUnitTestGenerator\tests\_fixture\_input\MagicMethodTest $magicTest
*
* @return string
*/
public function callMagicMethod(
MagicMethodTest $magicTest
)
{
$rc = $magicTest->foo();

return $rc;
}
}

shmock(
'MagicMethodTest',
function (
$shmock
) {
// $shmock->dont_preserve_original_methods();

/** @var $mock \Shmock\Spec */
$mock = $shmock->__call('foo', array (
));
$mock->return_value('bar');
}
);

// Execute the method under test.

$objectUnderTest = new MagicMethodUsage();
$executionResult = $objectUnderTest->callMagicMethod($mockMagicMethodTest0);

// Validate the execution result.

$expected = 'bar';
$this->assertSame(
$expected,
$executionResult,
'Variable ( executionResult ) doesn\'t have the expected value.'
);
}
}

```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the example from the issue with MagicMethodTest::__call, MagicMethodUsage::callMagicMethod, and the generated MagicMethodUsageGenTest. Compare behavior with and without dont_preserve_original_methods, then trace how Shmockers and Shmock\Spec handle the __call mock. Done means the mocked __call returns 'bar' when the option is enabled and the regression is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.