-
Notifications
You must be signed in to change notification settings - Fork 460
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
Creating an alias or overload of an interface containing __construct fails #650
Comments
@chappy84 when using So I'm guessing that's the issue you are seeing, and we can't really do anything about it. See the Mocking hard dependencies cookbook entry for a thorough explanation. If that is really the case, then this issue can be closed, as it's how Mockery works. |
@robertbasic unfortunately that isn't the case. The code originally provided, aside from including mockery, was all I ran to produce that output. These were both stand alone test scripts so that I could ensure these were both bugs. The issues are:
In both of the above cases there was no class named I hope this clarification helps. |
@chappy84 yes, but having the interface in the same file as the |
@robertbasic Mockery isn't trying to overload |
@chappy84 ah, you're right. I'll investigate some more. |
@chappy84 what is your use case for this? The Why don't you just implement the interfaces you want on your existing classes and then alias/overload them? I would really like to understand your usecase first, before diving deep into this. Thanks! |
@robertbasic Unfortunately both The interfaces have been implemented on the original classes to ensure that design patterns are adhered to. |
@chappy84 you are right, again, about that part. But I still don't understand you're use case. |
@robertbasic I decided to show this in an example. This is obviously a very crude example, but I'd expect a not overly un-expected extension of the the reason
Then this would normally be executed by running the following:
In a test scenario for |
The issue with Because the interface also has a With regards to |
@chappy84 This was more than a year ago, but just wondering if you ever found a workaround for this? I too have a similar situation where a class is depending on overloading to mock a hard dependency, and that dependency implements an interface, so it's not passing a type hint check when it's intercepted. Mine doesn't have any constructor requirements like yours though: interface MyInterface
{
public function doIt();
}
class MyImplementation implements MyInterface
{
public function doIt()
{
echo 'did it';
}
}
class Foo
{
public function get() : MyInterface
{
return new MyImplementation();
}
public function go()
{
$this->get()->doIt();
}
}
public function testIt()
{
$mock = Mockery::mock('overload:' . MyImplementation::class);
$mock->shouldReceive('doIt');
$foo = new Foo();
$foo->go();
} In my case the class |
$mock = Mockery::mock('overload:' . MyImplementation::class, MyInterface::class); |
The above will solve the issue in a normal overloading situation, this specific issue is around overriding the |
When trying to create a test double of an existing class that implements the correct interface, a
BadMethodCallException
is thrown (in the case ofalias:
) or the generated code contains syntax errors (in the case ofoverload:
)This can be reproduced easily with the following POCs:
In the case of alias, the code:
will produce the following output:
In the case of overload, the code:
will produce the following output:
These are both present in the latest 0.9.6 release
The text was updated successfully, but these errors were encountered: