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

Fatal error when using closure in callback matcher #33

Open
klinki opened this issue Aug 5, 2016 · 7 comments
Open

Fatal error when using closure in callback matcher #33

klinki opened this issue Aug 5, 2016 · 7 comments

Comments

@klinki
Copy link

klinki commented Aug 5, 2016

Hi,
I'm trying to create a mock with headers validation. I'm using callback for that.

I'm getting this error:

Fatal error: Function name must be a string in /vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(210) : eval()'d code on line 2

My code looks like this:

$method = 'POST';
$path = '/path';
$requestHeaders = [
   'Content-Type' => 'application/json'
];

$this->http->mock
            ->when()
            ->methodIs($method)
            ->pathIs($path)
            ->callback(static function(Request $request) use($requestHeaders) {
                foreach ($requestHeaders as $header => $value) {
                    if (!$request->hasHeader($header) || $request->getHeader($header) != $value) {
                        return false;
                    }
                }
                return true;
            })
            ->then()
            ->statusCode(200)
           ->body('ok')
           ->end();

Because of that bug, I cannot validate expected request headers. Could you please provide some alternative method to validate request headers until this issue is fixed?

Thanks

@klinki klinki changed the title Fatal error when using callback Fatal error when using closure in callback matcher Aug 5, 2016
@lstrojny
Copy link
Contributor

lstrojny commented Aug 5, 2016

Which version of super closure are you using? Which version of PHPUnit are you using?

@klinki
Copy link
Author

klinki commented Aug 8, 2016

I'm using PHPUnit 5.5.0 and SuperClosure 2.2.0

@lstrojny
Copy link
Contributor

lstrojny commented Aug 8, 2016

Can you try changing your setup to this:

$this->http->mock
            ->when()
                ->methodIs($method)
                ->pathIs($path)
                ->callback(static function(Request $request) use ($requestHeaders) {
                    foreach ($requestHeaders as $header => $value) {
                        if (!$request->headers->has($header) || $request->headers->get($header) !== $value) {
                            return false;
                        }
                    }
                    return true;
                })
            ->then()
                ->statusCode(200)
                ->body('ok')
            ->end();

@klinki
Copy link
Author

klinki commented Aug 10, 2016

I tried it and result is the same as before - fatal error again.

@lstrojny
Copy link
Contributor

Hmmmm, that’s strange. What's your PHP version?

@klinki
Copy link
Author

klinki commented Aug 10, 2016

5.6.23

@lstrojny
Copy link
Contributor

Very weird, I tried exactly your example locally with both PHP 7 and PHP 5.6 and I am unable to reproduce it. Can you try digging down vendor/jeremeamia/SuperClosure/src/SerializableClosure.php +210 and see how far you come?

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

No branches or pull requests

2 participants