【问题标题】:Setup include path for PEAR on Wamp设置包括 Wamp 上 PEAR 的路径
【发布时间】:2011-12-28 02:40:24
【问题描述】:

安装 PEAR 并按照http://www.phpunit.de/manual/current/en/installation.html 上的说明进行操作:

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

然后,我创建了测试:

<?php
# error reporting
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

# include TestRunner
require_once 'PHPUnit/TextUI/TestRunner.php';

# our test class
class ExampleTest extends PHPUnit_Framework_TestCase
{
    public function testOne()
    {
        $this->assertTrue(FALSE);
    }
}

# run the test
$suite = new PHPUnit_Framework_TestSuite('ExampleTest');
PHPUnit_TextUI_TestRunner::run($suite);
?>

我在 php.ini 文件中包含以下内容并重新启动了 Apache:

include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear"
include_path = ".;C:\Program Files/wamp/bin/php/php5.3.8/pear/PHPUnit"

我收到Warning: require_once(PHPUnit/TextUI/TestRunner.php) [function.require-once]: failed to open stream: No such file or directory in ...

为什么包含路径不起作用?是不是因为Program files里面有空格?

在 Windows XP 和 WAMP 中工作。

编辑:我按照建议更新了路径。

echo ini_get('include_path'); 在 require_once 调用之前的输出是:

.;C:\Program Files/wamp/bin/php/php5.3.8/pear

此外,删除 require_once 命令会抛出 Fatal error: Class 'PHPUnit_Framework_TestCase' not found in...

【问题讨论】:

  • 你能在你的 require_once 'PHPUnit/TextUI/TestRunner.php' 之前打印包含路径吗? echo ini_get('include_path');也许有什么东西覆盖了它
  • 在旁注中应该不需要手动在测试用例中包含来自 PHPUnit 的任何文件。当您从命令行运行 PHPUnit 时,它将注册自己的自动加载器。您只需要确保 PEAR 在您的 include_path 上。
  • 实际上,我确实参考了一些“我如何”的帖子。他们有许多不同的安装说明,但没有解决问题。
  • @BSeven 是的,它实际上根本不是 phpunit 问题。我修改了问题以反映这一点。也删除评论。您还应该通过运行php --ini 确保您在 CLI 上获得的 php 实际上是您使用该 php.ini 配置的那个。
  • 我只安装了一个版本的 PHP。我想我正在修改正确的 php.ini 文件,因为我可以使用 echo ini_get('include_path'); 看到路径的变化。

标签: php windows wamp pear include-path


【解决方案1】:

通过将这三行添加到 ini 中,最后一行将覆盖所有内容。只用这个

include_path = ".;C:\Program Files\wamp\bin\php\php5.3.8\pear"

编辑:添加@Gordon 评论。我们需要保留\pear。因为内部 pear 库假设 pear 已经在包含路径中。

http://pear.php.net/manual/en/installation.checking.php#installation.checking.cli.modifyingphpini

【讨论】:

  • 为什么是那个?为什么不include_path = ".;C:\Program Files\wamp\bin\php\php5.3.8
  • @BSeven 因为pear.php.net/manual/en/… ;)
猜你喜欢
  • 2011-12-28
  • 1970-01-01
  • 1970-01-01
  • 2013-04-01
  • 2011-10-20
  • 2012-06-12
  • 2012-03-10
  • 2011-02-23
  • 2013-05-20
相关资源
最近更新 更多