使用PHPUnit进行单元测试& Doctrine2:自动加载失败

时间:2010-12-25 06:39:17

标签: zend-framework phpunit doctrine-orm zend-test

我收到此错误

D:\Projects\Tickle\tests>phpunit
PHPUnit 3.5.5 by Sebastian Bergmann.

..........ok1
Fatal error: Doctrine\Common\ClassLoader::loadClass(): Failed opening required 'D:\Projects\Tickle\Application\Models\Ap
plication\Models\User.php' (include_path='D:\Projects\Tickle\application/../library;D:\Projects\Tickle\application;D:\Pr
ojects\Tickle\library;D:\ResourceLibrary\Frameworks\PHPFrameworks;C:\Program Files (x86)\PHP\pear;.;c:\php\includes') in
 D:\ResourceLibrary\Frameworks\PHPFrameworks\Doctrine\Common\ClassLoader.php on line 148

请注意D:\Projects\Tickle\Application\Models\Application\Models\User.php的重复“Application\Models”。在一些echo语句

的帮助下,我将其缩小为单元测试的1个函数
protected function isAllowed($userId, $taskId, $privilege) {
  $user = $this->em->find('Application\Models\User', $userId);
  echo 'ok1'; // this gets printed
  $task = $this->em->find('Application\Models\Task', $taskId); // this seem to be the cause of the problem
  echo 'ok2'; // this doesn't get printed
  return $this->acl->isAllowed($user, $task, $privilege);
}

完整的课程http://pastebin.com/rJungFvP

所以我尝试在Tasks类中查找使用User的东西......唯一可以使用User类的东西是

/**
 * @ManyToOne(targetEntity="User", inversedBy="ownedTasks")
 */
protected $owner;

/**
 * @ManyToOne(targetEntity="User", inversedBy="assignedTasks")
 */
protected $assigned;

除此之外,我没有看到任何用户的使用。全班http://pastebin.com/wDPXUPSV

我做错了什么?

1 个答案:

答案 0 :(得分:0)

问题实际上是在TodoList课程中找到的...我有类似

的内容
public function setProject(Application\Models\Project $project) {
  ...
}

当我应该使用像

这样的东西时
public function setProject(Project $project) {
  $this->project = $project;
}

代替