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

Add support for snake_care properties in fixtures. #323

Merged
merged 3 commits into from
May 13, 2016
Merged

Add support for snake_care properties in fixtures. #323

merged 3 commits into from
May 13, 2016

Conversation

hboomsma
Copy link

@hboomsma hboomsma commented Apr 6, 2016

When for a property a setter exists Alice will use that setter to populate the value. Now properties that use snake case are also transformed into their corresponding setters. For example:

Nelmio\Alice\support\models\User:
    user{1..10}:
        family_name: <lastName()>

Will use the setter setFamilyName if available and otherwise fill the property without setter.

@reinfi
Copy link
Contributor

reinfi commented Apr 8, 2016

A good codingstyle would have the setters also in snake_case, not in camelCase.
So what's the case you need this?

@hboomsma
Copy link
Author

hboomsma commented Apr 9, 2016

Having a PSR2 compatible code style with snake case properties. And several MLOC, I would rather not change. Already implemented this as extension in the company, just trying to give something back by making Alice more codestyle agnostic.

@reinfi
Copy link
Contributor

reinfi commented Apr 9, 2016

Do I understand you right that you have snake_case properties and camelCase setters?

@hboomsma
Copy link
Author

correct.

@tshelburne
Copy link
Collaborator

I think I'm good for this, since it doesn't break BC - @Seldaek any comments?

@Seldaek
Copy link
Member

Seldaek commented Apr 25, 2016

Seems safe enough as long as people use camelCased method names, but strictly speaking it does break BC as if you have setfoo_bar it'll now call setfoobar. I doubt it'll really be an issue in practice though.

@tshelburne
Copy link
Collaborator

@hboomsma I think @Seldaek makes a good point - why don't we just check for both methods and call whichever exists?

Remaining BC if a setsnake_case setter exists.

When for a property a setter exists Alice will use
that setter to populate the value. Now properties
that use snake case are also transformed into their
corresponding setters. For example:

    Nelmio\Alice\support\models\User:
        user{1..10}:
            family_name: <lastName()>

    will use the setter setFamilyName if available
    and otherwise fill the property without setter.
@hboomsma
Copy link
Author

@tshelburne I agree, added it in.

@theofidry theofidry added this to the 2.x milestone May 4, 2016
@theofidry
Copy link
Member

theofidry commented May 12, 2016

@hboomsma I've made a PR with a few changes. Once merged I will merge and squash this PR.

If you have a property full_name, it will look in order:

  • setfullname()
  • setfull_name()
  • set_full_name()
  • set_fullname()

If it is a normal property, e.g. name:

  • setname()
  • set_name()

It also avoids to introduce a BC @Seldaek mentioned.

@theofidry theofidry merged commit 9d45f2b into nelmio:master May 13, 2016
@theofidry
Copy link
Member

Thanks very much for the work @hboomsma :)

@hboomsma hboomsma deleted the feature/snake_case branch September 13, 2016 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants