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

"Uncaught Error: Function name must be a string" when matching on a callback #68

Open
gturri opened this issue Dec 21, 2021 · 1 comment

Comments

@gturri
Copy link
Contributor

gturri commented Dec 21, 2021

Hi,

I'm trying to follow the 2nd snippet of the doc here https://github.com/InterNations/http-mock/blob/main/doc/stubbing.md but I get an error. I'm not sure if I'm doing something wrong or if there is an issue and I would be thrilled if you can give me pointer to fix it.
Here is my code:

<?php
declare(strict_types=1);

use InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;

final class CalDAVUTest extends TestCase {
    use HttpMockTrait;
    public static function setUpBeforeClass() : void {
        static::setUpHttpMockBeforeClass('8082', 'localhost');
    }
    public static function tearDownAfterClass() : void {
        static::tearDownHttpMockAfterClass();
    }
    public function setUp() : void {
        $this->setUpHttpMock();
    }
    public function tearDown() : void {
        $this->tearDownHttpMock();
    }

    public function test_doc(){
        $this->http->mock
            ->when()
                ->callback(
                    static function (Request $request) {
                        return $request->getMethod() === 'GET' && $request->getPathInfo() === '/resource';
                    }
                )
            ->then()
                ->callback(
                    static function (Response $response) {
                        $response->setBody('response');
                    }
                )
            ->end();
        $this->http->setUp();


        $curl = curl_init("http://localhost:8082/resource");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_exec($curl);
    }
}

and here is the error I have:

1) CalDAVUTest::test_doc
HTTP mock server standard error output should be empty
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-''
+'[Tue Dec 21 22:59:15 2021] PHP Fatal error:  Uncaught Error: Function name must be a string in /documents/zwp/slack-agenda-app/vendor/jeremeamia/superclosure/src/SerializableClosure.php(210) : eval()'d code:2
+Stack trace:
+#0 [internal function]: InterNations\Component\HttpMock\Matcher\AbstractMatcher::{closure}()
+#1 /documents/zwp/slack-agenda-app/vendor/jeremeamia/superclosure/src/SerializableClosure.php(75): call_user_func_array()
+#2 /documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/app.php(130): SuperClosure\SerializableClosure->__invoke()
+#3 [internal function]: InterNations\Component\HttpMock\{closure}()
+#4 /documents/zwp/slack-agenda-app/vendor/silex/silex/src/Silex/ExceptionListenerWrapper.php(53): call_user_func()
+#5 /documents/zwp/slack-agenda-app/vendor/symfony/event-dispatcher/EventDispatcher.php(264): Silex\ExceptionListenerWrapper->__invoke()
+#6 /documents/zwp/slack-agenda-app/vendor/symfony/event-dispatcher/EventDispatcher.php(239): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch()
+#7 /documents/zwp/slack-agen in /documents/zwp/slack-agenda-app/vendor/jeremeamia/superclosure/src/SerializableClosure.php(210) : eval()'d code on line 2'

/documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/PHPUnit/HttpMockTrait.php:73
/documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/PHPUnit/HttpMockFacade.php:85
/documents/zwp/slack-agenda-app/vendor/internations/http-mock/src/PHPUnit/HttpMockTrait.php:75
/documents/zwp/slack-agenda-app/tests/CalDAVUTest.php:20

Here is the relevant part of my composer.json:

    "require-dev": {
        "phpunit/phpunit": "^9.5",
        "internations/http-mock": "^0.14.0"
    }

(and in my composer.lock I see that I'm using jeremeamia/superclosure version 2.4.0)

Does this error rings a bell?

@gturri
Copy link
Contributor Author

gturri commented Dec 21, 2021

it turns out my issue is a duplicate of #33 , sorry for not having spotted it sooner. Don't hesitate to let me know if you'd rather I close it and we continue the conversation there

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

1 participant