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

Function with enum argument causes error #1198

Closed
murrant opened this issue Nov 11, 2022 · 2 comments · Fixed by #1199
Closed

Function with enum argument causes error #1198

murrant opened this issue Nov 11, 2022 · 2 comments · Fixed by #1199
Labels
Bug An error or unexpected behavior.
Milestone

Comments

@murrant
Copy link
Contributor

murrant commented Nov 11, 2022

Calling the function on the mock results in an unexpected Undefined Constant error.

enum SimpleEnum {
    case single;
}
class EnumTest {
    public function call(SimpleEnum $enum = SimpleEnum::single) {
        echo $enum->name;
    }
}

$mock = Mockery::mock('EnumTest');
$mock->shouldReceive('call')->once();
$log = $mock->call();
   Error 

  Undefined constant "SimpleEnum"

  at vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php:34
     30▕         if (class_exists($definition->getClassName(), false)) {
     31▕             return;
     32▕         }
     33▕ 
  ➜  34▕         eval("?>" . $definition->getCode());
     35▕     }
     36▕ }
     37▕ 

  1   test.php:29
      Mockery_0_EnumTest::call()

Calling normally works as expected.

(new EnumTest())->call();
single
@murrant
Copy link
Contributor Author

murrant commented Nov 13, 2022

Looking a little more this is the errored code:

public function call(\SimpleEnum $enum = SimpleEnum){

It is missing ::single

murrant added a commit to murrant/mockery that referenced this issue Nov 13, 2022
murrant added a commit to murrant/mockery that referenced this issue Nov 15, 2022
fixes mockery#1198

Add tests
(add assertions to other test complaining about them too)
murrant added a commit to murrant/mockery that referenced this issue Nov 15, 2022
fixes mockery#1198

Add tests
(add assertions to other test complaining about them too)
@ghostwriter ghostwriter added this to the 1.6.0 milestone Apr 22, 2023
ghostwriter pushed a commit to murrant/mockery that referenced this issue Apr 22, 2023
fixes mockery#1198

Add tests
(add assertions to other test complaining about them too)
ghostwriter pushed a commit to murrant/mockery that referenced this issue Apr 22, 2023
fixes mockery#1198

Add tests
(add assertions to other test complaining about them too)
ghostwriter pushed a commit to murrant/mockery that referenced this issue Apr 22, 2023
fixes mockery#1198

Add tests
(add assertions to other test complaining about them too)
@ghostwriter
Copy link
Member

Resolved via #1199

@ghostwriter ghostwriter added the Bug An error or unexpected behavior. label Apr 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An error or unexpected behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants