Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tomaszturkowski opened this issue Nov 14, 2018 · 11 comments
Closed

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

tomaszturkowski opened this issue Nov 14, 2018 · 11 comments

Comments

@tomaszturkowski
Copy link

tomaszturkowski commented Nov 14, 2018

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: https://pastebin.com/MYjgpFbA
composer.json: https://pastebin.com/WQaYFBq1
composer.lock: https://pastebin.com/pwRsmnY8
PHP Version: 7.2.12

@mmarton
Copy link

mmarton commented Nov 14, 2018

Either composer doesn't find the class or phpunit doesn't use phpunit.xml.dist.
try running composer dump-autoload and/or bin/phpunit -c phpunit.xml.xsd

@xabbuh
Copy link
Member

xabbuh commented Nov 14, 2018

Status: Reviewed

@xabbuh
Copy link
Member

xabbuh commented Nov 14, 2018

I have no idea yet what is causing this issue, but I can confirm it.

@xabbuh
Copy link
Member

xabbuh commented Nov 14, 2018

seems to be caused by symfony/recipes#481

@nicolas-grekas
Copy link
Member

Does symfony/recipes#491 fix it?

@khal3d
Copy link

khal3d commented Nov 14, 2018

@nicolas-grekas I'm not sure how to test the recipe, but changing the code of bin/phpunit in my project and removing the following lines like what you did solved the issue:

$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
App\Kernel::bootstrapEnv('test');
$classLoader->unregister();

So, I think it does fix the issue.

@nicolas-grekas
Copy link
Member

Thanks for the feedback.

@hsb1007
Copy link

hsb1007 commented Nov 22, 2018

Even after removing the 3 lines, it still doesn't solve the issue for me =(

@nicolas-grekas
Copy link
Member

I don't have the issue when starting a new project from scratch.
You should compare your files with those of a new project and spot the diff.

@billgsm
Copy link

billgsm commented Jan 19, 2019

I had the same issue with a new project from scratch. However, I could get through it thanks to the answer below.

@nicolas-grekas I'm not sure how to test the recipe, but changing the code of bin/phpunit in my project and removing the following lines like what you did solved the issue:

$classLoader = require dirname(__DIR__).'/vendor/autoload.php';
App\Kernel::bootstrapEnv('test');
$classLoader->unregister();

So, I think it does fix the issue.

@saminet
Copy link

saminet commented Apr 12, 2019

In your class under tests folder, just replace this line
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
By this
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
And it will work fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants