This repository was archived by the owner on Feb 20, 2023. It is now read-only.
This repository was archived by the owner on Feb 20, 2023. It is now read-only.
Mocking of Interface method with type hint causes fatal error #319
Closed
Description
I need to create a mock of a class that implements two interfaces. This is what I do:
$contextMock = $this->createMock([QueryContextInterface::class, RepresentAggsAsFacets::class]);
$contextMock
->expects($this->once())
->method('getAggregationKeys')
->willReturn(['category_ids']);
QueryContextInterface:
interface QueryContextInterface
{
/**
* Get the query tree builder.
*
* @return TreeBuilder
*/
public function getTreeBuilder();
}
RepresentAggsAsFacets
interface RepresentAggsAsFacets
{
/**
* @return string[]
*/
public function getAggregationKeys(): array;
}
Now, when I execute the test, I get the following error message:
PHP Fatal error: Declaration of Mock_RepresentAggsAsFacets_2fec4bca::getAggregationKeys() must be compatible with Jobcloud\PlatformBundle\Elasticsearch\RepresentAggsAsFacets::getAggregationKeys(): array in /srv/httpd/unity-backend-core/PlatformBundle/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php(340) : eval()'d code on line 11
The error does not show if I remove the typehint of RepresentAggsAsFacets::getAggregationKeys.
PHP-Version: 7.0.9
PHPUnit: 5.5
phpunit-mock-objects: 3.1