Symfony\Bundle\FrameworkBundle\Test\WebTestCase class not found

Viewed 2701

I created fresh Symfony 4.1.x project, but when I'm trying to create and execute functional test I am getting error:

PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/tomasz/my_project/tests/ExampleControllerTest.php on line 7

Steps to reproduce:

  1. Create project

    composer create-project symfony/skeleton my_project

  2. Install phpunit, functional tests components and maker for generating skeleton of functional test

    composer req --dev symfony/phpunit-bridge symfony/css-selector symfony/browser-kit symfony/maker-bundle

  3. Create example functional test

    bin/console make:functional-test ExampleControllerTest

Content of created file:

<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class ExampleControllerTest extends WebTestCase
{
    public function testSomething()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/');

        $this->assertSame(200, $client->getResponse()->getStatusCode());
        $this->assertContains('Hello World', $crawler->filter('h1')->text());
    }
}
  1. Run tests

    bin/phpunit

Output (after installing phpunit dependencies):

PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/tomasz/my_project/tests/ExampleControllerTest.php on line 7

I checked and class Symfony\Bundle\FrameworkBundle\Test\WebTestCase does exist in vendor/. Any clues?

phpunit.xml.dist

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="vendor/autoload.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
    </php>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
        </whitelist>
    </filter>

    <listeners>
        <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
    </listeners>
</phpunit>
0 Answers
Related