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 interface with method name: empty #1166

Open
henzeb opened this issue Feb 21, 2022 · 2 comments
Open

Cannot mock interface with method name: empty #1166

henzeb opened this issue Feb 21, 2022 · 2 comments

Comments

@henzeb
Copy link

henzeb commented Feb 21, 2022

Any one who remembers #770, will understand my problem:

interface test {
    public function empty(): void;
}
Mockery::mock(test::class);

gives me:

PHP Fatal error:  Class Mockery_0_test contains 1 abstract method 
and must therefore be declared abstract or implement the remaining 
methods (test::empty) in .../vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(34) 
: eval()'d code on line 30
@ghostwriter
Copy link
Member

Hey @henzeb

Thanks for the detailed report. It looks like the method empty is a reserved word in PHP.


Mocker has a syntax for getting around this.

\Mockery::mock('Namespace\MyClass[method1,method2,foo,bar]');


interface test
{
    public function empty(): void;
}

\Mockery::mock(test::class . '[empty]');

Hope this resolves your issue ✌🏾

@mfn
Copy link
Contributor

mfn commented Feb 21, 2022

I had a similar issue in #1159

I worked it around by adapting the methods via \Mockery\Generator\MockConfigurationBuilder::setBlackListedMethods

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

3 participants