简体   繁体   中英

Class 'PHPUnit_Framework_TestCase' not found in Symfony2 project

I'm developing a project in symfony2 and I'm new with unit testing.

I have installed PHPUnit 3.6.10 via PEAR and it works from the terminal when I digit the phpunit command.

I wrote my first test class following the SensioLab suggestions ( http://symfony.com/doc/current/book/testing.html ) but when I use the command

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

I got

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

Here you are my test class:

<?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);
    }
}

I read this discussion Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...? but the symfony documentation doesn't say to include PHPUnit...

What I'm doing wrong? Thank you

I just had a similar issue (with DoctrineFixturesBundle), and solved it by adding PHPUnit to Symfony (as opposed to installing PHPUnit via PEAR).

What worked for me was:

1) add "phpunit/phpunit": "4.0.*" to the require section of composer.json :

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

2) running from the commandline:

php composer.phar update phpunit/phpunit

In case someone runs into a similar issue.

1- Install PHPUnit following this procedure :

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

2- Run your tests as described here :

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

The -c app/ option will be looking for a configuration file in the app/ directory. This configuration file is app/phpunit.xml.dist .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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