PHPUnit class TestCase not found

I had the same problem and I solved it by extending my test class from the PHPUnit_Framework_TestCase class instead of using the namespace PHPUnit\Framework\TestCase. After rebuilding your project-structure it worked fine for me.

tests/unit/testMyClass.php

<?php
require './vendor/autoload.php';

class MyClassTest extends PHPUnit_Framework_TestCase {
     public function testCreateMyClass() {
        // Tests are written here
     }
}
?>

composer.json

{
   "name": "root/project",
   "authors": [
      {
           "name": "watzerm",
           "email": "[email protected]"
      }
   ],
   "require": {
       "phpunit/phpunit": "5.4.*"
   },
   "autoload": {
       "classmap": [
           "src/"
       ]
   }
}

Result

$./vendor/bin/phpunit tests/unit/testMyClass.php

PHPUnit 4.8.27 by Sebastian Bergmann and contributors.

.

Time: 252 ms, Memory: 2.25MB

OK (1 test, 0 assertions)

Please let me know if this worked out for you too!


I solved the problem with newer version of PHPUnit:

wget https://phar.phpunit.de/phpunit-6.0.phar
php phpunit-6.0.phar -c app/

Output:

PHPUnit 6.0.10 by Sebastian Bergmann and contributors.

..                                                                  2 / 2 (100%)

Time: 486 ms, Memory: 14.00MB

OK (2 tests, 3 assertions)

This is working on Symfony 2.8 LTS and PHPunit 6.0 github repo - https://github.com/nikola-bodrozic/PHPUnit-Symfony28