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

[RFC][Behat] Extract reusable transformers #4269

Merged
merged 6 commits into from
Feb 24, 2016

Conversation

Zales0123
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets #4225
License MIT
Doc PR

In order to avoid (current or future) duplications and make new behat scenarios even easier to write and it (they're already pretty natural 😄), here is propose of two additional contexts, containing reusable transformers. Concept is widely described in related issue, just to make it clear about new features:

SharedStorageContext:

  • it -> transform to last resource from SharedStorage
  • this|that|the {resource} -> transform to specific resource from SharedStorage

LexicalContext:

  • €103.00 (string) -> 10300 (int)
  • 20% (string) -> 0.2 (float)

I'm sure we could find lots of more use cases that can be placed in one of this context. Moreover, I hope that by using them wisely, we could get rid of injecting SharedContext into most of contexts and minimize number of private functions.

@@ -24,6 +24,8 @@
<parameter key="sylius.behat.context.setup.shipping.class">Sylius\Behat\Context\Setup\ShippingContext</parameter>
<parameter key="sylius.behat.context.setup.zone.class">Sylius\Behat\Context\Setup\ZoneContext</parameter>
<parameter key="sylius.behat.context.setup.tax.class">Sylius\Behat\Context\Setup\TaxContext</parameter>
<parameter key="sylius.behat.context.setup.lexical.class">Sylius\Behat\Context\Setup\LexicalContext</parameter>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO new namespace sylius.behat.context.transform.* would be the most suitable for contexts that only transforms arguments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍 I couldn't come up with some good name, bad transform is simple and accurate 😄

@pamil
Copy link
Contributor

pamil commented Feb 23, 2016

👍, we will have to use shared context directly only to set a resource after this PR gets merged! :)

@pjedrzejewski pjedrzejewski added the DX Issues and PRs aimed at improving Developer eXperience. label Feb 23, 2016
}

/**
* @Transform /^"([^"]+)%"$/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be better to use here regex which will match only floats? ([0-9]*\.)?[0-9]+

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make it /^"((?:\d+\.)?\d+)%"$/ 🎉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, same for price from string :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pjedrzejewski pushed a commit that referenced this pull request Feb 24, 2016
[RFC][Behat] Extract reusable transformers
@pjedrzejewski pjedrzejewski merged commit 58871be into Sylius:master Feb 24, 2016
@pjedrzejewski
Copy link
Member

Thanks Mateusz! 👍

@Zales0123 Zales0123 deleted the extract-reusable-transformers branch October 28, 2016 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Issues and PRs aimed at improving Developer eXperience.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants