简体   繁体   English

如何使用 PEAR 正确安装 PHPUnit?

[英]How do I correctly install PHPUnit with PEAR?

I have had to de- and reinstall a newer version of PHPUnit following these directions .我不得不按照这些说明卸载并重新安装较新版本的 PHPUnit。 Now when I'm launching this line现在当我启动这条线时

sudo pear install --alldeps phpunit/PHPUnit

I see an error message, that looks like this.我看到一条错误消息,看起来像这样。

Unknown remote channel: pear.symfony.com
phpunit/PHPUnit requires package "channel://pear.symfony.com/Yaml" (version >= 2.1.0)
No valid packages found

If I install just Yaml by launching如果我通过启动只安装 Yaml

sudo pear install symfony/YAML

an older version (1.0.6) will be installed that doesn't meet the dependency of PHPUnit.将安装不符合 PHPUnit 依赖性的旧版本 (1.0.6)。 How can I possibly solve this?我怎么可能解决这个问题?

I had the same problem while upgrading my phpunit.我在升级我的 phpunit 时遇到了同样的问题。

This solved the problem:这解决了这个问题:

pear channel-discover pear.symfony.com
pear install pear.symfony.com/Yaml

Then run:然后运行:

pear install --alldeps pear.phpunit.de/PHPUnit

OBS: I think the pear install pear.symfony.com/Yaml is not necessary. OBS:我认为pear install pear.symfony.com/Yaml没有必要。 I'm just posting it because it is exactly the way I solved my problem.我只是发布它,因为这正是我解决问题的方式。

Use this, as described in the PHPUnit docs : (i don't what sudo means, this is how I do it on a windows PC):使用它,如PHPUnit 文档中所述:(我不知道 sudo 是什么意思,这就是我在 Windows PC 上的做法):

pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit

I also had this error message:我也有这个错误信息:

Unknown remote channel: pear.symfony.com未知远程频道:pear.symfony.com

Solved creating an alias:解决了创建别名的问题:

pear channel-alias pear.symfony-project.com pear.symfony.com

and then接着

channel-discover pear.symfony-project.com

sudo pear channel-discover components.ez.no

sudo pear update-channels

sudo pear upgrade-all

sudo pear install --force --alldeps phpunit/PHPUnit

First: locate pear you may have multiple versions installed and this could be a pain.首先: locate pear您可能安装了多个版本,这可能会很痛苦。

At work we have something like this in our intranet:在工作中,我们的内部网中有这样的东西:

sudo [your pear install] channel-update pear.php.net  
sudo [your pear install] upgrade pear  
sudo [your pear install] channel-discover pear.phpunit.de  
sudo [your pear install] install --alldeps phpunit/PHPUnit

I know theres a more automated way to install it using: go-pear ( http://pear.php.net/manual/en/installation.getting.php )我知道有一种更自动化的安装方式: go-pear ( http://pear.php.net/manual/en/installation.getting.php )

However, if you already have some other install of pear it will totally wreck everything and you'll spend quite some time trying to fix it.但是,如果您已经安装了一些其他的 pear,它将完全破坏一切,并且您将花费相当多的时间来尝试修复它。 I think the biggest hurdle is being able to tell all the libraries where each other is.我认为最大的障碍是能够告诉所有图书馆彼此的位置。

sudo pear install -a phpunit
sudo pear channel-discover pear.phpunit.de

I had similar problem complaining about "Unknown remote channel: pear.symfony.com".我有类似的问题抱怨“未知的远程频道:pear.symfony.com”。 had to do (without sudo, I got weird error about cannot open some file)必须做(没有 sudo,我收到了关于无法打开某些文件的奇怪错误)

sudo pear channel-discover pear.symfony.com

then然后

sudo pear install phpunit/PHPUnit

Now I can see phpunit in my /usr/bin现在我可以在我的 /usr/bin 中看到 phpunit

Process mentioned by PutzKipa works however you might need super user privileges. PutzKipa 提到的过程可以工作,但是您可能需要超级用户权限。 For ubuntu add sudo before each command.对于 ubuntu,在每个命令之前添加 sudo。

Following Plínio César, I solved it finally, but with slight variation:在 Plínio César 之后,我终于解决了它,但略有不同:

First I did a "sudo apt-get remove phpunit" to remove the faulty installation.首先我做了一个“sudo apt-get remove phpunit”来删除错误的安装。 Then using pear to do the phpunit installation:然后使用pear进行phpunit安装:

sudo pear install pear.symfony.com/Yaml须藤梨安装 pear.symfony.com/Yaml

sudo pear channel-discover pear.phpunit.de sudo pear channel-discover pear.phpunit.de

sudo pear config-set auto_discover 1须藤梨配置集 auto_discover 1

sudo pear install --alldeps pear.phpunit.de/PHPUnit须藤梨安装 --alldeps pear.phpunit.de/PHPUnit

Thanks Plinio Cesar!!!感谢普利尼奥·塞萨尔!!!

The easiest way to obtain PHPUnit in Ubuntu, Debian, Fedora or OpenSUSE is to download a PHP Archive (PHAR) that has all required (as well as some optional) dependencies of PHPUnit bundled in a single file.在 Ubuntu、Debian、Fedora 或 OpenSUSE 中获取 PHPUnit 的最简单方法是下载一个 PHP 存档 (PHAR),它将 PHPUnit 的所有必需(以及一些可选)依赖项捆绑在一个文件中。

Open the terminal and type:打开终端并输入:

wget https://phar.phpunit.de/phpunit.phar  # download the PHP Archive (PHAR) file  
chmod +x phpunit.phar   
sudo mv phpunit.phar /usr/local/bin/phpunit   

There are many different versions of phpunit.phar at https://phar.phpunit.de/ . https://phar.phpunit.de/ 上有许多不同版本的 phpunit.phar。 If you use the first command, it will select and download the latest version.如果您使用第一个命令,它将选择并下载最新版本。

Note: The /usr/local/bin/ path in the last command is correct for Ubuntu, Debian, Fedora and OpenSUSE distributions and also for other Linux distributions that have a /usr/local/bin/ directory.注意:最后一个命令中的/usr/local/bin/路径对于 Ubuntu、Debian、Fedora 和 OpenSUSE 发行版以及其他具有/usr/local/bin/目录的 Linux 发行版都是正确的。

Reference: What is /usr/local/bin?参考: 什么是/usr/local/bin? Came across it in an script installation for Applescript but would like to know more 在 Applescript 的脚本安装中遇到了它,但想了解更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM