【问题标题】:Update PHPunit Xampp更新 PHPunit Xampp
【发布时间】:2017-08-28 12:58:35
【问题描述】:

今天早上,我意识到 Xampp 提供的 PHPUnit 版本已经被弃用了一段时间...... . 版本 3.7.21。安装在 Xampp 中,但实际版本(在撰写本文时)是 6.0.13。

我尝试了一些在谷歌上提出的解决方案(所有旧的 5 年 + 解决方案),包括

无论如何,梨似乎不是一个可行的解决方案。有没有简单的方法在 Xampp 中更新 PHPUnit?

【问题讨论】:

    标签: php windows xampp phpunit updates


    【解决方案1】:

    我遇到了类似的问题并找到了不同的解决方案。 我已经用 composer globaly 安装了 phpunit

    composer global require phpunit/phpunit "^9"
    

    和我项目中的本地化(两个相同的版本“^9”)。

    cd C:/fullpath/to/myproject
    
    composer require-dev phpunit/phpunit "^9"
    

    但是由于某种原因,phpunit 是从 xampp 文件夹中触发的。所以我所做的被删除了

    phpunit
    phpunit.bat
    

    来自C:\xampp\php,它对我有用。

    记住在 Windows 中将 Composer 路径设置为您的 env 路径。

    现在您可以在项目根目录中创建 phpunit.xml(这对我有用):

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.0/phpunit.xsd"
             bootstrap="vendor/autoload.php"
             colors="true"
             testdox="true"
             verbose="false"
             convertErrorsToExceptions="true"
             convertNoticesToExceptions="true"
             convertWarningsToExceptions="true"
             forceCoversAnnotation="true"
             processIsolation="false"
             stopOnError="false"
             stopOnFailure="false"
             stopOnIncomplete="false"
             stopOnSkipped="false"
             stopOnRisky="false">
             
        <testsuites>
            <testsuite name="default">
                <directory suffix="Test.php">tests</directory>
            </testsuite>
        </testsuites>
    
        <filter>
            <whitelist processUncoveredFilesFromWhitelist="true">
                <directory suffix=".php">src</directory>
            </whitelist>
        </filter>
    </phpunit>
    

    然后只需 cd 到我的根目录并在我的终端中运行 phpunit 以运行 tests 文件夹中的所有测试

    希望这些信息对您有所帮助 *编辑:Hypper.js - 在 Windows 10 上使用 Git Bash(以防万一)

    【讨论】:

      【解决方案2】:

      谢谢,使用 XAMPP v7.3.7 工作正常

      最新的phpunit.phar可以从:https://phar.phpunit.de下载

      • XAMPP 包含的版本 = Sebastian Bergmann 的 PHPUnit 3.7.21。
      • 下载版本 (2019-08-11) = Sebastian Bergmann 和贡献者的 PHPUnit 8.3.4。

      【讨论】:

        【解决方案3】:

        其实可以通过三个简单的步骤来更新:

        1. 在此处下载最新版本的 PHPUnit: https://phpunit.de/index.html
        2. 将“phpunit.phar”复制到“C:\xampp\php”中。
        3. 在文件:“phpunit.bat”中,更新以下行: "%PHPBIN%" "C:\xampp\php\phpunit" %* 至:"%PHPBIN%" "C:\xampp\php\phpunit.phar" %*

        你不需要重启 apache。

        附加说明:在您的测试中,您需要将:phpunit_framework_testcase 替换为:TestCase

        并在测试文件的顶部包含:use PHPUnit\Framework\TestCase

        当然,测试套件在我的生产服务器上仍然兼容(centos7,在Linux上按照官方文档更新https://phpunit.de/getting-started.html)。

        【讨论】:

        • 谢谢!我假设在第 3 步中您打算编辑 phpunit.bat 而不是 phpdoc.bat
        • 感谢您的帖子。这个对我有用。在第 3 点中,应该是“phpunit.bat”而不是“phpunit.bat.bat”。
        • @Frank Liu 已修复。感谢您的反馈。
        猜你喜欢
        • 1970-01-01
        • 2017-04-25
        • 2012-12-15
        • 1970-01-01
        • 2016-04-12
        • 2011-08-13
        • 2023-03-20
        • 2012-02-29
        • 1970-01-01
        相关资源
        最近更新 更多