JeroenDeDauw / ParamProcessor

Declarative parameter processing library
https://entropywins.wtf
Other
20 stars 4 forks source link

Cannot mock `Param` because it is declared final, and `IParam` is empty #40

Open mwjames opened 5 years ago

mwjames commented 5 years ago

For a test I tried to:

$param = $this->getMockBuilder( '\ParamProcessor\Param' )
    ->disableOriginalConstructor()
    ->getMock();

but it returns with "Class "ParamProcessor\Param" is declared "final" and cannot be mocked." then I tried

$param = $this->getMockBuilder( '\ParamProcessor\IParam' )
    ->disableOriginalConstructor()
    ->getMock();

which returns "Trying to configure method "getName" which cannot be configured because it does not exist, has not been specified, is final, or is static".

In order to get going I ended up with:

$param = $this->getMockBuilder( '\stdClass' )
    ->disableOriginalConstructor()
    ->setMethods( [ 'getName', 'getValue' ] )
    ->getMock();

$param->expects( $this->any() )
    ->method( 'getName' )
    ->will( $this->returnValue( 'outlineproperties' ) );

$param->expects( $this->any() )
    ->method( 'getValue' )
    ->will( $this->returnValue( [] ) );
mwjames commented 5 years ago

In order to get going I ended up with:

https://github.com/SemanticMediaWiki/SemanticResultFormats/pull/515

JeroenDeDauw commented 5 years ago

Both Param and IParam are marked as package private and IParam is deprecated.

JeroenDeDauw commented 5 years ago

SMW looks like it can be migrated away from these (and I suspect SMW is the last user). Will give that a try.

Semi-related: https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/4171

JeroenDeDauw commented 5 years ago

https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/4172

After that you should be able to just use ProcessedParam (which is a sane value object) in your test without needing any mocking.

JeroenDeDauw commented 5 years ago

"sane"... it has setters though :D Please slap 2013 Jeroen if you see him.