Error when I try run PHPUnit from PhpStorm

Hello,

I have little problem when I'm trying to run PHPUnit test in 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.

Sample test class:

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


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

5 comments

Hi Piotr,

I have no clue what wrong you are doing -- works fine for me (managed to set it up from first attempt). BTW -- I'm on Windows 7 x64; PHP 5.4.13; PhpStorm v6.0.1 EAP build 129.240

  1. Empty project
  2. Tools | Composer | Init Composer -- download from internet
  3. Tools | Composer | Add dependency
  4. Choose phpunit/phpunit (v3.7.19) -- took a bit time to download and install (around 30-40 seconds) but did it OK (my first attempt to use composer in PhpStorm)
  5. Created file with your code in PROJECT/tests/ReaderTest.php
  6. Settings | PHP -- select/configure PHP interpreter
  7. Settings | PHP | PHPUnit --> Use custom loader --> PROJECT\vendor\autoload.php
  8. Run | Edit Configuration
  9. Created new one of "PHPUnit" type
  10. Tests scope = Directoiry; Path = PROJECT\\tests
  11. Run


screen01.png

I'm attaching my whole project (just use "Open Directory" in PhpStorm.

P.S.
It's 7zip archive format; I'm on Windows, so you may need to alter some paths to your OS format.



Attachment(s):
composer_phpunit.7z.zip
0

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.

0

Hi Andriy,

thanks for your post.
I did your steps and loaded phpunit with composer, but as i run the test, i got 3 warnings and 1 fatal error:
     Test framework quit unexpectedly;

Warning: include(C:\Users\Ben\devZone\yak\vendor/phpunit/phpunit/PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in C:\Users\Ben\devZone\yak\vendor\composer\ClassLoader.php on line 382

Warning: include(): Failed opening 'C:\Users\Ben\devZone\yak\vendor/phpunit/phpunit/PHPUnit/Runner/Version.php' for inclusion (include_path='C:\Users\Ben\devZone\yak\vendor/phpunit/php-text-template;C:\Users\Ben\devZone\yak\vendor/phpunit/phpunit-mock-objects;C:\Users\Ben\devZone\yak\vendor/phpunit/php-timer;C:\Users\Ben\devZone\yak\vendor/phpunit/php-token-stream;C:\Users\Ben\devZone\yak\vendor/phpunit/php-code-coverage;C:\Users\Ben\devZone\yak\vendor/phpunit/phpunit;C:\Users\Ben\devZone\yak\vendor/symfony/yaml;.;C:\Users\Ben\devZone\pear\pear;C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library') in C:\Users\Ben\devZone\yak\vendor\composer\ClassLoader.php on line 382

Warning: require_once(PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in C:\Users\Ben\AppData\Local\Temp\ide-phpunit.php on line 49

Fatal error: require_once(): Failed opening required 'PHPUnit/Runner/Version.php' (include_path='C:\Users\Ben\devZone\yak\vendor/phpunit/php-text-template;C:\Users\Ben\devZone\www.kurzurlaub.de\yak\vendor/phpunit/phpunit-mock-objects;C:\Users\Ben\devZone\yak\vendor/phpunit/php-timer;C:\Users\Ben\devZone\yak\vendor/phpunit/php-token-stream;C:\Users\Ben\devZone\yak\vendor/phpunit/php-code-coverage;C:\Users\Ben\devZone\yak\vendor/phpunit/phpunit;C:\Users\Ben\devZone\yak\vendor/symfony/yaml;.;C:\Users\Ben\devZone\pear\pear;C:\Program Files (x86)\Zend\ZendServer\share\ZendFramework\library') in C:\Users\Ben\AppData\Local\Temp\ide-phpunit.php on line 49

Process finished with exit code 255


this is my my test-class:

<?php
/**
* Created by PhpStorm.
*/

namespace projects
\pages\search;

class controllerTest extends \PHPUnit_Framework_TestCase {

    public function testTrueIsTrue(){
        $foo=true;
        $this->assertTrue($foo);
    }
}



some information to my workflow:
phpstorm 8.0.3
windows 8.1
phpunit 3.7.38 (installed with composer)

if you can help me, it would be great

kind regards,
ben

0

Well .. as far as I understood the message it says that PHP cannot find/load certain PHPUnit files (vendor/phpunit/phpunit/PHPUnit/Runner/Version.php in particular).

1) Do you have such file there?
2) Maybe try another PHPUnit version or reinstall this one again.

https://confluence.jetbrains.com/display/PhpStorm/Testing+PHP+Applications

0

Thanks for your answer.

I asked yesterday a friend, too.
We updated PHP and now everything is fine.

Thanks for your very fast engagement.

0

Please sign in to leave a comment.