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

Inconsistent behavior of optional operator with empty strings #849

Closed
ju1ius opened this issue Dec 24, 2017 · 3 comments
Closed

Inconsistent behavior of optional operator with empty strings #849

ju1ius opened this issue Dec 24, 2017 · 3 comments
Milestone

Comments

@ju1ius
Copy link

ju1ius commented Dec 24, 2017

Probably related to #601 ?

Current behavior

Using the following fixture file:

AppBundle\Entity\Foo:
  title: '50%? <sentence()> : ""'

Results in the string "" being insterted in the database.

Using the following fixture file:

AppBundle\Entity\Foo:
  title: "50%? <sentence()> : ''"

Results in an empty string being inserted in the database.

Expected behavior

Both fixture files should result in an empty string being inserted in the database.

Dependencies

{
    "require-dev": {
        "doctrine/data-fixtures": "^1.3",
        "hautelook/alice-bundle": "^2.0",
        "nelmio/alice": "^3.1",
        "theofidry/alice-data-fixtures": "^1.0"
    },
}
@theofidry
Copy link
Member

Actually maybe this one is different as I guess if you want a "" or '' as a string input the expression should be \"\" and \'\'

@theofidry theofidry added this to the 2.x milestone Dec 25, 2017
@theofidry theofidry modified the milestones: 2.x, 3.x Feb 19, 2018
@theofidry
Copy link
Member

Actually looking at this again, this is a legit case. Indeed there is no way to understand that "" should be interpreted as an empty string as your expression is strictly equivalent to say "50% changes of having '<sentences()>' (which will be interpreted) or having '""' which is a plain string. If you want the result to be evaluated in an empty string i think that's the case where a custom Faker provider is required.

@dribtech
Copy link

dribtech commented Aug 19, 2018

Actually there is no need for custom Faker provider. Since PHP functions can be used as providers, this works reliable:
addressNote: '20%? <sentence()>: <strval("")>'
Of course instead of "" you can use anything that will evaluate into empty string by strval.

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

No branches or pull requests

3 participants