zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
608 stars 63 forks source link

Metadata in doc-comments is deprecated #555

Closed Piairre closed 3 months ago

Piairre commented 4 months ago

We are currently writing functionals tests. We implement our test files with Factories and ResetDatabase this way:

<?php

namespace App\Tests\Func\Auth;

use App\DataFixtures\Factory\UserFactory;
use App\Tests\Func\CustomApiTestCase;
use Zenstruck\Foundry\Test\Factories;
use Zenstruck\Foundry\Test\ResetDatabase;
// Some others imports

class AuthTest extends CustomApiTestCase
{

    use Factories;
    use ResetDatabase;

    public function testBadLogin(): void
    {
        // Our test
    }
}

Our tests pass, but we have this warning: Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

It appears on the _setUpFactories, _tearDownFactories, _resetDatabase and _resetSchema methods.

It appears that annotations will soon no longer be supported.

nikophil commented 4 months ago

Hi,

thaks for reporting this.

It seems that you're using PHPUnit 11. But Foundry still have not taken the phpunit 10 train, nor the whole Symfony world... we are more or less waiting for symfony phpunit bridge. I think you can add these warnings to a baseline, for sure when phpunit 12 will be released, we will use attributes :innocent:

kbond commented 4 months ago

@Piairre, can you confirm if a test has the docblock AND the corresponding attribute, the deprecation is removed? I think the solution here is to have the attribute in addition to the docblock.

nikophil commented 4 months ago

From : https://docs.phpunit.de/en/11.0/annotations.html

PHPUnit will first look for metadata in attributes before it looks for annotations in comments. When metadata is found in attributes, metadata in comments is ignored. Support for metadata in comments is closed for further development: bugs will be fixed, but no new functionality will be implemented based on annotations.

this means the migration can be done smoothly

kbond commented 3 months ago

Should be fixed by #562.