-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Using JSON in Yaml fixtures #183
Comments
I believe you should just define an array (or yaml object) and let i.e. field: {label_alignment: block, max_length: 50, field_length: 60,
default_value: ""} |
That seemed to have solved it, in combination with me removing an 'array to string' conversion error in the entity. Arrays given to the setConfig() were casted to a string for some reason |
I was able to solve this using a custom faker provider (as mentioned here). JsonProvider.php class JsonProvider
{
/**
* Decodes a JSON string.
* This function must be used in order to use a JSON object (string) as a column value. Without this method, the
* JSON string would be escaped. The value that will be assigned to the column will be a correct JSON string.
* @see https://github.com/nelmio/alice/issues/935#issuecomment-397587318
* @example <json_decode('{"jeff":"IDK","slim":"shady","age":5}')>
*
* @throws JsonException
*/
public function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0)
{
return json_decode($json, $assoc, $depth, JSON_THROW_ON_ERROR | $options);
}
} fixtures.yaml Fully\Qualified\Name\MyClass:
my_class_7:
id: 1
value: <json_decode('{"jeff":"IDK","slim":"shady","age":5}')>
Notice that I made json_decode throw an exception when something goes wrong. I did this to prevent any unexpected behaviour and to stop the fixtures early and report the problem. |
Some of the entities im trying to write fixtures for contain json data.
The data looks like this in the fixture:
'{"label_alignment":"block","max_length":50,"field_length":"60","default_value":""}'
But once i run the fixtures, the ", { and } will be escaped with a \ making it invalid json
I tried putting a Processor in between, but the Pre persist and Post persist data is both unescaped.
This is the entity entry for the data
Is it something i am doing wrong? or is it something the entities are doing wrong? or is Alice doing something wrong? I am clueless. Any help will be nice.
The text was updated successfully, but these errors were encountered: