【问题标题】:Liip\FunctionalTestBundle\Test\WebTestCase' not found in C:\wamp\www\test\src\TestTask\PhotosBundle\Tests\Controller\ApiControllerTest.php在 C:\wamp\www\test\src\TestTask\PhotosBundle\Tests\Controller\ApiControllerTest.php 中找不到 Liip\FunctionalTestBundle\Test\WebTestCase'
【发布时间】:2016-04-14 07:30:49
【问题描述】:

当我运行命令php ApiControllerTest.php 时,它显示了这个错误:

Liip\FunctionalTestBundle\Test\WebTestCase' 在第 12 行的 C:\wamp\www\test\src\TestTask\PhotosBundle\Tests\Controller\ApiControllerTest.php 中找不到

我的作曲家如下:

"require-dev": {
    "sensio/generator-bundle": "~2.3",
    "symfony/phpunit-bridge": "~2.7",
    "hautelook/alice-bundle": "^1.1",
    "doctrine/doctrine-fixtures-bundle": "^2.3",
    "liip/functional-test-bundle": "^1.4",
    "phpunit/phpunit": "^4.8",
    "helmich/phpunit-json-assert": "^1.0

我的文件appkernel如下;

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
    $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
    $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    $bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
    $bundles[] = new Hautelook\AliceBundle\HautelookAliceBundle();
    $bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle();

我的测试控制器如下;我看不出问题出在哪里;一切都在这里,

<?php

namespace TestTask\PhotosBundle\Tests\Controller;

use Helmich\JsonAssert\JsonAssertions;
use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\BrowserKit\Client;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Response;

class ApiControllerTest extends WebTestCase
{
    use JsonAssertions;

    public function testPostInvalidPhoto()
    {
        $client = static::createClient();
        $client->request(
            'POST',
            '/photos',
            array(
                'tags' => array(
                    'ololo',
                    'trololo',
                )
            ),
            array('image' => $this->getFile(__FILE__)),
            array('HTTP_Accept' => 'application/json')
        );

当我使用命令运行它时:phpunit -c app/phpunit.xml.dist 或 php vendor/bin/phpunit -c app/phpunit.xml.dist 它显示 phpunit 无法识别

【问题讨论】:

  • 您应该尝试使用phpunit 命令运行测试,正如官方文档中所建议的那样:symfony.com/doc/current/book/testing.html 这应该可以使用以下命令之一:phpunit -c app/phpunit.xml.distphp vendor/bin/phpunit -c app/phpunit.xml.dist
  • 我尝试这样做,但它显示 phpunit 无法识别
  • 您能否添加我在您的问题中写的 2 个命令的输出?
  • 你是对的,已经解决了,谢谢,我只是配置错误
  • 您可以在解决方案中添加答案,这可能会对其他访问者有所帮助。

标签: symfony liipfunctionaltestbundle


【解决方案1】:

当我运行命令时php ApiControllerTest.php

这会失败,因为您必须引导 PHPUnit 而不是直接执行测试类。

您必须按照official documentation 中的建议使用phpunit 命令运行测试。

这应该可以使用以下命令之一(当前目录必须是 Symfony 项目的根目录):

phpunit -c app/phpunit.xml.dist src/TestTask/PhotosBundle/Tests/Controller/ApiControllerTest.php
# or
php vendor/bin/phpunit -c app/phpunit.xml.dist src/TestTask/PhotosBundle/Tests/Controller/ApiControllerTest.php

如果您想启动所有测试而不是这个特定文件,您可以删除最后一个参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-13
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    相关资源
    最近更新 更多