19

I have little problem when I'm trying to run PHPUnit test in IDE PhpStorm.

I use composer file which looks:

{
    "require": {
        "phpunit/phpunit": "3.7.19"
    }
}

Now when I run test I recive exception: PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.'

What is wrong? When I included pear installed version test working OK.

//EDIT Sample test class:

 class ReaderTest extends PHPUnit_Framework_TestCase
    {
        /**
         * @test
         */
        public function shouldGetReadedValue ()
        {
            $this->assertTrue(true);
        }
    }

//EDIT2 Trace:

/usr/bin/php /tmp/ide-phpunit.php --no-configuration /path/to/my/project
Testing started at 14:53 ...
PHP Fatal error:  Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.' in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:183
Stack trace:
#0 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(315): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#1 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(389): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass))
#2 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('/var/www/php-sh...')
#3 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Runner/BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#4 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('/var/www/php-sh...', '', A in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php on line 183

Process finished with exit code 255
2
  • 1
    Can you show your unit test? Does your test class extend PHPUnit_Framework_TestCase? Commented Apr 12, 2013 at 12:43
  • 1
    I edit my question, and add sample test class. I have few test classes. Commented Apr 12, 2013 at 12:45

4 Answers 4

12

I found solution about this problem.

In Edit configurations in directory I set path to my tests catalog (/path/to/my/project/tests), after this tests are running properly.

Sign up to request clarification or add additional context in comments.

1 Comment

It's important to notice that the path has to be set via: Run > Edit Configuration > PhpUnit There, the Directory can be set. You do not(!) find this under File > Settings in PhpStorm.
6

This is what worked for me, thanks to Piotr's answer above, but I'm providing with a bit more exact detail here all the steps I had to do:

Steps to make it work (test in PHPStorm 8.0.1):

1) In Preferences > PHP > PHPUnit make sure that nothing is set for Default configuration file or default bootstrap file.

2) Make a custom PHPUnit Configuration via Run > Edit Configurations > in the Command Line subsection, and be sure to:

a) set Custom working directory: to be /absolute/path/to/vendor.

b) check "Use alternative configuration file:" and set it to /absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist

Then you can run any test class in the suite by specifying the class and file, or just check "Defined in the configuration file" to run all of them according to the config.

Comments

5

I have same problem when using composer.

The solution is to put your test file in its own directory. Here is my working phpunit, i put all my test in test directory.

<phpunit bootstrap="vendor/autoload.php" 
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    stopOnFailure="true">
    <testsuites>
        <testsuite name="Test Suite">
            <directory>test</directory>
        </testsuite>
    </testsuites>
</phpunit>

Hope it solves if anyone have same problem.. :)

Comments

0

Inside the PHPUnit_Framework_TestSuite, this code exists in the constructor:

if (!$theClass->isSubclassOf('PHPUnit_Framework_TestCase')) {
   throw new PHPUnit_Framework_Exception(
      'Class "' . $theClass->name . '" does not extend PHPUnit_Framework_TestCase.'
   );
}

I see in your example that you are extending PHPUnit_Framework_TestCase but the error suggests you are using PHPUnit_Extensions_RepeatedTest which extends PHPUnit_Extensions_TestDecorator which ultimately extends PHPUnit_Framework_Assert

PHPUnit_Framework_Assert
   |
   --PHPUnit_Extensions_TestDecorator
      |
      --PHPUnit_Extensions_RepeatedTest

Double check your tests because the error suggests you are attempting to run a TestSuite using a test extending PHPUnit_Extensions_RepeatedTest. Were you instead trying to extend PHUnit using Test Decorators?

http://docs.tadiavo.com/phpunit/www.phpunit.de/pocket_guide/3.1/en/extending-phpunit.html

That is all the advice I can currently offer without seeing your actual tests and how you are running them.

3 Comments

OK, but why when I run test from console everything is OK? I'm quite sure that my test is good. When I'm using PHPUnit as including external library and set appropriate configuration in PhpStorm works fine.
Your question stated that it doesn't work in PHPStorm. Perhaps you had the IDE configured incorrectly and now it works?
I was configure IDE like in manual. I add dependency successfully then I set custom loader to vendor/autoload.php. That's all what I did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.