Is it possible to have my classes autoload with PHPUnit?

I am attempting to add PHPUnit testing to my PHPStorm project.

I understand that there is an incompatability between PHPUnit 4.6 and PHPStorm, so I am using PHPUnit 4.5.

I am using Composer to manage the PHPUnit dependency. In File | Settings | Languages and Frameworks | PHP | PHPUnit, I have set "PHP unit library" to "use custom autoloader" and set the path to script as <project_root>/ventor/autoload.php, per the instructions here.

When I run my unit tests, however, they do not load my classes. I can get them to run by adding require_once calls, but I am wondering if there is a way to get them to autoload my classes, like what happens when I run the project as a server.

1 comment
Comment actions Permalink

Hi there,

1) PhpStorm v8 supports PHPUnit 4.6 if installed via Composer but not if PHAR file is used. The 4.6 PHAR file support was added in v9 (currently in EAP stage).

2) You can add rules for autoloading into your composer.json ("autoload" section) and then use "composer update" (or "composer dump-autoload") so it will include your rules in its' "autoload.php"

3) If you have your own autoloader and prefer to use it instead of Composer's -- do it in bootstrap.php file (you can specify such file in PhpStorm's settings for PHPUnit or via PHPUnit's own config file -- phpunit.xml)

0

Please sign in to leave a comment.