I just installed PHPUnit version 3.7.19 from Sebastian Bergman through Composer and wrote a class that I would like to unit test.
I would like all my classes to be automatically loaded into each unit test without , to use include or require at the top of my test, but it is complicated!
This is what my directory structure looks like (trailing / slash indicates a directory, not a file):
- composer.json
- composer.lock
- composer.phar
- Library /
- Tests /
- seller /
- bin /
- composer /
- PHPUnit /
- Symfony /
- autoload.php
My composer.json file contains the following:
"require": { "phpunit/phpunit": "3.7.*", "phpunit/phpunit-selenium": ">=1.2" }
The return.php class file contains the following:
<?php class Returning { public $var; function __construct(){ $this->var = 1; } } ?>
My test file returnTest.php includes the following:
<?php class ReturningTest extends PHPUnit_Framework_TestCase { protected $obj = null; protected function setUp() { $this->obj = new Returning; } public function testExample() { $this->assertEquals(1, $this->obj->var); } protected function tearDown() { } } ?>
However, when I run ./vendor/bin/phpunit tests from the command line, I get the following error:
PHP Fatal error: Return class not found in /files/code/php/db/tests/returningTest.php on line 8
I noticed that composer created the autoload.php file in vendor/autoload.php , but I'm not sure if this is relevant for my problem.
Also, in some other answers on Qaru, people mentioned something about using PSR-0 in composer and the namespace command in PHP, but I have not had success in using one of them.
Please, help! I just want to autoload my classes in PHPUnit, so I can just use them to create objects without worrying about include or require .
Update: August 14, 2013
Now I have created an open source project called PHPUnit Skeleton to help you quickly and easily test PHPUnit for your project.