symfonyliipfunctionaltestbundle

Liip\FunctionalTestBundle\Test\WebTestCase' not found in C:\wamp\www\test\src\TestTask\PhotosBundle\Tests\Controller\ApiControllerTest.php


When I run the command php ApiControllerTest.php, it shows me this error:

Liip\FunctionalTestBundle\Test\WebTestCase' not found in C:\wamp\www\test\src\TestTask\PhotosBundle\Tests\Controller\ApiControllerTest.php on line 12

My composer is as follows:

"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

My file appkernel is as follows;

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

and my test controller is as follows; I don't see where is the problem; everythings is include here,

<?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')
        );

when i run it with commands: phpunit -c app/phpunit.xml.dist, or php vendor/bin/phpunit -c app/phpunit.xml.dist it shows me phpunit is not recognized


Solution

  • When I run the command php ApiControllerTest.php

    This fails because you have to boot PHPUnit instead of executing the test class directly.

    You have to run the tests with the phpunit command, as suggested in the official documentation.

    This should work with one of these commands (the current directory must be the root of your Symfony project):

    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
    

    You can remove the last parameter if you want to launch all the tests instead of this particular file.