mockery
mockery copied to clipboard
Mocking pass by reference do not work in protected methods, while in public it does
<?php
use PHPUnit\Framework\TestCase;
require_once './vendor/autoload.php';
class Bug
{
public function doWork(&$test)
{
return true;
}
protected function doNotWork(&$test)
{
return true;
}
}
class BugTest extends TestCase
{
public function testWorking()
{
$mock = \Mockery::mock(Bug::class);
$mock->makePartial()->shouldAllowMockingProtectedMethods();
$test = [];
$this->assertTrue($mock->doWork($test));
}
public function testNotWorking()
{
$mock = \Mockery::mock(Bug::class);
$mock->makePartial()->shouldAllowMockingProtectedMethods();
$test = [];
$this->assertTrue($mock->doNotWork($test));
}
}
PHPUnit 8.0.4 by Sebastian Bergmann and contributors.
.E 2 / 2 (100%)
Time: 42 ms, Memory: 4.00 MB
There was 1 error:
1) BugTest::testNotWorking
Parameter 1 to Bug::doNotWork() expected to be a reference, value given
/var/workspace/tests/Test.php:40
ERRORS!
Tests: 2, Assertions: 1, Errors: 1.
The error is rather strange, but shouldn't you get an error for calling protected method from outer scope instead anyway?