dougehe2022 2014-10-14 07:42
浏览 78
已采纳

Behat无法初始化:Client :: createResponse()的声明应该与createResponse()兼容

I am trying to set-up Behat but it fails to init when I run bin/behat --init. My composer.json is taken from the official docs:

{
    "require": {
        "behat/behat": "2.4.*@stable",
        "behat/mink": "1.4.*@stable",
        "behat/mink-extension": "*",
        "behat/mink-goutte-driver": "*",
        "behat/mink-selenium2-driver": "*"
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}

The composer install works fine and looks like all dependencies get installed.

# behat.yml
default:
  paths:
    features:  features
    bootstrap: features/bootstrap

  extensions:
    Behat\MinkExtension\Extension:
      base_url: http://en.wikipedia.org
      goutte: ~
      selenium2: ~

annotations:
  paths:
    features: features/annotations

closures:
  paths:
    features: features/closures 

Running # bin/behat --init yields the following error:

PHP Strict Standards:  Declaration of Behat\Mink\Driver\Goutte\Client::createResponse() should be compatible with Goutte\Client::createResponse(GuzzleHttp\Message\Response $response) in /web/Test-1/vendor/behat/mink-goutte-driver/src/Behat/Mink/Driver/Goutte/Client.php on line 23

Strict Standards: Declaration of Behat\Mink\Driver\Goutte\Client::createResponse() should be compatible with Goutte\Client::createResponse(GuzzleHttp\Message\Response $response) in /web/Test-1/vendor/behat/mink-goutte-driver/src/Behat/Mink/Driver/Goutte/Client.php on line 23


  [ReflectionException]
  Class Guzzle\Http\Client does not exist

Could somebody tell me why? I did everything exactly like in official article.

  • 写回答

1条回答 默认 最新

  • doutangtan6386 2014-10-14 11:01
    关注

    You are using incompatible versions of Mink extensions / drivers. The following pulls the latest versions compatible (right now) with Behat 3 and Mink 1.6, while you want to use much older versions (2.4.* and 1.4.* respectively).

    "behat/mink-extension": "*",
    "behat/mink-goutte-driver": "*",
    "behat/mink-selenium2-driver": "*"
    

    I am assuming you've pulled this from the Internet, as I can't find a different example out there with fixed versions, which is pretty ironic, as the same people are probably blogging at the same time about how much of a bad practice that is. If you are just beginning, I suggest you stick with the latest versions of Behat and Mink, they are much better and have been more than stable for the past 6 months. Change you composer.json and update the dependencies:

    "behat/behat": "*",
    "behat/mink": "*"
    

    If not, go to each extension / driver repo and find the tagged version from early-mid 2013, that should fix it for the older packages.

    Update

    The code you provided doesn't work because you are using the old config format with the new Behat / Mink version. Don't forget, Behat 2 configs must be upgraded for Behat 3. Documentation is still pretty poor, but the basics are covered rather well here and here. Updating your config to this resolves the issue:

    default:
      extensions:
        Behat\MinkExtension:
          base_url: http://en.wikipedia.org
          goutte: ~
          selenium2: ~
    
      suites:
        default:
          paths: 
            - '%paths.base%/features'
    
        annotations:
          paths:
            - '%paths.base%/features/annotations'
    
        closures:
          paths:
            - '%paths.base%/features/closures'
    

    Here are the the packed files, just in case you get lost, the init command produces this:

    Ian-Bytcheks-MacBook-Pro:behat ianbytchek$ php ./vendor/bin/behat --init
    +d features - place your *.feature files here
    +d features/bootstrap - place your context classes here
    +f features/bootstrap/FeatureContext.php - place your definitions, transformations and hooks here
    +d features/annotations - place your *.feature files here
    +d features/closures - place your *.feature files here
    

    Update

    The root of all evil was the curl module, that was not installed in the author's environment. Instead of a proper warning php tried to mitigate the problem by using an alternative, which didn't help much.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀