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

发布于 2024-10-09 02:33:13 字数 1663 浏览 1 评论 0原文

我收到此错误

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

请注意 Application\Models 的重复“D:\Projects\Tickle\Application\Models\Application\Models\User.php”。在一些 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

我做错了什么?

I am getting this error

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

Notice its repetition "D:\Projects\Tickle\Application\Models\Application\Models\User.php" of Application\Models. I narrowed it down to 1 function of my unit tests with the help of some echo statements

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);
}

The full class http://pastebin.com/rJungFvP

So I tried looking of something in the Tasks class that uses User ... the only thing that might use the User class are

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

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

apart from that, I don't see use of any Users. full class http://pastebin.com/wDPXUPSV.

What did I do wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁吢 2024-10-16 02:33:13

问题实际上是在 TodoList 类中发现的......我遇到了类似的问题

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

,当我应该使用类似的东西

public function setProject(Project $project) {
  $this->project = $project;
}

The problem was actually found in the TodoList class ... I had something like

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

when I should be using something like

public function setProject(Project $project) {
  $this->project = $project;
}

instead

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文