Skip to content

ApiTestCase generator uses wrong path #1092

@HerHde

Description

@HerHde

Symfony version(s) affected

6.0.x

Description

Generating a new ApiTestCase via cli results in failing tests. It seems as the generator uses the wrong class path.

How to reproduce

run

symfony new --dir .
composer require symfony/maker-bundle symfony/test-pack symfony/http-client --dev
php bin/console make:test
# > ApiTestCase
# > Example
composer require api
php bin/phpunit

results in

PHP Fatal error: Uncaught Error: Class "ApiPlatform\Symfony\Bundle\Test\ApiTestCase" not found in [...]/tests/ExampleTest.php:7

Possible Solution

In the resulting tests/ExampleTest.php, cange the import:

<?php

namespace App\Tests;

-use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
+use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;

class ExampleTest extends ApiTestCase
{
    public function testSomething(): void
    {
        $response = static::createClient()->request('GET', '/');

        $this->assertResponseIsSuccessful();
        $this->assertJsonContains(['@id' => '/']);
    }
}

Additional Context

PHP 8.1.3
Symfony CLI version 5.4.7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions