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

FactoryBuilder trying to unintentionally call field #23361

Closed
haekb opened this issue Mar 1, 2018 · 1 comment
Closed

FactoryBuilder trying to unintentionally call field #23361

haekb opened this issue Mar 1, 2018 · 1 comment

Comments

@haekb
Copy link

haekb commented Mar 1, 2018

  • Laravel Version: 5.6.3
  • PHP Version: 7.2.2
  • Database Driver & Version: MariaDB 10.1.30

Description:

Hey there,

For testing I've created a Provider with custom functions to dish out fake data for my model's factory.

I have a function that returns 2 random amenities in an array using ->randomElements from faker. One of these items is "Storage".

If Storage happens to be the first item in that array, the factory will die with an error of
BadMethodCallException with message 'Call to undefined method League\Flysystem\Filesystem::Restaurant'
(Restaurant is replaceable with whatever the second element of that array might be.)

I've tracked it down to FactoryBuilder@expandAttributes, where I guess it's overlapping with the Storage facade?

To get around this I can json_encode the fields, but this model does indeed cast that field as an array/json, so I feel like this should be safe to do.

$casts = [
...
"amenities" => "array", 
...
]

Steps To Reproduce:

  • Have a factory return an element that contains an array with the first element being Storage, second element can be anything.
$factory->define( ... your model ..., function() {
   return [
     "foo" => ["Storage", "Bar"]
   ]
}
  • See error
    BadMethodCallException with message 'Call to undefined method League\Flysystem\Filesystem::Bar'
@themsaid
Copy link
Member

themsaid commented Mar 2, 2018

Fixed here: #23372

thanks

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

No branches or pull requests

2 participants