繁体   English   中英

在Symfony2项目中找不到类'PHPUnit_Framework_TestCase'

[英]Class 'PHPUnit_Framework_TestCase' not found in Symfony2 project

我正在symfony2开发一个项目,我是单元测试的新手。

我已经通过PEAR安装了PHPUnit 3.6.10,当我对phpunit命令进行编号时,它可以在终端上运行。

我按照SensioLab建议( http://symfony.com/doc/current/book/testing.html )编写了我的第一个测试类,但是当我使用命令时

php -c app src/My/CalendarBundle/Tests/Calendar/CalendarTest.php 

我有

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /Library/WebServer/Documents/calendar/src/My/CalendarBundle/Tests/Calendar/CalendarTest.php on line 7

在这里,您是我的测试类:

<?php
namespace My\CalendarBundle\Tests\Calendar;

use My\CalendarBundle\Calendar\Calendar;

class CalendarTest extends \PHPUnit_Framework_TestCase
{
    public function testGetNextMonth()
    {
        $calendar = new Calendar('09', '2012', null);        
        $result = $calendar->getNextMonth();

        $this->assertEquals(10, $result);
    }
}

我读了这个讨论为什么,致命的错误:类'PHPUnit_Framework_TestCase'找不到...? 但symfony文档并未说明包含PHPUnit ...

我做错了什么? 谢谢

我刚刚遇到了类似的问题(使用DoctrineFixturesBundle),并通过向Symfony添加PHPUnit来解决它(而不是通过PEAR安装PHPUnit)。

对我有用的是:

1)将"phpunit/phpunit": "4.0.*"composer.jsonrequire部分:

{
    "require": {
        ...
        "phpunit/phpunit": "4.0.*"
    }
}

2)从命令行运行:

php composer.phar update phpunit/phpunit

万一有人遇到类似的问题。

1-按照以下步骤安装PHPUnit

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

2-按照此处所述运行测试:

$ phpunit -c app/ src/My/CalendarBundle/Tests/Calendar/CalendarTest.php 

-c app/选项将在app/目录中查找配置文件。 此配置文件是app/phpunit.xml.dist

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM