LIIP \ FunctionalTestBundle \测试\ WebTestCase'在C:\ wamp \ www \ test \ src \ TestTask \ PhotosBundle \ Tests \ Controller \ ApiControllerTest.php中找不到

时间:2016-04-14 07:30:50

标签: symfony liipfunctionaltestbundle

当我运行命令php ApiControllerTest.php时,它会显示此错误:

  

LIIP \ FunctionalTestBundle \测试\ 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无法识别

1 个答案:

答案 0 :(得分:1)

  

当我运行命令php ApiControllerTest.php

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

您必须按answer中的建议使用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

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