更新 PHPunit Xampp

Update PHPunit Xampp

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

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

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

其实只要简单三步就可以更新:

  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)。

谢谢,使用 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。

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

composer global require phpunit/phpunit "^9"

和我项目中的 localy(都是相同的版本“^9”)。

cd C:/fullpath/to/myproject

composer require-dev phpunit/phpunit "^9"

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

phpunit
phpunit.bat

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

请记住在 Windows 中将作曲家路径设置为您的环境路径。

现在您可以在项目根目录中创建 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(以防万一)