2

In my new project using Symfony 6.2 & Api Platform, I have a deprecation that I would like to correct. Can you help me to corret it please ?

I have the following error after running tests with PhpUnit :

Remaining indirect deprecation notices (1)

1x: Since symfony/http-foundation 6.2: The "Symfony\Component\HttpFoundation\Request::getContentType()" method is deprecated, use "getContentTypeFormat()" instead.

1x in UserTest::testPost from App\Tests\Func

The method testPost contain the following code :

public function testPost(): void
{
    $response = static::createClient()->request('POST', '/api/users', [
        'headers' => ['Accept' => 'application/json'],
        'json' => [
            'email' => 'new-user@example.com',
            'password' => 'password',
        ],
    ]);
    $this->assertResponseStatusCodeSame(201);
}

I have try :

composer update 

But it dosent fix it. Thanks for your help.

Edit :

composer.json :

{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
    "php": ">=8.1",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "api-platform/core": "^3.0",
    "doctrine/annotations": "^1.0",
    "doctrine/doctrine-bundle": "^2.7",
    "doctrine/doctrine-migrations-bundle": "^3.2",
    "doctrine/orm": "^2.14",
    "lexik/jwt-authentication-bundle": "^2.16",
    "nelmio/cors-bundle": "^2.2",
    "phpdocumentor/reflection-docblock": "^5.3",
    "phpstan/phpdoc-parser": "^1.15",
    "symfony/asset": "6.2.*",
    "symfony/console": "6.2.*",
    "symfony/dotenv": "6.2.*",
    "symfony/expression-language": "6.2.*",
    "symfony/flex": "^2",
    "symfony/framework-bundle": "6.2.*",
    "symfony/property-access": "6.2.*",
    "symfony/property-info": "6.2.*",
    "symfony/runtime": "6.2.*",
    "symfony/security-bundle": "6.2.*",
    "symfony/serializer": "6.2.*",
    "symfony/twig-bundle": "6.2.*",
    "symfony/validator": "6.2.*",
    "symfony/yaml": "6.2.*"
},
"require-dev": {
    "doctrine/doctrine-fixtures-bundle": "^3.4",
    "fakerphp/faker": "^1.21",
    "phpunit/phpunit": "^9.5",
    "symfony/browser-kit": "6.2.*",
    "symfony/css-selector": "6.2.*",
    "symfony/http-client": "6.2.*",
    "symfony/maker-bundle": "^1.48",
    "symfony/phpunit-bridge": "^6.2"
},
"config": {
    "allow-plugins": {
        "symfony/flex": true,
        "symfony/runtime": true
    },
    "sort-packages": true
},
"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Tests\\": "tests/"
    }
},
"replace": {
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*",
    "symfony/polyfill-php73": "*",
    "symfony/polyfill-php74": "*",
    "symfony/polyfill-php80": "*",
    "symfony/polyfill-php81": "*"
},
"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts"
    ],
    "post-update-cmd": [
        "@auto-scripts"
    ]
},
"conflict": {
    "symfony/symfony": "*"
},
"extra": {
    "symfony": {
        "allow-contrib": false,
        "require": "6.2.*"
    }
}
}
  • Running `composer update` will do nothing, as the code is already up to date (that is why you get that deprecation notice). You have to share the stack trace of the error, so we can know if we have control over that line notifying this or not. I do not know much about Symfony, only about Laravel, but all depends if this deprecation is being thrown inside the `vendor` folder or in a folder/file you have control over... – matiaslauriti Dec 30 '22 at 03:26
  • I have no stack trace on this deprecation. I find the trigger_deprecation, the deprecated method call the new method so it's fix but not 'clean'. – Aymeric Cucherousset Dec 30 '22 at 10:07
  • Can you edit your post and add your composer file? – Bossman Dec 30 '22 at 11:57
  • 1
    Thats an indirect deprecation, meaning its origin is not in your source code. It originates by a bundle you have installed. Your best options are: Wait for the maintainers to fix it or support them by supplying a fix yourself as a pull request. See https://symfony.com/doc/current/components/phpunit_bridge.html to learn more about reporting deprecations via phpunit. – simon.ro Jan 02 '23 at 10:41

0 Answers0