在共享服务器上安装 PHPUnit


Installing PHPUnit on Shared server

我正在尝试在共享主机服务器上安装PHPUnit,即GoDaddy。在GoDaddy提供的cpanel中,我可以看到PHP Pear扩展,在搜索时只给了我phpunit1,phpunit2,这是非常旧的版本,因为我们现在有phpunit 4.6。

这里的文档 https://phpunit.de/manual/3.7/en/installation.html#installation.phar 说使用

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

当我进入我的共享主机并做了一个wget时,它给了我拒绝的许可。

我想知道是否有办法让 godaddy 共享主机使用 cpanel 拥有 phpunit4.6。如果没有,我可以简单地在现有框架中下载phpunit并开始引用phpunit框架来编写我的测试用例吗?

您要做的是全局安装 PHPUnit。我从未使用过GoDaddy,但我可以假设,因为它是一个共享主机,您将永远不允许将phpunit.phar移动到bin文件夹。

尝试将其保留在本地文件夹中。这应该可以毫无问题地工作。

您也可以使用作曲家来安装它。在这里查看官方文档:https://phpunit.de/manual/current/en/installation.html

在搜索如何在 GoDaddy 帐户上安装 PHPUnit for CakePHP 2 时发现了这一点。

  • 根据/2.0/en/development/testing.html,PHPUnit 4 及更高版本与 CakePHP 2 不兼容。
  • 下载 sebastianbergmann/phpunit/tree/3.7
  • 从 acrchive 中提取PHPUnit文件夹并将其放在 /lib 下,/app文件夹旁边的那个,而不是它里面。

CakePHP 会自动将其添加到include_path中,并获取 PHPUnit 的Autoloader.php

现在,问题不是专门关于CakePHP。在这种情况下,只需确保 PHPUnit 位于您的包含路径中(您可以通过从命令行运行 php -i | grep include_path 或只是调用 phpinfo() 来读取它(