gpt4 book ai didi

php - 在 Symfony2 项目中找不到类 'PHPUnit_Framework_TestCase'

转载 作者:可可西里 更新时间:2023-11-01 13:43:17 25 4
gpt4 key购买 nike

我正在 symfony2 中开发一个项目,我是单元测试的新手。

我已经通过 PEAR 安装了 PHPUnit 3.6.10,当我输入 phpunit 命令时它可以从终端运行。

我按照 SensioLab 的建议 (http://symfony.com/doc/current/book/testing.html) 编写了我的第一个测试类,但是当我使用命令时

php -c app src/My/CalendarBundle/Tests/Calendar/CalendarTest.php 

我得到了

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /Library/WebServer/Documents/calendar/src/My/CalendarBundle/Tests/Calendar/CalendarTest.php on line 7

这是我的测试类:

<?php
namespace My\CalendarBundle\Tests\Calendar;

use My\CalendarBundle\Calendar\Calendar;

class CalendarTest extends \PHPUnit_Framework_TestCase
{
public function testGetNextMonth()
{
$calendar = new Calendar('09', '2012', null);
$result = $calendar->getNextMonth();

$this->assertEquals(10, $result);
}
}

我阅读了这个讨论 Why, Fatal error: Class 'PHPUnit_Framework_TestCase' not found in ...?但是 symfony 文档没有说要包含 PHPUnit...

我做错了什么?谢谢

最佳答案

我刚刚遇到了类似的问题(与 DoctrineFixturesBundle),并通过将 PHPUnit 添加到 Symfony(而不是通过 PEAR 安装 PHPUnit)解决了这个问题。

对我有用的是:

1) 添加"phpunit/phpunit": "4.0.*"composer.jsonrequire部分:

{
"require": {
...
"phpunit/phpunit": "4.0.*"
}
}

2) 从命令行运行:

php composer.phar update phpunit/phpunit

关于php - 在 Symfony2 项目中找不到类 'PHPUnit_Framework_TestCase',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12900916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com