zenstruck/foundry
Zenstruck Foundry is a Laravel-friendly factory and fixtures toolkit for building and persisting test data. Define model factories, create realistic related objects, seed databases, and write cleaner, faster tests with helpers for states, Faker, and repositories.
bc10d82 fix: withoutDoctrineEvents should do nothgin in unit tests (#1121) by @VincentLanglet
db2b673 fix: use full semver versions for PHPUnit requirements (#1118) by @nikophil
d109883 Update warning message for Foundry v2 documentation (#1113) by @gisostallenberg
31c90dd Minor doc fix (#1117) by @javiereguiluz
11f55e7 feat: throw when withoutDoctrineEvents() is called within flush_after() (#1111) by @nikophil
f81db0d feat: add withoutDoctrineEvents() to suppress listeners during factory create (#1109) by @seb-jean
1408436 fix: factory template formatting (#1110) by @enekochan
b8f8909 minor: change Foundry's baseline (#1108) by @nikophil
5e70129 fix: arrange compatibility with PHPUnit 10 (#1103) by @nikophil
47a431c chore(ci): use-dama => no-dama (#1090) by @nikophil d8ce94b fix: ensure in WebTestCase with kernel already boot does not occur (#1088) by @nikophil 4820f3c chore: fix bug report template by @nikophil 516b786 chore: test using PHPunit 13 (#1086) by @nikophil 692f74c docs: minor docs fixes (#1082) by @nikophil
This release deprecates Factories and ResetDatabase traits in favor of the usage of the PHPUnit extension shipped with Foundry. These features mainly impact users using PHPUnit >= 10.
You can now remove all usages of the Factories trait. And replace the trait ResetDatabase with the attribute #[ResetDatabase]. Rectors sets are shipped with the release, see https://github.com/zenstruck/foundry/blob/2.x/UPGRADE-2.9.md.
You can even automate the reset database mechanism:
<!-- phpunit.xml -->
<phpunit>
<extensions>
<bootstrap class="Zenstruck\Foundry\PHPUnit\FoundryExtension">
<parameter name="enabled-auto-reset" value="true"/>
</bootstrap>
</extensions>
</phpunit>
This will automatically reset the database before all KernelTestCase tests. With this configuration, even #[ResetDatabase] traits can be omitted.
5e11589 minor: fix last bits before release (#1080) by @nikophil
4f97e89 fix(in-memory): trigger in memory on PreparationStarted (#1077) (#1080) by @nikophil
e539491 fix: handle reset DB mechanism along with "before hooks" methods (#1070) (#1080) by @nikophil
2d59700 feat: automatic DB reset (#1068) (#1080) by @nikophil
9aaf683 minor: remove useless Factories trait (#1067) (#1080) by @nikophil
78b95d1 feat(2.9): deprecate ResetDatabase trait (#985) (#1080) by @nikophil
11b4b03 fix permutations in .github/workflows/phpunit.yml (#1080) by @nikophil
3025311 remove useless import (#1080) by @nikophil
f91c2fa fix: fixes after deprecating Factories trait (#1066) (#1080) by @nikophil
deb7637 feat(2.9): deprecate Factories trait and force PHPUnit extension usage (#968) (#1080) by @nikophil
e57d750 refactor: harmonize how factories are proxified in data providers (#1065) (#1080) by @nikophil
9cbf3c7 minor: some house keeping (#1064) (#1080) by @nikophil
c45e03c fix: allow deleting ghost object (#1076) by @nikophil 86a2036 minor: provide a way to skip faker's seed management (#1075) by @nikophil 32542a6 chore: use APP_ENV=test for benchmark (#1074) by @nikophil 4b6324e minor: add priorities for PHPUnit hooks (#1073) by @nikophil 63c3cac minor: use test environment (#1072) by @nikophil 5dccced Update issue templates (#1064) by @nikophil
f6e35e5 fix(autorefresh): prevent weird autorefresh recursion (#1060) by @nikophil 377c6d4 fix: handle derived entities in autorefresh mechanism (#1058) by @nikophil 8701b45 mnior: reboot kernel in database resetter instead of shutdown (#1059) by @nikophil 965fe3c refactor: simplify ResetDatabaseManager (#1054) by @nikophil 473559c chore: add PHP 8.5 to test matrix (#1043) by @nikophil 6c3a127 refactor: explicitly boot Foundry in ResetDatabase (#1049) by @nikophil 368e686 chore: skip legacy proxy tests using #[RequiresMethod] (#1048) by @nikophil d7add25 chore: require symfony/flex as dev dependency (#1047) by @nikophil
45b6e21 fix: remove problematic "conflict" in composer.json (#1046) by @nikophil
a102c0a fix: Allow PersistManager::refresh() to not throw in specific cases (#1044) by @nikophil d4f9997 fix: auto-refresh problem with doctrine/orm 2 (#1042) by @nikophil cace455 Update issue templates by @nikophil b0a5703 fix: call inverse relatoinship callback before afterInstantiate() (#1041) by @nikophil
9621dae Improve phpdoc for non empty list (#1037) by @VincentLanglet
7b9dc07 chore: actually suport Symfony 8 (#1022) by @nikophil
This release introduces a new attribute #[AsFoundryHook], which allows to declare Foundry hooks as Symfony services. It also permits to have "global" hooks for all kind of objects created with Foundry:
final class FoundryHook
{
#[AsFoundryHook(Post::class)]
public function beforeInstantiate(BeforeInstantiate $event): void
{
// do something before the post is instantiated:
// $event->parameters is what will be used to instantiate the object, manipulate as required
// $event->objectClass is the class of the object being instantiated
// $event->factory is the factory instance which creates the object
}
#[AsFoundryHook(Post::class)]
public function afterInstantiate(AfterInstantiate $event): void
{
// $event->object is the instantiated Post object
// $event->parameters contains the attributes used to instantiate the object and any extras
// $event->factory is the factory instance which creates the object
}
#[AsFoundryHook(Post::class)]
public function afterPersist(AfterPersist $event): void
{
// this event is only called if the object was persisted
// $event->object is the persisted Post object
// $event->parameters contains the attributes used to instantiate the object and any extras
// $event->factory is the factory instance which creates the object
}
#[AsFoundryHook]
public function afterInstantiateGlobal(AfterInstantiate $event): void
{
// Omitting the class defines a "global" hook which will be called for all objects
}
}
8dc0b1f feat(2.8): introduce #[AsFoundryHook] attribute (#986) by @nikophil
bf4549c feat(2.8): dispatch events (#974) by @nikophil
8516af1 docs: Remove array params on function alwaysForce (#1028) by @philpichet
5f3a6b1 feat: add hooks priority (#1029) by @nikophil
41ab3ae fix: auto-refresh with Mongo after DoctrineMongoDBBundle 5.4.3 (#1030) by @nikophil
728c8f8 minor: Add default value to Factory::attributes (#1026) by @VincentLanglet 0fe1017 tests: ensure Doctrine lifecycle works (#1020) by @nikophil 1247b0b chore: remove paratest from dev dependencies (#1023) by @nikophil 11355a9 chore: add concurrency for all workflows (#1019) by @nikophil fed6e4a chore: fix rector with bamarni (#1018) by @nikophil 545cf18 chore: split CIs and add concurrency (#1017) by @nikophil 17796f2 chore: add bc-check to CI (#1016) by @nikophil b8ced9b chore: disable sync template for cs config (#1015) by @nikophil b802463 chore: some housekeeping (#1014) by @nikophil
7766a85 fix: only use PersistedObjectsTracker when auto-refresh is enabled (#1013) by @nikophil
95d2a96 fix: autorefresh should work after kernel shutdown (#1011) by @nikophil 0ea8430 tests: ensure OneToMany relationships are refreshed (#1010) by @nikophil 3c6faff fix: RepositoryAssertion::exist() $criteria should allow mixed (#1007) by @nikophil 81cc97d minor: accept as story any child of Story (#1006) by @alsciende e99f3b0 chore: run rector CI with PHPUnit 12 (#1002) by @nikophil
81eacf5 docs: add a note about using make:factory --test (#1000) by @ttskch
660942d [Rector] Add rector to require-dev and use single autoload vendor for run PHPUnit (#1001) by @samsonasik
f06d58d fix: using refresh_all() with flush_after() (#999) by @HypeMC
9489e83 fix: 🐛 use isser instead of constructor to apply autorefresh setting to Factory (#998) by @ttskch
45214f7 fix: revert adding PersistManager::findBy() (#996) by @nikophil b36b9b3 chore: upgrade PHPStan (#997) by @nikophil 55f2689 fix: edge case with Doctrine Middleware & early kernel boot (#993) by @HypeMC 9fa21b3 fix(repository): use IN() when an array is passed (#995) by @nikophil cad1466 fix: handle readonly when refreshing from repository decorator (#989) by @nikophil b4b2ffe fix: Enhanced random method with additional safety check. (#991) by @sofwar
97b60b6 fix: applyStateMethod should not be internal (#988) by @nikophil
This release deprecates the proxy system in PHP 8.4 in favor of an auto-refresh mechanism which leverages PHP lazy objects.
Please follow the upgrade guide.
cd1b31a docs: add "Troubleshooting" section in upgrade guide (#943) by @nikophil a83c249 feat: enable auto-refresh at factory level (#970) by @nikophil 32e9868 fix: few fixes after #972 (#943) by @nikophil 47b0d79 feat: use ghost objects for auto refresh mechanism (#967) (#943) by @nikophil 3a131ef minor: improve deprecation message (#943) by @nikophil 30df79d feat: auto-refresh objects from RepositoryDecorator (#943) by @nikophil f675c37 minor: use ProxyGenerator::unwrap() instead of unproxy() and prevent deprec (#943) by @nikophil 9d04094 minor: remove PersistedObjectsTracker::reset() call in tear down (#943) by @nikophil 3e23fda refactor(maker): deprecate --with-phpdocs for PHP >=8.4 (#952) (#943) by @nikophil 61cabac docs: create upgrade guide to 2.7 and document auto-refresh (#951) (#943) by @nikophil fe6374b feat: auto refresh with lazy object php84 enabled by config (#950) (#943) by @nikophil 9717676 feat: Rector rules to help migrating away from proxy (#941) (#943) by @nikophil 35e8da6 feat: use native proxies for object creation in data providers (#943) by @nikophil 02f85f2 feat: create proxy system with PHP 8.4 lazy proxies (#943) by @nikophil
67a7731 fix: misc fixes when creating objects in data provider (#972) by @nikophil 5e068c4 fix: ignore PHPUnit warnings when dataprovider returns more data than test method accepts (#958) by @nikophil 0a65872 Fix proxying of classes that have tenative return types (#962) by @BackEndTea f9e95cb fix: doctrine deprecation (#961) by @nikophil c8256e3 Add support for Symfony 8 (#960) by @Kocal
6f4e920 fix(proxy): add autorefresh call for union and intersection return types (#959) by @BackEndTea 58fd89a feat: introduce method FactoryCollection::applyStateMethod() (#956) by @nikophil
932c63a feat: rename foundry:load-stories to foundry:load-fixtures (#954) by @kbond
1d31275 Update index.rst (#945) by @treztreiz
e5e5162 fix: doctrine deprecation (#949) by @nikophil
dc54221 Update index.rst (#946) by @treztreiz
5ae21ec docs: fix forceSet() to _set() in example (#948) by @mariecharles, Marie CHARLES
56161cc feat: add randomRangeOrCreate() method (#932) by @elliotbruneel, Elliot Bruneel
2d28e67 test: ensure no deprecation when Factories used in parent class (#922) by @nikophil
b25eb60 minor: fix running phpunit w/o arguments (#933) by @kbond
f9b8132 minor: add UID types to factory maker (#936) by @HypeMC
030f7aa chore: temporarily disable cascade relationship combinations (#938) by @nikophil
8238e0f fix: remove useless Configuration::boted() check (#929) by @nikophil
8e202b4 fix: TypeError FactoryCollection::create() when calling many with 0 (#925) by @jdecool
fe12d09 fix: add missing flush_once feature flag (#912) by @phasdev f991999 docs: Fix data providers phpunit link (#906) by @alexander-schranz 19ddd55 docs: in memory behavior needs PhpUnit extension (#905) by @nikophil 6a0b4ac docs: improve docs for in-memory repositories (#904) by @nikophil
How can I help you explore Laravel packages today?