8000 Simplify some parts of the functional tests · Issue #27627 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Simplify some parts of the functional tests #27627

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

Closed
javiereguiluz opened this issue Jun 18, 2018 · 1 comment
Closed

Simplify some parts of the functional tests #27627

javiereguiluz opened this issue Jun 18, 2018 · 1 comment
Labels
BrowserKit DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature

Comments

@javiereguiluz
Copy link
Member
javiereguiluz commented Jun 18, 2018

Description
The code needed to click links or submit forms in functional tests looks a bit verbose.

The steps used to get the Link object may be OK when using this inside the DomCrawler component ... because you can do advanced things like calling the getUri() on the Link object. However, when using this inside a Symfony app, it looks unnecessary.

Example

Links

Before:

$link = $crawler->selectLink('Click here')->link();
$client->click($link);

After:

$client->click('Click here');

// if click() arguments can't be changed, then
// $client->clickLink(...)

Forms

Before:

$buttonCrawlerNode = $crawler->selectButton('Register');
$form = $buttonCrawlerNode->form();
$form = $buttonCrawlerNode->form([
    'my_form_name[name]'    => 'Fabien',
    'my_form_name[subject]' => 'Symfony rocks!',
], 'DELETE');
$client->submit($form);

After:

$client->submit('Register', [
    'my_form_name[name]'    => 'Fabien',
    'my_form_name[subject]' => 'Symfony rocks!',
], 'DELETE');

// if submit() arguments can't be changed, then
// $client->submitForm(...)

We could also change how things work and take the forms via their names (if they don't have a name, then use the traditional way). The above example would look like this:

$client->submit('my_form_name', [
    'name'    => 'Fabien',
    'subject' => 'Symfony rocks!',
], 'DELETE');
@javiereguiluz javiereguiluz added Feature DomCrawler DX DX = Developer eXperience (anything that improves the experience of using Symfony) BrowserKit and removed DomCrawler labels Jun 18, 2018
@Aerendir
Copy link
Contributor

Yes, it is really verbose and hiding this logic in helper methods seems a good thing to me. Anyway, if someone wants more control can continue to use the actual ways. +1

fabpot added a commit that referenced this issue Jul 12, 2018
…lass (nowiko)

This PR was squashed before being merged into the 4.2-dev branch (closes #27807).

Discussion
----------

Added new methods submitForm and clickLink to Client class

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Added new methods to BrowserKit/Client to simplify work with links and forms.
Related to #27627

Commits
-------

e098edd Added new methods submitForm and clickLink to Client class
@xabbuh xabbuh closed this as completed Jul 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BrowserKit DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature
Projects
None yet
Development

No branches or pull requests

3 participants
0