1

I'm trying to execute the PHPUnit test but the PHPUnit doesn't read any tests in my file:

hm@BP_PC3:/mnt/c/MAMP/htdocs$ phpunit
PHPUnit 6.0.10 by Sebastian Bergmann and contributors.



Time: 126 ms, Memory: 8.00MB

No tests executed!

But when i run ./vendor/bin/phpunit then i see the following output:

PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in /mnt/c/MAMP/htdocs/test/unit/CalcTest.php on line 5

I have configured my file like this:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit  bootstrap="./vendor/autoload.php"
          color="true"
          convertErrorsToExceptions="true"
          convertNoticesToExceptions="true"
          convertWarningsToExceptions="true"
          stopOnFailures="false"
          syntaxCheck="false">
     <testsuites>
          <testsuite name="PHPUnit Tuts">
               <directory>test</directory>
          </testsuite>
     </testsuites>
</phpunit>

And thats the structure:

app - lib - calculator.php
|
test - unit - CalcTest.php
|
vendor - bin - (standard files)
|
composer.json
composer.lock
phpunit.xml

composer.json:

{    
     "autoload": {
          "psr-4": {
               "App\\": "app"
          }
     },
     "autoload-dev": {
           "files": ["test/unit/CalcTest.php"]
     },
     "require-dev" : {
          "phpunit/phpunit": "^6.0"
     }
}

And this is how my CalcTest.php looks like, actually very standard:

<?php 

require_once 'PHPUnit/Autoload.php';

class CalcTest extends \PHPUnit_Framework_TestCase {

     public function testAdd() {

          $this->assertTrue(true);

     }

}


?>

I have tried to delete the line "files" in composer.json and it didn't work either.

  • 1
    Please check this link may be you can find your solution. http://stackoverflow.com/questions/6065730/why-fatal-error-class-phpunit-framework-testcase-not-found-in – Maya Shah Mar 27 '17 at 08:38
  • This is what I did @Maya Shah. I wrote require_once 'PhPUnit/Autoload.php' and it did not help. Even if I would write the one above in that link I get: PHPUnit_Framework_Assert not found... – Banovi Partner GmbH Mar 27 '17 at 08:45
  • Try to clear cache with > composer clear-cache and then install again > composer install – Maya Shah Mar 27 '17 at 08:50
  • Didn't work. Same output – Banovi Partner GmbH Mar 27 '17 at 08:51
  • 1
    starting from PHPUnit v6 it is namespaced so you should extend `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase` – xmike Mar 27 '17 at 09:25
  • Very good PHPUnit_Framework_Assert not found.., is gone now, BUT now I have still "No tests executed!" – Banovi Partner GmbH Mar 27 '17 at 09:52
  • Ok i executed with this: phpunit test/unit/CalcTest.php and i see this: PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'test/unit/CalcTest' could not be found in '/mnt/c/MAMP/htdocs/test/unit/CalcTest.php'. in phar:///usr/local/bin/phpunit/phpunit/Runner/StandardTestSuiteLoader.php:107 Stack trace: #0 phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php(130): PHPUnit\Runner\StandardTestSuiteLoader->load('test/unit/CalcT...', '/mnt/c/MAMP/htd...') #1 phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php(71): PHPUnit\Runner\BaseTestRunner->loadSuiteClass – Banovi Partner GmbH Mar 27 '17 at 09:58
  • seems like you have several versions/instances of phpunit on the machine. How about trying `venor/bin/phpunit test/unit/CalcTest.php` or just `vendor/bin/phpunit` with no arguments -- it should use the `phpunit.xml` for configuration – xmike Mar 27 '17 at 10:11
  • I got the bug! I deleted "autoload-dev" from composer.json then i cleared the cache o f composer and installed again and now finally result: OK (1 test, 1 assertion). Thank you @xmike for your help! – Banovi Partner GmbH Mar 27 '17 at 10:18
  • well, that's good )) – xmike Mar 27 '17 at 10:38

0 Answers0