Skip to content
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

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

Open
mwjames opened this issue Jul 27, 2019 · 5 comments
Open

Comments

@mwjames
Copy link
Collaborator

mwjames commented Jul 27, 2019

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
Copy link
Collaborator Author

mwjames commented Jul 27, 2019

In order to get going I ended up with:

SemanticMediaWiki/SemanticResultFormats#515

@JeroenDeDauw
Copy link
Owner

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

@JeroenDeDauw
Copy link
Owner

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: SemanticMediaWiki/SemanticMediaWiki#4171

@JeroenDeDauw
Copy link
Owner

SemanticMediaWiki/SemanticMediaWiki#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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants