2

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

anony
  • 185
  • 2
  • 14
  • You should try to run the test with the `phpunit` command, as suggested in the official documentation: http://symfony.com/doc/current/book/testing.html This should work with one of these commands: `phpunit -c app/phpunit.xml.dist`, or `php vendor/bin/phpunit -c app/phpunit.xml.dist`. – A.L Apr 14 '16 at 13:59
  • I tried to do that but it shows me phpunit is not recognized – anony Apr 14 '16 at 14:25
  • Can you please add the outputs of the 2 commands I wrote in your question? – A.L Apr 14 '16 at 15:03
  • 1
    you were right, it's solved, Thank you , i had just a config error – anony Apr 15 '16 at 07:56
  • You can add an answer with the solution, that may help some other visitors. – A.L Apr 15 '16 at 09:53
  • Your first answer is the solution – anony Apr 18 '16 at 14:48

1 Answers1

1

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.

A.L
  • 10,259
  • 10
  • 67
  • 98