phpphpunit

PHPUnit 'Error : Class "path\to\class\classToTest" not found'


I'm trying to write some unit tests. However no matter what I do I keep getting this error:

Error : Class "path\to\class\classToTest" not found

The test I'm trying to run has a simple structure:

<?php
namespace tests\unit;

use path\to\class\classToTest;
use PHPUnit\Framework\TestCase;

class className extends TestCase
{
  public function testname()
  {
    $classToTest = new classToTest;
    $result = $classToTest->test();
    $this->assertTrue($result);
  }
}

The classToTest looks like this:

<?php
namespace path\to\class;

class classToTest
{
  public function test()
  {
    return true;
  }
}

The autoload of the composer.json looks like this:

"autoload":
{
  "psr-4":
  {
    "FolderClassIsIn\\": "folderClassIsIn/"
  }
}

Solution

  • The issue was with case sensitivity.

    Even when the folders were all lowercase, when using namespaces the first letter had to be uppercase.