nelmio / alice

Expressive fixtures generator
MIT License
2.5k stars 329 forks source link

Boolean Optional Value #281

Closed ReservedDeveloper closed 8 years ago

ReservedDeveloper commented 9 years ago

Not sure if this is a feature request, bug, or other. Been trying to use the optional setter w/ a self-reference boolean field.

Rough idea:

myEntity:
   someBool: <boolean(50)>
   conditionalArray: @self->someBool? <myArrayProvider()>

Seeing that optional data seems to prefer ###? <provider()> syntax, I also tried <($someBool ? 100 : 0>%?. Wondering if the optional return might be kicking back a string instead of a null value, I also tried conditionalArray: @self->someBool? <myArrayProvider()> : <myEmptyArrayProvider()>

In each instance I received the following error:

[Symfony\Component\Debug\Exception\ContextErrorException]  
  Notice: Array to string conversion                         

Exception trace:
 () at /var/www/sites/mysite/vendor/nelmio/alice/src/Nelmio/Alice/Instances/Processor/Methods/Faker.php:125
 Symfony\Component\Debug\ErrorHandler->handleError() at n/a:n/a
 preg_replace_callback() at /var/www/sites/mysite/vendor/nelmio/alice/src/Nelmio/Alice/Instances/Processor/Methods/Faker.php:125
 Nelmio\Alice\Instances\Processor\Methods\Faker->process() at /var/www/sites/mysite/vendor/nelmio/alice/src/Nelmio/Alice/Instances/Processor/Processor.php:88
 Nelmio\Alice\Instances\Processor\Processor->process() at /var/www/sites/mysite/vendor/nelmio/alice/src/Nelmio/Alice/Instances/Populator/Populator.php:82
 Nelmio\Alice\Instances\Populator\Populator->populate() at /var/www/sites/mysite/vendor/nelmio/alice/src/Nelmio/Alice/Fixtures/Loader.php:303
 Nelmio\Alice\Fixtures\Loader->populateObjects() at /var/www/sites/mysite/vendor/nelmio/alice/src/Nelmio/Alice/Fixtures/Loader.php:143
 Nelmio\Alice\Fixtures\Loader->load() at /var/www/sites/mysite/vendor/hautelook/alice-bundle/src/Alice/DataFixtures/Fixtures/Loader.php:38

I suspect one of the following is at play: a) This has been addressed, but the fix version is not being referenced by AliceBundle yet. b) Expressions cannot be used for the optional portion of a fixture. c) Identity cannot be combined with the optional portion of a fixture. d) Custom providers cannot be combined with the optional portion of a fixture. e) ???

For the time being, I've split my fixtures out in to true & false varieties. However, I'd appreciate any insight on the above!

reinfi commented 8 years ago

@theofidry I'm currently working on this, fyi

theofidry commented 8 years ago

@reinfi did you find a fix for it?

theofidry commented 8 years ago

Looking again at this, I think this is just a parsing issue in 2.x. It's quite this kind of bug that are hard to spot and fix in 2.x due to the inexistence of a proper parser/lexer to handle this task. This should however definitely work on 3.x.

If you have found a fix in 2.x I would gladly accept it, otherwise it will be kept as fixed in 3.x only.