Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Method signature of merge() in Zend\Config\Config prevents mocking #2977

Closed
jurajseffer opened this issue Nov 15, 2012 · 2 comments
Closed
Assignees
Labels
Milestone

Comments

@jurajseffer
Copy link

I've extended ZF2's Zend\Config\Config class with my own.

namespace App\Config;

use Zend\Config\Config as ZendConfig;

class Config extends ZendConfig implements ConfigInterface {
}

I then mocked my config class in a PHPUnit test

$config = $this->getMock("\App\Config\Config");

only to receive an error:
Declaration of Mock_Config_3a90f1fc::merge() should be compatible with that of Zend\Config\Config::merge()

Zend\Config\Config merge() method signature is:

public function merge(self $merge)

when "self" is amended to "\Zend\Config\Config", mocking works. Can this be changed?

Also see sebastianbergmann/phpunit-mock-objects#107

@prolic
Copy link
Contributor

prolic commented Jan 20, 2013

I think this is a php unit problem, or even with your architecture. Why do you have a reason to mock Zend\Config\Config? Normally most objects should not depend on that one. Better would be to use Options classes (Zend\Stdlib\AbstractOptions) to check configuration for a given object.

@weierophinney
Copy link
Member

While I see your point, we shouldn't use self for type-hinting.
On Jan 20, 2013 12:49 PM, "prolic" [email protected] wrote:

I think this is a php unit problem, or even with your architecture. Why do
you have a reason to mock Zend\Config\Config? Normally most objects should
not depend on that one. Better would be to use Options classes
(Zend\Stdlib\AbstractOptions) to check configuration for a given object.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2977#issuecomment-12475179.

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

No branches or pull requests

3 participants