foundry: [BUG] In order to use Foundry correctly, you must use the trait "Zenstruck\Foundry\Test\Factories" in your "ApiPlatform\Symfony\Bundle\Test\ApiTestCase" tests
When a test class extends \ApiPlatform\Symfony\Bundle\Test\ApiTestCase, this deprecation is triggered:
Since zenstruck/foundry 2.4: In order to use Foundry correctly, you must use the trait "Zenstruck\Foundry\Test\Factories" in your "ApiPlatform\Symfony\Bundle\Test\ApiTestCase" tests. This will throw an exception in 3.0.
This is wrong, as the bundle should only force the userland tests to use the trait Factories.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 19 (8 by maintainers)
@nikophil, I checked the version from the PR. I no longer see deprecation messages for the
ApiTestCaseclass. For me this solves the issue.Hi @Aerendir @7-zete-7
looking at the stack trace provided, I understood what was going on (@kbond yet another proxy subtle problem 😁)
I managed to reproduce it in our test suite and I fixed it in https://github.com/zenstruck/foundry/pull/922
any chance you test the fix before I merge/release it? 🙏
Yeah I’ll handle this soon
BTW, we ship a docker stack to work on Foundry, the readme explains that
Ok, I actually found the problem: Foundry is called many times during my test.
The problem is that the backtrace is sometimes “inverted”, so it first finds the ApiPlatform test case (and throws the deprecation), while other times it first finds the actual test that uses
Factoriesand so doesn’t trigger the deprecation.The only solution I see is to first traverse the entire backtrace tree, then decide if the deprecation has to be thrown or not.
Once I will have an actual solution, I will also try to write proper tests.
yeah OK, I can see the problem, let me fix this 😃