laracasts / TestDummy

Easy factories for PHP integration testing.
https://laracasts.com/lessons/whats-new-in-testdummy
MIT License
457 stars 80 forks source link

Pass through override arguments to factory definition callback #111

Closed foglerek closed 6 years ago

foglerek commented 8 years ago

This edit simply passes through any arguments provided during factory calls, i.e ...

Factory::method('Model', $overrides);

... on to the factory definition callback, if provided:

$factory('Model', function($faker, $overrides) {
    ...
});

... or an empty array by default.

This allows for customising factory behaviour and conditionally creating relational models within the factory definition callback.

This also opens up the door for creating more complex generators in the callback, that can perform custom logic based on the passed $overrides data.