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

ApiTestCase generator uses wrong path #1092

Closed
HerHde opened this issue Apr 13, 2022 · 2 comments · Fixed by #1108
Closed

ApiTestCase generator uses wrong path #1092

HerHde opened this issue Apr 13, 2022 · 2 comments · Fixed by #1108

Comments

@HerHde
Copy link

HerHde commented Apr 13, 2022

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

@HerHde HerHde added the Bug Bug Fix label Apr 13, 2022
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Apr 13, 2022
@xabbuh xabbuh transferred this issue from symfony/symfony Apr 13, 2022
@jrushlow
Copy link
Collaborator

Related to #1091

@mdoutreluingne
Copy link
Contributor

mdoutreluingne commented Apr 27, 2022

Environment

PHP 8.1.4
Symfony CLI version 5.4.7
Symfony 6.0.x
API Platform 2.6

I confirm that I have the same problem.

The make:test generates the test for me with use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; while I only own the class use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; (because i have API Platform 2.6)

It seems to be related to from this PR, for anticipated version 3.0 of API Platform, which apparently indicates that use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; will be deprecated in 2.7 and become invalid in 3.0 .

You should use use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; from API Platform version 2.7.

I will try to fix this problem.

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

Successfully merging a pull request may close this issue.

4 participants