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

Factory property not working #972

Open
gonzalezlopezjm opened this issue Jan 21, 2019 · 2 comments
Open

Factory property not working #972

gonzalezlopezjm opened this issue Jan 21, 2019 · 2 comments
Labels
Milestone

Comments

@gonzalezlopezjm
Copy link

Hi, in advance thanks for the hard work in this awesome package!

I'm trying to create objects with the factory property with this YAML

AppBundle\Entity\Media:
  media-1:
    __construct: { AppBundle\Fixture\Factory\MediaFactory::create: ['<username()>']}

But I'm was unable to do this. In all my attemps we obtain the next error:

In TolerantFixtureDenormalizer.php line 68:

  An error occurred while denormalizing the fixture "media-1" (AppBundle\Entity\Media): Could not denormalize the given factory.


In DenormalizerExceptionFactory.php line 28:

  Could not denormalize the given factory.

I figure out that this is related with the data parsing because if I dump the parsed array from the YAML it returns this.

  ["AppBundle\Entity\Media"]=>
  array(1) {
    ["media-1"]=>
    array(1) {
      ["__construct"]=>
      array(1) {
        ["AppBundle\Fixture\Factory\MediaFactory"]=>
        string(24) "create: ['<username()>']"
      }
    }
  }

You can observe that the arguments are an string that is the opposite result that we expected (an array) and this cause the exception throw.

In fact if we change __factory to __construct we obtain other exception:

In SimpleObjectGenerator.php line 114:

  An error occurred while generating the fixture "media-1" (AppBundle\Entity\Media): Notice: Array to string conversion


In ListValueResolver.php line 98:

  Notice: Array to string conversion

I'm using the latest version of your package, and I think that this is a parser bug. I hope that this info will be enought to identify the issue.

Thanks and best regards

@theofidry theofidry added the Bug label Jan 21, 2019
@theofidry theofidry added this to the 3.x milestone Jan 21, 2019
@theofidry
Copy link
Member

Thanks for the report. It's a curious issue, but in the first example, this looks like a YAML parsing issue as:

AppBundle\Entity\Media:
  media-1:
    __construct: { 'AppBundle\Fixture\Factory\MediaFactory::create': ['<username()>']}

is parsed correctly unlike the example you gave. I do not know if it's expected or not but it might be worth checking or alternatively update the documentation to make use of the quotes where appropriate.

I suspect the __factory issue is related

@gonzalezlopezjm
Copy link
Author

Sorry, I sent the YAML with and error, the correct YAML is:

AppBundle\Entity\Media:
  media-1:
    __factory: { AppBundle\Fixture\Factory\MediaFactory::create: ['<image()>']}

And like you indicated with the quotes works correctly, is enough for me that I think that is a good idea to update the documentation accordly

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

No branches or pull requests

2 participants