0
votes

Trying to be a good back-end developer by jumping onto the bandwagon of Test-Driven Development I have just installed PHPUnit via composer. I then ran command vendor/bin/phpunit and could see that PHPUnit was correctly installed.

Below is my file structure:

-fileserver
  src
  tests/
  vendor
  composer.json
  composer.lock
  index.php
  phpunit.xml

Inside phpunit.xml file I have the contents below:

<?xml version="1.0" encoding="UTF-8"?>
  <phpunit colors="true">
    <testsuites>
      <testsuite name="File Server Test Suite">
        <directory>./fileserver/tests/</directory>
      </testsuite>
    </testsuites>
  </phpunit>

If I run vendor/bin/phpunit I can see that my configuration file has been loaded but no tests run.

I basically created a simple test file inside tests folder and extended PHPUnit_Framework_TestCase. All my test use the psr-4 namespace PhpUnitTest.

composer.json

//Other part excluded
"autoload": {
  "psr-4": { 
    "FileServer\\": "src" ,
    "PhpUnitTest\\": "tests"
  }

Sample test class

namespace PhpUnitTest;

 class StupidTest extends \PHPUnit_Framework_TestCase
 {
   public function testTrueIsTrue()
   {
     $foo = true;
     $this->assertTrue($foo);
   }
 }

However below is the output I get:

PS C:\wamp\www\fileserver> vendor/bin/phpunit
PHPUnit 3.7.14 by Sebastian Bergmann.

Configuration read from C:\wamp\www\fileserver\phpunit.xml



  Time: 3.53 seconds, Memory: 1.25Mb

←[30;43m←[2KNo tests executed!
←[0m←[2KPS C:\wamp\www\fileserver>

What have I missed? Why my test case has not been executed? Thanking you in advance.

1

1 Answers

1
votes

You're not adding the composer-generated autoloader to your phpunit.xml file. Set the bootstrap attribute on the phpunit tag. The paths to your testsuites are incorrect, too. The path should be relative to the phpunit.xml file, so you should loose the fileserver/ bit in the path

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true">
    <testsuites>
        <testsuite name="File Server Test Suite">
            <directory>tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

That ought to do it