如何在Mac OS X 10.5上安装PHPUnit而不使用PEAR?

7
我安装PEAR遇到了问题,但我只想安装PHPUnit。有人有这方面的经验吗?
5个回答

8

通过GIT安装

您可以按照Git自述文件的说明进行操作:https://github.com/sebastianbergmann/phpunit/

使用"git"下载文件并将其放置在您的主目录中

cd ~ && mkdir phpunit && cd phpunit
git clone git://github.com/sebastianbergmann/phpunit.git
git clone git://github.com/sebastianbergmann/dbunit.git
git clone git://github.com/sebastianbergmann/php-file-iterator.git
git clone git://github.com/sebastianbergmann/php-text-template.git
git clone git://github.com/sebastianbergmann/php-code-coverage.git
git clone git://github.com/sebastianbergmann/php-token-stream.git
git clone git://github.com/sebastianbergmann/php-timer.git
git clone git://github.com/sebastianbergmann/phpunit-mock-objects.git
git clone git://github.com/sebastianbergmann/phpunit-selenium.git

设置个人二进制路径

cd ~ && mkdir bin
vi ~/.profile
>> export PATH=$HOME/bin:$PATH
>> :wq
source ~/.profile

创建可执行文件

touch ~/bin/phpunit
chmod 755 ~/bin/phpunit

编写可执行文件

#!/usr/bin/env php
<?php

// set main method
define('PHPUnit_MAIN_METHOD','PHPUnit_TextUI_Command::main');

// add phpunit to the include path
$paths = scandir($_ENV['HOME'].'/phpunit');
$includes = array();
foreach($paths as $path){
    if (!preg_match('/^\./', $path)){
        $includes[] = $_ENV['HOME'].'/phpunit/' . $path;
    }
}
set_include_path(implode(PATH_SEPARATOR,$includes).PATH_SEPARATOR.get_include_path());

// set the auto loader
require 'PHPUnit/Autoload.php';

// execute
PHPUnit_TextUI_Command::main();

测试可执行文件

which phpunit
phpunit --version

4
PHPUnit安装指南中得知:
尽管使用PEAR Installer是安装PHPUnit的唯一支持方式,但您也可以手动安装PHPUnit。对于手动安装,请执行以下操作:
  1. http://pear.phpunit.de/get/下载一个发行版存档,并将其提取到列在php.ini配置文件的include_path中的目录中。
  2. 准备phpunit脚本:
    1. 将phpunit.php脚本重命名为phpunit。
    2. 用您的PHP命令行解释器路径(通常为/usr/bin/php)替换其中的@php_bin@字符串。
    3. 将其复制到您的路径中并使其可执行(chmod +x phpunit)。
  3. 准备PHPUnit / Util / Fileloader.php脚本:
    1. 用您的PHP命令行解释器路径(通常为/usr/bin/php)替换其中的@php_bin@字符串。

我怎样才能确定我的PHP命令行解释器位于/usr/bin/php? - Andrew
另外,我已经多次更改我的包含路径,试图设置pear。Mac OS X 10.5的默认值应该是什么? - Andrew
which php 应该会告诉您系统隐式使用的二进制文件。 - Erik

0

最近我制作了一个phpunit的github分支, 当前可以(大部分地)在不使用pear的情况下运行。它可能适合你。


0

安德鲁,我正在努力安装PHPUnit。发现如果在php.ini中更新include_path后重新启动Web服务器会有很大帮助。 现在正在寻找PHP命令行解释器的确切位置(这就是我来到这里的原因)。我会保持你的知情。

萨宾


0

我今天刚安装了它。我的步骤如下:

  • 从/get/下载 - 我使用的是3.3.9.tgz
  • 将所有文件提取到pear目录中(pear-phpunit,PHPUnit/等)
  • 在上述文件中将@php_bin@更改为指向我的php二进制文件(/usr/bin/php)
  • 创建一个符号链接从pear-phpunit到/usr/local/bin/phpunit(ln -s /usr/share/php/pear/pear-phpunit /usr/local/bin/phpunit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接