Unpacking array behavior is weird when using makePartial method.
Author: wadakatuCreated Mar 3, 2023Updated Aug 10, 2024
| Q | A |
|---|---|
| PHPUnit version | 9.6.4 |
| Mockery version | 1.5.0 |
| PHP version | 8.1.12 |
| Installation Method | Composer |
Summary
The behavior of array spread operator (...) is not expected when I use makePartial method.
Current behavior
Without makePartial method.
// test method
public function testMethodCallOnce()
{
$course = new Course();
(new ActualController($course))->index();
}
---
"a"
array:3 [
"email" => "[email protected]"
"role" => "test_role"
"last_name" => "aaa"
]With makePartial method
// test method
public function testDumpMethodCallOnce()
{
$course = Mockery::mock(Course::class)
(new ActualController($course))->index();
}
---
"a"
[]index method and dump method are like below.
// ActualController Class
public function index()
{
$this->course->dump('abc', ...[
'email' => '[email protected]',
'role' => 'test_role',
'last_name' => 'aaa',
]);
}
// Course Class
public function dump(string $abc, ...$attributes)
{
// I use Laravel.
dd($abc, $attributes);
}How to reproduce
Expected behavior
I expect that both output are same.
Without makePartial method.
// test method
public function testMethodCallOnce()
{
$course = new Course();
(new ActualController($course))->index();
}
---
"abc"
array:3 [
"email" => "[email protected]"
"role" => "test_role"
"last_name" => "aaa"
]With makePartial method
// test method
public function testDumpMethodCallOnce()
{
$course = Mockery::mock(Course::class)
(new ActualController($course))->index();
}
---
"abc"
array:3 [
"email" => "[email protected]"
"role" => "test_role"
"last_name" => "aaa"
]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.
Source: mockery/mockery