【问题标题】:Can't set up PHPunit to work with Yii on Windows无法设置 PHPunit 在 Windows 上与 Yii 一起使用
【发布时间】:2012-12-11 12:14:42
【问题描述】:

PHPUnit 适用于其他项目,但是当我尝试运行 Yii 测试时,我收到以下警告(即使是空测试):

有 1 次失败:

1) 警告

警告:include(PHP_Invoker.php):打开流失败:没有这样的文件 或目录 C:\Users\pumpkin\Documents\GitHub\arhano\codebase\arhanoii\vendor\yiisoft\yii\framework\YiiBase.php 在第 423 行

警告:include():未能打开“PHP_Invoker.php”以包含在内 (include_path='.;C:\Users\pumpkin\Documents\GitHub\arhano\codebase\arhanoii\componen ts;C:\Users\pumpkin\Documents\GitHub\arhano\codebase\arhanoii\models;C:\xampp\php\PEAR') 在 C:\Users\pumpkin\Documents\GitHub\arhano\codebase\arhanoii\ vendor\yiisoft\yii\framework\YiiBase.php 在第 423 行

看起来我必须安装 phpunit/PHP_Invoker,但这是不可能的,因为它需要 pcntl PHP 扩展,这在 Win 上不可用。

您知道如何消除此警告吗?是否可以在不使用 PHP_Invoker 的情况下在 Windows 上运行 Yii 测试?

【问题讨论】:

    标签: php yii phpunit


    【解决方案1】:

    该文件是(PSR-0 兼容)PHP/Invoker.php,因此您需要更改 YiiBase.php 并将那里的_ 替换为/

    【讨论】:

      【解决方案2】:

      @cweiske : 该行实际上是 PHPUnit 的 autoload() 使用的,因此无法更改。

      @Alex:我这里也有同样的问题,原因是 PHPUnit 的 PHP_Invoker 不能在 Windows 上工作,因为它依赖于一个名为“pcntl”的扩展,它只能在 UNIX 系统上工作。由于问题来自在 Windows 上运行的第三方框架,我相信 Sebastian Bergmann 不会太在意这个问题:https://github.com/sebastianbergmann/php-invoker/issues/6

      无论如何,测试似乎运行良好。所以...

      【讨论】:

        【解决方案3】:

        这是一个对我有用的解决方案: https://github.com/yiisoft/yii/issues/1907#issuecomment-14519537

        引用:

        • 去了pear.phpunit.de
        • 手动下载的 PHP_Invoker 实用程序类
        • 在我女儿的 Mac 上解压缩文件(我运行的是 Windows)
        • 将“Invoker”目录放到C:\xampp\php\pear\PHP下
        • 将“Invoker.php”文件放到C:\xampp\php\pear\PHP下

        我在 Windows 7 机器上,解压缩工作正常。不需要mac...

        测试在任何情况下都运行良好,但现在我不再烦人了 “包括(PHP_Invoker.php):无法打开流” 每次在测试过程中发生错误时的消息。

        【讨论】:

        • 感谢@c-cba,您指出的评论也解决了我的问题。提及以帮助其他用户。
        【解决方案4】:

        对我有用的 phpunit 安装指南(Windows 7、XAMPP): http://learnyii.blogspot.com/2011/08/how-to-install-phpunit-on-windows.html

        在命令提示符中(以管理员身份):

        pear channel-update pear.php.net  
        pear upgrade-all  
        pear channel-discover pear.phpunit.de  
        pear channel-discover components.ez.no  
        pear channel-discover pear.symfony-project.com  
        pear update-channels  
        pear install -a -f phpunit/PHPUnit
        

        附言
        如果您遇到 PHPUnit_Extensions_Selenium_TestCase 错误,请使用:

        pear install phpunit/PHPUnit_Selenium
        

        如果您遇到 PHPUnit_Extensions_Story_TestCase 错误,请使用:

        pear install phpunit/PHPUnit_Story
        

        【讨论】:

          【解决方案5】:

          this tutorial 之后稍作调整对我们有用。

          它基本上是在 Invoker 存储库中克隆的。我假设 Invoker 仍然无法工作,但它会阻止 PHPUnit 出错:

          {
              "repositories": [
                  {
                      "type": "composer",
                      "url": "http://packages.phundament.com"
                  },
                  {
                      "type": "package",
                      "package": {
                          "name": "phpunit/php-invoker",
                          "version": "1.1.3",
                          "source": {
                              "type": "git",
                              "url": "http://github.com/sebastianbergmann/php-invoker",
                              "reference": "master"
                          },
                          "autoload": {
                              "classmap": [
                                  "src/"
                              ]
                          }
                      }
                  }
              ],
              "require-dev": {
                  "phpunit/phpunit": "4.1.*",
                  "phpunit/phpunit-selenium": "*",
                  "phpunit/phpunit-skeleton-generator": "*",
                  "phpunit/dbunit": "*",
                  "phpunit/phpunit-story": "*",
                  "phpunit/php-invoker": "*",
                  "phpunit/phpunit-mock-objects": "*"
              }
          } 
          

          【讨论】:

            猜你喜欢
            • 2013-06-19
            • 1970-01-01
            • 1970-01-01
            • 2019-10-26
            • 1970-01-01
            • 1970-01-01
            • 2015-01-08
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多