Using PSR-4 autoloading with Composer, when I try to test this class:
namespace User;
use User\Contracts\UserId;
use User\Contracts\User as UserContract;
class User implements UserContract
{
private $id;
public function __construct(UserId $id)
{
$this->id = $id;
}
public function getId()
{
return $this->id;
}
}
using PHPUnit:
use User\Contracts\UserId;
class UserTest extends \PHPUnit_Framework_TestCase
{
public function test_the_identifier_can_be_used_as_string()
{
$identifier = m::mock(UserId::class);
$identifier->shouldReceive('__toString')->once()->andReturn('foo');
$user = new User($identifier);
$this->assertSame('foo', (string) $user->getId());
}
}
I receive this error in the console
PHP Fatal error: Cannot use User\Contracts\UserId as UserId because the name is already in use in /src/User/User.php on line 5
This is the file/folder structure:
src
`-- User
|-- Contracts
| |-- User.php
| `-- UserId.php
|-- User.php
`-- UserId.php
tests
`-- User
|-- UserIdTest.php
`-- UserTest.php
I've done a lot of searches about this problems, but I've not found any solution about that.
- PHP Version: 5.6.13-1+deb.sury.org~trusty+3
- PHPUnit version: 5.0.3
- OS: Ubuntu 14.04.3 LTS
How can I solve this problem?