Class 'PHPUnit_Framework_TestCase' not found in Symfony2 project
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
Gianluca78
Updated on June 13, 2022Comments
-
Gianluca78 almost 2 years
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
-
Marcel Burkhard over 9 yearsChances are you don't need phpunit in your production environment. That said I would add it to require-dev not require.
-
Vasily over 8 yearsOr you can install it from command line: composer require --dev phpunit/phpunit (--dev parameter for placing the dependency to the require-dev section of composer.json )