【问题标题】:Running behat outputs annoying PHP Strict standards error/notice运行 behat 输出恼人的 PHP Strict 标准错误/通知
【发布时间】:2015-07-26 23:54:43
【问题描述】:

我已经尝试实现这两个问题的答案:

但没有运气:每当我运行 behat 时,我仍然会在功能运行之前收到此消息:

PHP Strict standards:  Declaration of Behat\Behat\Console\Input\InputDefinition::getSynopsis() should be compatible with Symfony\Component\Console\Input\InputDefinition::getSynopsis($short = false) in C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\Input\InputDefinition.php on line 157
PHP Stack trace:
PHP   1. {main}() C:\phpbin\behat\vendor\behat\behat\bin\behat:0
PHP   2. Symfony\Component\Console\Application->run() C:\phpbin\behat\vendor\behat\behat\bin\behat:32
PHP   3. Behat\Behat\Console\BehatApplication->doRun() C:\phpbin\behat\vendor\symfony\console\Application.php:126
PHP   4. Behat\Behat\Console\BehatApplication->createCommand() C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\BehatApplication.php:66
PHP   5. Symfony\Component\DependencyInjection\ContainerBuilder->get() C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\BehatApplication.php:80
PHP   6. Symfony\Component\DependencyInjection\ContainerBuilder->createService() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:504
PHP   7. ReflectionClass->newInstanceArgs() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:980
PHP   8. Behat\Behat\Console\Command\BehatCommand->__construct() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:980
PHP   9. Composer\Autoload\ClassLoader->loadClass() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:0
PHP  10. Composer\Autoload\includeFile() C:\phpbin\behat\vendor\composer\ClassLoader.php:301

Strict standards: Declaration of Behat\Behat\Console\Input\InputDefinition::getSynopsis() should be compatible with Symfony\Component\Console\Input\InputDefinition::getSynopsis($short = false) in C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\Input\InputDefinition.php on line 157

Call Stack:
    0.0003     237800   1. {main}() C:\phpbin\behat\vendor\behat\behat\bin\behat:0
    0.0250    1812816   2. Symfony\Component\Console\Application->run() C:\phpbin\behat\vendor\behat\behat\bin\behat:32
    0.0331    2201280   3. Behat\Behat\Console\BehatApplication->doRun() C:\phpbin\behat\vendor\symfony\console\Application.php:126
    0.0331    2201344   4. Behat\Behat\Console\BehatApplication->createCommand() C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\BehatApplication.php:66
    0.2716    6867024   5. Symfony\Component\DependencyInjection\ContainerBuilder->get() C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\BehatApplication.php:80
    0.2717    6868160   6. Symfony\Component\DependencyInjection\ContainerBuilder->createService() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:504
    0.2903    7223504   7. ReflectionClass->newInstanceArgs() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:980
    0.2903    7225288   8. Behat\Behat\Console\Command\BehatCommand->__construct() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:980
    0.2904    7226416   9. Composer\Autoload\ClassLoader->loadClass() C:\phpbin\behat\vendor\symfony\dependency-injection\ContainerBuilder.php:0
    0.2909    7226568  10. Composer\Autoload\includeFile() C:\phpbin\behat\vendor\composer\ClassLoader.php:301

Feature: Search
  In order to use the admin pages
  As me (admin)
  I need to be able to load the pages

  Scenario: Navigating to the admin home page - check title and main heading # features\wikipedia.feature:6
    Given I am on "/dabblelabs/admin"                                        # FeatureContext::visit()
    Then I should see "Admin" in the "body" element                          # FeatureContext::assertElementContainsText()
    Then the element "body" should contain "Admin Home"                      # FeatureContext::assertElementContainsString()
    Then the title contains "Admin Home"                                     # FeatureContext::assertTitleContains()

1 scenario (1 passed)
4 steps (4 passed)
0m0.245s

在我的 FeatureContext.php 文件中,在类定义上方,我有:

ini_set('display_errors', '0');
error_reporting(E_ALL & ~E_STRICT);
define('BEHAT_ERROR_REPORTING', E_ERROR);

但我仍然得到错误。我该如何隐藏它们?

【问题讨论】:

    标签: php behat error-reporting


    【解决方案1】:

    我不是交响乐和贝哈特的专业人士,但

     Declaration of Behat\Behat\Console\Input\InputDefinition::getSynopsis() should be compatible with Symfony\Component\Console\Input\InputDefinition::getSynopsis($short = false) in C:\phpbin\behat\vendor\behat\behat\src\Behat\Behat\Console\Input\InputDefinition.php on line 157
    

    此错误表明您的函数声明不匹配

    我看到解决问题的一种方法,在 Behat\Behat\Console\Input\InputDefinition::getSynopsis($short = false) 的声明中添加 $short = false

    这不会改变任何事情,但 Behat 中的反射不会打扰你

    【讨论】:

    • 太好了,谢谢。但是,AFAIK 我需要找到一种不修改 Behat 代码的方法,因为在各种情况下任何修改都会被作曲家覆盖。
    • 显然这是一个错误:google.ca/… 唯一的解决方法是在 php.ini 中指定 error_reporting = E_ALL & ~E_STRICT 如果您有权访问
    • 谢谢 - 但遗憾的是我编辑了 c:\wamp\bin\php\php5.4.12\php.ini (我已将 behat 配置为使用 WAMP 安装的 php 二进制文件)并指定 error_reporting = E_ALL & ~E_STRICT 但它没有用。
    • 为我工作,究竟是什么没有工作?你还在收到同样的 E_STRICT 消息吗?
    • 是的,我仍然收到严格的信息。但是,我找到了解决方案并将其发布为答案。感谢您的帮助,我相信它会帮助其他人。
    【解决方案2】:

    事实证明,我遵循了几个过时的教程,这些教程使用了旧的、未维护的 Behat 版本 (2.4.*)。我通过在 Behat 的 Github 存储库上提出问题了解到这一点:

    https://github.com/Behat/Behat/issues/773#issuecomment-126410052

    最终为我工作的 composer.json 是:

    {
        "require": {
            "behat/behat": "@stable",
            "behat/symfony2-extension": "@stable",
            "behat/mink": "@stable",
            "behat/mink-extension": "@stable",
            "behat/mink-browserkit-driver": "@stable",
            "behat/mink-goutte-driver": "@stable",
            "behat/mink-selenium2-driver": "@stable",
            "phpunit/php-code-coverage": "@stable",
            "phpunit/phpunit-mock-objects": "@stable",
            "phpunit/phpunit": "@stable"
            },
        "config": {
            "bin-dir": "bin/"
        }
    }
    

    而我的 behat.yml 是:

    default:
      suites:
          default:
              contexts:
                  - FeatureContext:
                      parameters:
                          my_empty_array:
                              'mydummykey1': 'mydummyvalue1'
      extensions:
        Behat\MinkExtension:
          base_url: http://localhost
          goutte: ~
          selenium2: ~
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-30
      • 2011-05-22
      • 2011-09-02
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 2012-08-27
      • 2013-05-11
      相关资源
      最近更新 更多