XWizard
XWizard

Reputation: 339

phpunit composer file not found

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?

Upvotes: 1

Views: 143

Answers (1)

Tomas Votruba
Tomas Votruba

Reputation: 24280

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.

Upvotes: 1

Related Questions