I use composer and phpunit but the error "Class not found" is appeared.
Directory Structure:
- php_sample/sample/question/
- php_sample/sample/question/Hello.php
- php_sample/sample/question/tests/HelloTest.php
And created composer.json
{
"require-dev": {
"phpunit/phpunit": "4.5.*"
}
}
I installed the composer like this.
$ curl -sS https://getcomposer.org/installer | php
$ ./composer.phar update
$ ./composer.phar install --dev
Hello.php is like this.
<?php
namespace sample\question;
class Hello
{
public function hello()
{
return 'Hello, world';
}
}
?>
test/HelloTest.php is like this.
<?php
namespace sample\question\tests;
use sample\question\Hello;
class HelloTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Hello
*/
public $SUT;
/**
* @test
*/
public function canPrint()
{
$this->assertThat($this->SUT->hello(), $this->equalTo('Hello, world'));
}
protected function setUp()
{
$this->SUT = new Hello;
}
}
And then, I run the this script and the error is occurred.
$ vendor/bin/phpunit --bootstrap vendor/autoload.php tests/HelloTest.php
PHP Fatal error: Class 'sample\question\Hello' not found in /Users/foobar/work/php_sample/sample/question/tests/HelloTest.php on line 32
It would be great if you answer to me.