Skip to content

Conversation

@nikophil
Copy link
Member

@nikophil nikophil commented Aug 25, 2025

This is an experiment: I'd like to remove the usage of Factories trait in favor of the PHPUnit extension.

This would be really less error prone, since it would be impossible to omit it, and it would be added once for all

fixes #965 (because we won't check anymore if the trait is used)

I had hard times (like REALLY hard times) to make the feature "use PersistentObjectFactory::create() method in data providers" work without the trait. The code is kinda hacky, but since we cannot access the test instance from the PHPUnit extension (even with some hacky code, this is literally impossible), I had to be... well... creative 😅

@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch from 15eba47 to a786b04 Compare August 25, 2025 17:43
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 2 times, most recently from 91d0ab5 to 876b505 Compare August 27, 2025 05:08
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 4 times, most recently from b2d669d to fec86ed Compare September 22, 2025 15:03
@nikophil nikophil changed the title feat: force PHPUnit extension usage feat: deprecate Factories trait and force PHPUnit extension usage Sep 22, 2025
@nikophil nikophil requested a review from Copilot September 22, 2025 15:29
@nikophil nikophil marked this pull request as ready for review September 22, 2025 15:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the deprecation of the Factories trait in favor of forcing PHPUnit extension usage. The purpose is to make Foundry's PHPUnit integration more robust by eliminating the possibility of forgetting to use the trait, which currently leads to errors.

  • Deprecates the Factories trait and shows deprecation warnings when used
  • Introduces new PHPUnit extension functionality to handle test lifecycle management
  • Adds comprehensive test coverage for both trait and extension usage scenarios

Reviewed Changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Test/Factories.php Adds deprecation warnings and early returns when PHPUnit extension is enabled
src/PHPUnit/FoundryExtension.php Extends extension functionality with new subscribers and state tracking
src/PHPUnit/BootFoundryOnPreparationStarted.php New subscriber to boot Foundry when test preparation starts
src/PHPUnit/ShutdownFoundryOnTestFinished.php New subscriber to shutdown Foundry when test finishes
src/PHPUnit/DataProvider/*.php New data provider handling subscribers for extension-based workflow
src/Persistence/PersistentObjectFromDataProviderRegistry.php New registry for managing persistent objects from data providers
tests/Integration/ForceFactoriesTraitUsage/ New test files to verify both trait and extension behaviors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@nikophil nikophil requested a review from kbond September 22, 2025 15:30
@zenstruck zenstruck deleted a comment from Copilot AI Sep 22, 2025
@zenstruck zenstruck deleted a comment from Copilot AI Sep 22, 2025
@zenstruck zenstruck deleted a comment from Copilot AI Sep 22, 2025
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 2 times, most recently from e2bb951 to bb8a6b1 Compare September 22, 2025 20:18
@nikophil nikophil changed the title feat: deprecate Factories trait and force PHPUnit extension usage feat(2.8): deprecate Factories trait and force PHPUnit extension usage Sep 23, 2025
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 2 times, most recently from 11e17e4 to a9dd8cf Compare September 23, 2025 09:42
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 2 times, most recently from cccf9b7 to f216d8b Compare September 24, 2025 17:10
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 4 times, most recently from 12f9f16 to 8408b91 Compare October 10, 2025 11:52
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch 3 times, most recently from 45ce8eb to c5183af Compare October 11, 2025 08:07
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch from c5183af to 3e531a2 Compare October 25, 2025 12:22
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch from 3e531a2 to 5d4f69d Compare October 27, 2025 09:07
@nikophil nikophil force-pushed the feat/force-phpunit-extension-usage branch from 5d4f69d to b0c4b6f Compare October 27, 2025 09:08
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.

Remove usage of debug_backtrace() to check presence of Factories trait

1 participant