如何在Mac OS X 10.5上不使用PEAR的情况下安装PHPUnit?

And*_*rew 7 php pear phpunit

我在安装PEAR时遇到问题,但我真的只想安装PHPUnit.有没有人有这方面的经验?

tob*_*ius 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
Run Code Online (Sandbox Code Playgroud)

设置个人二进制路径

cd ~ && mkdir bin
vi ~/.profile
>> export PATH=$HOME/bin:$PATH
>> :wq
source ~/.profile
Run Code Online (Sandbox Code Playgroud)

创建可执行文件

touch ~/bin/phpunit
chmod 755 ~/bin/phpunit
Run Code Online (Sandbox Code Playgroud)

写可执行文件

#!/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();
Run Code Online (Sandbox Code Playgroud)

测试可执行文件

which phpunit
phpunit --version
Run Code Online (Sandbox Code Playgroud)


Cia*_*lty 4

来自PHPUnit 安装指南

尽管使用 PEAR 安装程序是安装 PHPUnit 的唯一受支持的方法,但您可以手动安装 PHPUnit。对于手动安装,请执行以下操作:

  1. 从http://pear.phpunit.de/get/下载发布存档并将其解压到 php.ini 配置文件的 include_path 中列出的目录。
  2. 准备 phpunit 脚本:
    1. 将 phpunit.php 脚本重命名为 phpunit。
    2. 将其中的 @php_bin@ 字符串替换为 PHP 命令行解释器的路径(通常为 /usr/bin/php)。
    3. 将其复制到路径中的目录并使其可执行(chmod +x phpunit)。
  3. 准备 PHPUnit/Util/Fileloader.php 脚本:
    1. 将其中的 @php_bin@ 字符串替换为 PHP 命令行解释器的路径(通常为 /usr/bin/php)。