laracasts / TestDummy

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

Builder::triggerFakerOnAttributes is calling random functions #87

Closed h-collector closed 9 years ago

h-collector commented 9 years ago

The line

$attribute = is_callable($attribute) ? $attribute() : $attribute;

in specified method can call random functions and throw exceptions or even do pretty nasty things, eg. if I make and use something like provider for random font-awesome icon name, sometimes I get

[ErrorException]                                                                                                                                                        
  Missing argument 1 for unlink(), called in /vendor/laracasts/testdummy/src/Laracasts/TestDummy/Builder.php on line 192/200 and defined 

I suggest, changing the line to:

$attribute = $attribute instanceof \Closure ? $attribute() : $attribute;

("all Faker properties are wrapped in closures."... so check for them and not for all callables)

JeffreyWay commented 9 years ago

PR?