1

I have this structure of a project:

root
    -lib
        -dir
            -file1 (namespace PROJECT\dir\)
            -file2
    -tests
        -dir
            -file1Test
            -file2Test (namespace PROJECT\tests)
    -vendor

Composer.json is as follows:

 "require-dev":{
    "phpunit/phpunit": "5.0.*"
},
"autoload":{
"psr-4":{
    "PROJECT\\": "lib/"
    }
}

If I run tests without using classes from lib, everything works well. But (for example) if I have

file1Test.php

use PROJECT\dir\file1;

function void testMethod(){
$var = new file1();} 

I get this:

Class PROJECT\dir\file1 not found in full/path/to/file1Test.php

Does anyone know where the problem could be?

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
XWizard
  • 319
  • 6
  • 17

1 Answers1

1

You probably need to add phpunit.xml to your root, with following content.

<phpunit bootstrap="vendor/autoload.php">
</phpunit>

This would load all classes loaded by composer.

Tomas Votruba
  • 23,240
  • 9
  • 79
  • 115
  • After adding this file, I got unfortunately the same error. – XWizard Oct 12 '15 at 17:04
  • I would try camel case naming. Project\Lib\File1. Your naming is not really standard. See PSR-1 for file naming standard, that is used by composer. PSR-4 is its simpler successor. – Tomas Votruba Oct 13 '15 at 00:12