麻烦包括PHPUnit [英] trouble including PHPUnit

查看:112
本文介绍了麻烦包括PHPUnit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始为我的代码编写测试,所以我使用以下命令安装了最新的PHPUnit

I want to start writing tests for my code so I installed the latest PHPUnit with the following commands

wget http://pear.phpunit.de/get/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

http:// phpunit.de/manual/3.8/en/installation.html

然后我将/ usr / local / bin添加到我的php.ini包含路径像这样

then I added /usr/local/bin to my php.ini include path which looks like this

include_path =。/ Applications / MAMP / bin / php / php5.4.10 / lib / php:/ usr / bin

但我遇到以下错误当我访问 /my-app/test.php

but I'm getting the following errors when I visit /my-app/test.php


警告(2):include(PHPUnit / Autoload.php):无法打开流:No
这样的文件或目录
[CORE / Cake / TestSuite / CakeTestSuiteDispatcher.php,第150行]

Warning (2): include(PHPUnit/Autoload.php): failed to open stream: No such file or directory [CORE/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 150]

警告(2):include包含]:无法打开
'PHPUnit / Autoload.php'包含
(include_path ='/ Users / DevinCrossman / Sites / studio-bliss / lib:。/ Applications / MAMP / bin / php / php5.4.10 / lib / php:/ usr / local / bin')
[CORE / Cake / TestSuite / CakeTestSuiteDispatcher.php,第150行]

Warning (2): include() [function.include]: Failed opening 'PHPUnit/Autoload.php' for inclusion (include_path='/Users/DevinCrossman/Sites/studio-bliss/lib:.:/Applications/MAMP/bin/php/php5.4.10/lib/php:/usr/local/bin') [CORE/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 150]

我尝试将 / usr / local / bin / phpunit 更改为 / usr / local / bin / PHPUnit 但是没有工作。我也尝试改变包含路径从 / usr / local / bin / usr / local / bin / phpunit 重新启动apache(我在这台机器上使用MAMP PRO,但它也没有在我的ubuntu服务器上工作)

I tried changing /usr/local/bin/phpunit to /usr/local/bin/PHPUnit but that didn't work. I also tried changing the include path from /usr/local/bin to /usr/local/bin/phpunit and restarted apache (I'm using MAMP PRO on this machine but it also didn't work on my ubuntu server)

a phpinfo / code>显示包含路径设置正确。

a phpinfo() shows the include path is being set correctly.

这可能是一个明显的我错过了。谁能告诉我为什么这不工作?

it's probably something obvious that I've missed. Can anyone tell me why this isn't working?

推荐答案

CakePHP建议使用PEAR安装PHPUnit

将phar放在/ usr / local / bin中,文件名为'phpunit',意味着运行 PHPUnit的testrunner通过命令行,因为它会使phpunit命令可用。例如运行命令:

Putting the phar in /usr/local/bin with filename 'phpunit' is meant to be used by running PHPUnit's testrunner via the command line as it will make the phpunit command available. e.g. running command:

phpunit MyTest test.php

在浏览器中运行时,您需要PHPUnit类可用于加载,它不工作,只需在包含路径中包含您的phar的路径。
我不确定,但它可能工作,如果你包括phar在你的测试文件:

When running in the browser, you need the PHPUnit classes available to load which does not work by simply having the path to your phar in the include path. I'm not sure but it may work if you include the phar in your test file:

require_once '/path/to/phpunit.phar'

这篇关于麻烦包括PHPUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆