New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unpacking array behavior is weird when using makePartial method. #1220
Comments
Weird one, I don't think you've misunderstood anything. Simple test case: <?php
use Mockery\Adapter\Phpunit\MockeryTestCase;
require "vendor/autoload.php";
class Foo {
public function bar($a, ...$b) {
return [$a, $b];
}
}
class test extends MockeryTestCase
{
/** @test */
public function a_test()
{
$mock = Mockery::mock(Foo::class)->makePartial();
$res = $mock->bar('abc', ...['def' => 'hjk']);
self::assertEquals('abc', $res[0]);
self::assertEquals(['def' => 'hjk'], $res[1]);
}
} |
Thank you for providing simple test case. I did some research about this behavior. Apparently, Mockery uses this method as follows. public function bar($a, ...$b){
$argc = func_num_args(); // get the number of function's arguments.
$argv = func_get_args(); // get the content of function's arguments.
$ret = $this->_mockery_handleMethodCall(__FUNCTION__, $argv); // execute method with arguments.
return $ret;
} if I define bar method something like below... $foo = new Foo();
$foo->bar('abc', ...['def' => 'hjk']);
It shows that my second argument I do not know whether or not this behavior is intentional. |
I assume this is the problem. Really not sure how we get around it. |
Summary
The behavior of array spread operator (...) is not expected when I use makePartial method.
Current behavior
Without makePartial method.
With makePartial method
index method and dump method are like below.
How to reproduce
Expected behavior
I expect that both output are same.
Without makePartial method.
With makePartial method
I have no idea what causes this behavior.
Perhaps, I misunderstood something about phpunit.
If you need more info and code, please let me know.
Thank you.
The text was updated successfully, but these errors were encountered: