Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 411
Gianluca78 Avatar asked Oct 15 '12 17:10

Gianluca78


1 Answers

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
like image 160
Paolo Stefan Avatar answered Sep 29 '22 14:09

Paolo Stefan