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

feat: throw an error if Factories trait is not used in a KernelTestCase #766

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

nikophil
Copy link
Member

@nikophil nikophil commented Dec 18, 2024

fixes #750

@nikophil nikophil marked this pull request as draft December 18, 2024 17:42
@nikophil nikophil force-pushed the feat/force-using-factories-trait-in-tests branch 6 times, most recently from 8fa82b8 to b28e7cb Compare December 21, 2024 17:26
@nikophil nikophil force-pushed the feat/force-using-factories-trait-in-tests branch from b28e7cb to 05cef62 Compare December 21, 2024 17:28

final class KernelTestCaseWithBothTraitsInWrongOrderTest extends KernelTestCase
{
use ResetDatabase, Factories;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my different tests, I noticed that sometimes, the order of these traits could have an impact, so I wanted to test with both cases

$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel';
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithOnlyResetDatabaseTraitTest.php';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this specific case, where only the ResetDatabase trait is used, the error occurs during the "before test class" hook, so the error cannot be caught in a regular test . Hence this low level ".phpt" test

@nikophil nikophil requested a review from kbond December 21, 2024 17:34
@nikophil nikophil marked this pull request as ready for review December 21, 2024 17:34
@nikophil
Copy link
Member Author

nikophil commented Jan 7, 2025

@kbond I think I won't throw directly an error, but add a deprecation instead: Foundry kinda works without the trait in few situations...

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

Successfully merging this pull request may close these issues.

Using factories in a KernelTestCase without Factories trait should throw
2 participants