已安装PHPUnit但未找到类PHPUnit_TestCase

谈论第一个障碍。 我的测试脚本:</ p>

 &lt;?php 

require_once('PHPUnit / Framework.php');

class TransferResponseTest扩展PHPUnit_TestCase {

.. 。

}
</ code> </ pre>

运行我的测试用例:</ p>

  $ phpunit TransferResponseTest 

Fatal error :在第5行的
/ Volumes / Data / greg / code / syndicate / tests / TransferResponseTest.php中找不到类'PHPUnit_TestCase'
$ php -i | grep include_path
include_path =&gt; 。:/ usr / lib / php =&gt; 。:/ usr / lib / php
$ ls -l / usr / lib / php / PHPUnit /
total 8
drwxr-xr-x 16 root wheel 544 27 Mar 19:03 Extensions
drwxr-xr-x 28 root wheel 952 27 Mar 19:03 Framework
-rw-r - r-- 1根轮3193 27 Mar 19:03 Framework.php
drwxr-xr-x 8根轮272 27 Mar 19:03 Runner
drwxr- xr-x 5根轮170 27 Mar 19:03 TextUI
drwxr-xr-x 32根轮1088 27 Mar 19:03 Util
</ code> </ pre>

我复制了 /etc/php.ini-default </ code>到 /etc/php.ini </ code>并明确指定包含路径为 / usr / lib / php / </ code> 结束 / </ code>但仍未成功。</ p>

  $ php -i |  grep include_path 
include_path =&gt; 。:/ usr / lib / php / =&gt; 。:/ usr / lib / php /
$ phpunit TransferResponseTest.php
PHP致命错误:在第5行
/ Volumes / Data / greg / code / syndicate / tests / TransferResponseTest.php中找不到类'PHPUnit_TestCase'\ n $ phpunit --version
PHPUnit 3.4.11 by Sebastian Bergmann。
</ code> </ pre>

任何想法?</ p>
</ div>

展开原文

原文

Talk about falling at the first hurdle. My test script:

<?php

require_once('PHPUnit/Framework.php');

class TransferResponseTest extends PHPUnit_TestCase {

    ...

}

Running my test case:

$ phpunit TransferResponseTest

Fatal error: Class 'PHPUnit_TestCase' not found in 
/Volumes/Data/greg/code/syndicate/tests/TransferResponseTest.php on line 5
$ php -i | grep include_path
include_path => .:/usr/lib/php => .:/usr/lib/php
$ ls -l /usr/lib/php/PHPUnit/
total 8
drwxr-xr-x  16 root  wheel   544 27 Mar 19:03 Extensions
drwxr-xr-x  28 root  wheel   952 27 Mar 19:03 Framework
-rw-r--r--   1 root  wheel  3193 27 Mar 19:03 Framework.php
drwxr-xr-x   8 root  wheel   272 27 Mar 19:03 Runner
drwxr-xr-x   5 root  wheel   170 27 Mar 19:03 TextUI
drwxr-xr-x  32 root  wheel  1088 27 Mar 19:03 Util

I copied /etc/php.ini-default to /etc/php.ini and explicitly specified the include path as /usr/lib/php/ with an end / but still no success.

$ php -i | grep include_path
include_path => .:/usr/lib/php/ => .:/usr/lib/php/
$ phpunit TransferResponseTest.php 
PHP Fatal error:  Class 'PHPUnit_TestCase' not found in 
/Volumes/Data/greg/code/syndicate/tests/TransferResponseTest.php on line 5
$ phpunit --version
PHPUnit 3.4.11 by Sebastian Bergmann.

Any ideas?

1个回答



它不是 PHPUnit_TestCase </ code>,而是 PHPUnit_Framework_TestCase </ code>。 并且您不必要求在运行测试时已经由PHPUnit加载的“PHPUnit / Framework.php”。</ p>
</ div>

展开原文

原文

It's not PHPUnit_TestCase, but PHPUnit_Framework_TestCase. And you don't have to require 'PHPUnit/Framework.php' which is already loaded by PHPUnit by the time your tests are run.

duanmaifu3428
duanmaifu3428 啊真是个傻瓜。 我在阅读PHPUnit测试之前阅读了一篇关于编写PHPUnit测试的旧教程(之前我使用过Simple Test)。 谢谢!
10 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐