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

PHP-VCR 1.5.0 generates fatal error with wp_remote_post and wp_remote_get from WordPress #328

Open
felipead opened this issue Aug 19, 2020 · 2 comments

Comments

@felipead
Copy link

felipead commented Aug 19, 2020

I'm trying to record some HTTP requests generated by WordPress HTTP functions, such as wp_remote_post and wp_remote_get.

When using PHP-VCR 1.4.5, I get the error described in #327. After upgrading to PHP-VCR 1.5.0 (latest), I get the following fatal error:

Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 6.0.13 by Sebastian Bergmann, Julien Breux (Docker) and contributors.


Starting test 'Example_TestCase::test_should_get_index_from_example_com'.
PHP Fatal error:  Declaration of Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch(Symfony\Contracts\EventDispatcher\object $event, ?string $eventName = NULL): Symfony\Contracts\EventDispatcher\object must be compatible with Psr\EventDispatcher\EventDispatcherInterface::dispatch(Psr\EventDispatcher\object $event) in /app/vendor/symfony/event-dispatcher-contracts/EventDispatcherInterface.php on line 19
PHP Stack trace:
PHP   1. {main}() /tmp/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /tmp/vendor/phpunit/phpunit/phpunit:53
PHP   3. PHPUnit\TextUI\Command->run() /tmp/vendor/phpunit/phpunit/src/TextUI/Command.php:136
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /tmp/vendor/phpunit/phpunit/src/TextUI/Command.php:207
PHP   5. PHPUnit\Framework\TestSuite->run() /tmp/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:514
PHP   6. PHPUnit\Framework\TestSuite->run() /tmp/vendor/phpunit/phpunit/src/Framework/TestSuite.php:743
PHP   7. PHPUnit\Framework\TestCase->run() /tmp/vendor/phpunit/phpunit/src/Framework/TestSuite.php:743
PHP   8. PHPUnit\Framework\TestResult->run() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:856
PHP   9. PHPUnit\Framework\TestCase->runBare() /tmp/vendor/phpunit/phpunit/src/Framework/TestResult.php:697
PHP  10. PHPUnit\Framework\TestCase->runTest() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:901
PHP  11. ReflectionMethod->invokeArgs() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:1042
PHP  12. Example_TestCase->test_should_get_index_from_example_com() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:1042
PHP  13. wp_remote_get() /app/tests/google-mail/test-api.php:29
PHP  14. WP_Http->get() /tmp/wordpress/wp-includes/http.php:162
PHP  15. WP_Http->request() /tmp/wordpress/wp-includes/class-http.php:626
PHP  16. Requests::request() /tmp/wordpress/wp-includes/class-http.php:394
PHP  17. Requests_Transport_cURL->request() /tmp/wordpress/wp-includes/class-requests.php:381
PHP  18. VCR\LibraryHooks\CurlHook::curl_exec() /tmp/wordpress/wp-includes/Requests/Transport/cURL.php:162
PHP  19. VCR\LibraryHooks\CurlHook::__callStatic() /tmp/wordpress/wp-includes/Requests/Transport/cURL.php:162
PHP  20. VCR\LibraryHooks\CurlHook::curlExec() /app/vendor/php-vcr/php-vcr/src/VCR/LibraryHooks/CurlHook.php:160
PHP  21. VCR\Videorecorder->VCR\{closure}() /app/vendor/php-vcr/php-vcr/src/VCR/LibraryHooks/CurlHook.php:217
PHP  22. VCR\Videorecorder->handleRequest() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:277
PHP  23. VCR\Videorecorder->dispatch() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:217
PHP  24. VCR\Videorecorder->getEventDispatcher() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:106
PHP  25. spl_autoload_call() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:84
PHP  26. Composer\Autoload\ClassLoader->loadClass() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:84
PHP  27. Composer\Autoload\includeFile() /tmp/vendor/composer/ClassLoader.php:322
PHP  28. include() /tmp/vendor/composer/ClassLoader.php:444
PHP  29. spl_autoload_call() /app/vendor/symfony/event-dispatcher/EventDispatcher.php:32
PHP  30. Composer\Autoload\ClassLoader->loadClass() /app/vendor/symfony/event-dispatcher/EventDispatcher.php:32
PHP  31. Composer\Autoload\includeFile() /tmp/vendor/composer/ClassLoader.php:322
PHP  32. include() /tmp/vendor/composer/ClassLoader.php:444
PHP  33. spl_autoload_call() /app/vendor/symfony/event-dispatcher/EventDispatcherInterface.php:23
PHP  34. Composer\Autoload\ClassLoader->loadClass() /app/vendor/symfony/event-dispatcher/EventDispatcherInterface.php:23
PHP  35. Composer\Autoload\includeFile() /tmp/vendor/composer/ClassLoader.php:322
PHP  36. include() /tmp/vendor/composer/ClassLoader.php:444

Fatal error: Declaration of Symfony\Contracts\EventDispatcher\EventDispatcherInterface::dispatch(Symfony\Contracts\EventDispatcher\object $event, ?string $eventName = NULL): Symfony\Contracts\EventDispatcher\object must be compatible with Psr\EventDispatcher\EventDispatcherInterface::dispatch(Psr\EventDispatcher\object $event) in /app/vendor/symfony/event-dispatcher-contracts/EventDispatcherInterface.php on line 19

Call Stack:
    0.0003     344952   1. {main}() /tmp/vendor/phpunit/phpunit/phpunit:0
    0.0046     352160   2. PHPUnit\TextUI\Command::main() /tmp/vendor/phpunit/phpunit/phpunit:53
    0.0047     352272   3. PHPUnit\TextUI\Command->run() /tmp/vendor/phpunit/phpunit/src/TextUI/Command.php:136
    3.9065    6977144   4. PHPUnit\TextUI\TestRunner->doRun() /tmp/vendor/phpunit/phpunit/src/TextUI/Command.php:207
    3.9109    7052032   5. PHPUnit\Framework\TestSuite->run() /tmp/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:514
    3.9139    7053016   6. PHPUnit\Framework\TestSuite->run() /tmp/vendor/phpunit/phpunit/src/Framework/TestSuite.php:743
    3.9634    7053616   7. PHPUnit\Framework\TestCase->run() /tmp/vendor/phpunit/phpunit/src/Framework/TestSuite.php:743
    3.9636    7053616   8. PHPUnit\Framework\TestResult->run() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:856
    3.9655    7055872   9. PHPUnit\Framework\TestCase->runBare() /tmp/vendor/phpunit/phpunit/src/Framework/TestResult.php:697
    3.9714    7163568  10. PHPUnit\Framework\TestCase->runTest() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:901
    3.9715    7163864  11. ReflectionMethod->invokeArgs() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:1042
    3.9715    7163872  12. Example_TestCase->test_should_get_index_from_example_com() /tmp/vendor/phpunit/phpunit/src/Framework/TestCase.php:1042
    4.1267    7702208  13. wp_remote_get() /app/tests/google-mail/test-api.php:29
    4.1267    7702648  14. WP_Http->get() /tmp/wordpress/wp-includes/http.php:162
    4.1267    7703024  15. WP_Http->request() /tmp/wordpress/wp-includes/class-http.php:626
    4.1306    7809856  16. Requests::request() /tmp/wordpress/wp-includes/class-http.php:394
    4.1666    8263976  17. Requests_Transport_cURL->request() /tmp/wordpress/wp-includes/class-requests.php:381
    4.1684    8267672  18. VCR\LibraryHooks\CurlHook::curl_exec() /tmp/wordpress/wp-includes/Requests/Transport/cURL.php:162
    4.1684    8268048  19. VCR\LibraryHooks\CurlHook::__callStatic() /tmp/wordpress/wp-includes/Requests/Transport/cURL.php:162
    4.1685    8268464  20. VCR\LibraryHooks\CurlHook::curlExec() /app/vendor/php-vcr/php-vcr/src/VCR/LibraryHooks/CurlHook.php:160
    4.1686    8268464  21. VCR\Videorecorder->VCR\{closure}() /app/vendor/php-vcr/php-vcr/src/VCR/LibraryHooks/CurlHook.php:217
    4.1686    8268464  22. VCR\Videorecorder->handleRequest() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:277
    4.2092    8281472  23. VCR\Videorecorder->dispatch() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:217
    4.2094    8281472  24. VCR\Videorecorder->getEventDispatcher() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:106
    4.2094    8281472  25. spl_autoload_call() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:84
    4.2094    8281552  26. Composer\Autoload\ClassLoader->loadClass() /app/vendor/php-vcr/php-vcr/src/VCR/Videorecorder.php:84
    4.2103    8281784  27. Composer\Autoload\includeFile() /tmp/vendor/composer/ClassLoader.php:322
    4.2164    8325544  28. include('/app/vendor/symfony/event-dispatcher/EventDispatcher.php') /tmp/vendor/composer/ClassLoader.php:444
    4.2164    8325544  29. spl_autoload_call() /app/vendor/symfony/event-dispatcher/EventDispatcher.php:32
    4.2164    8325640  30. Composer\Autoload\ClassLoader->loadClass() /app/vendor/symfony/event-dispatcher/EventDispatcher.php:32
    4.2178    8325880  31. Composer\Autoload\includeFile() /tmp/vendor/composer/ClassLoader.php:322
    4.2223    8332288  32. include('/app/vendor/symfony/event-dispatcher/EventDispatcherInterface.php') /tmp/vendor/composer/ClassLoader.php:444
    4.2223    8332288  33. spl_autoload_call() /app/vendor/symfony/event-dispatcher/EventDispatcherInterface.php:23
    4.2223    8332384  34. Composer\Autoload\ClassLoader->loadClass() /app/vendor/symfony/event-dispatcher/EventDispatcherInterface.php:23
    4.2235    8332624  35. Composer\Autoload\includeFile() /tmp/vendor/composer/ClassLoader.php:322
    4.2279    8335480  36. include('/app/vendor/symfony/event-dispatcher-contracts/EventDispatcherInterface.php') /tmp/vendor/composer/ClassLoader.php:444

This is the test code:

class Example_TestCase extends WP_UnitTestCase {

    public function test_should_get_index_from_example_com() {
        VCR::turnOn();
        VCR::insertCassette( 'get_example_com.yml' );

        $response = wp_remote_get( 'http://example.com' );

        print_r( $response );

        VCR::eject();
        VCR::turnOff();
    }
}

When I run this test using php-unit, an empty get_example_com.yml cassette file is generated, without any HTTP requests being recorded. I only get the fatal error described above.

I have tested it with endpoints from Google, Facebook, and other sites. It does not seem related to any particular website.

Environment

I'm running WordPress 5.2.4 and PHP 7.

I'm using PHP-VCR version 1.5.0 (latest) installed through Composer. Unfortunately, I couldn't test it PHP-VCR version 1.5.0.

I'm running tests in this Docker container, which is based on the php-unit/php-unit:6.0.6 image. If you look at the Dockerfile, you can see this image has PHP 7 installed through Alpine and all necessary dependencies, including curl and php7-curl.

@JeroenVanOort
Copy link
Member

Which version of the Symfony event dispatcher are you using?

@felipead
Copy link
Author

felipead commented Aug 21, 2020

Which version of the Symfony event dispatcher are you using?

Symfony event dispatcher has been automatically installed as a php-vcr dependency by Composer. Looking at composer.lock I can see it is using Symfony event dispatcher version 5.1.3.

        {
            "name": "symfony/event-dispatcher",
            "version": "v5.1.3",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/event-dispatcher.git",
                "reference": "7827d55911f91c070fc293ea51a06eec80797d76"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/7827d55911f91c070fc293ea51a06eec80797d76",
                "reference": "7827d55911f91c070fc293ea51a06eec80797d76",
                "shasum": ""
            },
            "require": {
                "php": ">=7.2.5",
                "symfony/deprecation-contracts": "^2.1",
                "symfony/event-dispatcher-contracts": "^2",
                "symfony/polyfill-php80": "^1.15"
            },
            "conflict": {
                "symfony/dependency-injection": "<4.4"
            },
            "provide": {
                "psr/event-dispatcher-implementation": "1.0",
                "symfony/event-dispatcher-implementation": "2.0"
            },
            "require-dev": {
                "psr/log": "~1.0",
                "symfony/config": "^4.4|^5.0",
                "symfony/dependency-injection": "^4.4|^5.0",
                "symfony/expression-language": "^4.4|^5.0",
                "symfony/http-foundation": "^4.4|^5.0",
                "symfony/service-contracts": "^1.1|^2",
                "symfony/stopwatch": "^4.4|^5.0"
            },
            "suggest": {
                "symfony/dependency-injection": "",
                "symfony/http-kernel": ""
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "5.1-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Symfony\\Component\\EventDispatcher\\": ""
                },
                "exclude-from-classmap": [
                    "/Tests/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony EventDispatcher Component",
            "homepage": "https://symfony.com",
            "funding": [
                {
                    "url": "https://symfony.com/sponsor",
                    "type": "custom"
                },
                {
                    "url": "https://github.com/fabpot",
                    "type": "github"
                },
                {
                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
                    "type": "tidelift"
                }
            ],
            "time": "2020-06-18T18:24:02+00:00"
        },

I am also including full contents of my composer.lock.

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

2 participants