Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DomCrawler] Add hint about Form::getName method #11705

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

Merged
merged 1 commit into from
Oct 1, 2019

Conversation

JustBlackBird
Copy link
Contributor

This PR describes some use cases of Symfony\Component\DomCrawler\Form::getName method

@JustBlackBird JustBlackBird force-pushed the dom-crawler-form-name branch from 41ed748 to 36ced8b Compare June 9, 2019 12:15
fabpot added a commit to symfony/symfony that referenced this pull request Jun 14, 2019
…JustBlackBird)

This PR was squashed before being merged into the 4.4 branch (closes #31959).

Discussion
----------

[DomCrawler][Feature][DX] Add Form::getName() method

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | None
| License       | MIT
| Doc PR        | symfony/symfony-docs#11705

The PR adds `Symfony\Component\DomCrawler\Form::getName` method.

The method is actually a syntax sugar but can improve DX when dealing with tests. For example, in the snippet

```php
$client = static::createClient();
$crawler = $client->request('GET', '/post/hello-world');
$form = $crawler->selectButton('submit')->form();

$form['my_form[name]'] = 'Fabien';
$form['my_form[subject]'] = 'Symfony rocks!';
```
the prefix in field name (`my_form`) is form name, which is generated by Symfony automatically. The method, added in the PR helps to get that name in a most obvious way.

Commits
-------

ff53cb4 [DomCrawler][Feature][DX] Add Form::getName() method
symfony-splitter pushed a commit to symfony/dom-crawler that referenced this pull request Jun 14, 2019
…JustBlackBird)

This PR was squashed before being merged into the 4.4 branch (closes #31959).

Discussion
----------

[DomCrawler][Feature][DX] Add Form::getName() method

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | None
| License       | MIT
| Doc PR        | symfony/symfony-docs#11705

The PR adds `Symfony\Component\DomCrawler\Form::getName` method.

The method is actually a syntax sugar but can improve DX when dealing with tests. For example, in the snippet

```php
$client = static::createClient();
$crawler = $client->request('GET', '/post/hello-world');
$form = $crawler->selectButton('submit')->form();

$form['my_form[name]'] = 'Fabien';
$form['my_form[subject]'] = 'Symfony rocks!';
```
the prefix in field name (`my_form`) is form name, which is generated by Symfony automatically. The method, added in the PR helps to get that name in a most obvious way.

Commits
-------

ff53cb462a [DomCrawler][Feature][DX] Add Form::getName() method
testing.rst Outdated
@@ -801,6 +801,12 @@ their type::
$form['my_form[field][O]']->upload('/path/to/lucas.jpg');
$form['my_form[field][1]']->upload('/path/to/lisa.jpg');

.. tip::

All field names in forms generated by symfony are prefixed with form's name.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
All field names in forms generated by symfony are prefixed with form's name.
All field names in forms generated by Symfony are prefixed with the form's name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OskarStark fixed

@OskarStark OskarStark requested a review from xabbuh June 14, 2019 11:35
@xabbuh xabbuh added this to the 4.4 milestone Jun 14, 2019
@JustBlackBird JustBlackBird force-pushed the dom-crawler-form-name branch from 36ced8b to c8a6ec5 Compare June 14, 2019 20:27
.. tip::

All field names in forms generated by Symfony are prefixed with the form's name.
If the name is autogenerated you can get it using
Copy link
Member

Choose a reason for hiding this comment

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

This sounds misleading IMO. For the method it doesn't really matter how the name originates. Maybe we should reword it to something like this:

Use the getName() method if you need to access the name of a form.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Name of the field is not that obvious on the first sight, so I believe a hint is needed to make it clear. Also, using getName method in tests can make them a little less fragile.

javiereguiluz added a commit that referenced this pull request Oct 1, 2019
…ackBird)

This PR was merged into the 4.4 branch.

Discussion
----------

[DomCrawler] Add hint about Form::getName method

This PR describes some use cases of `Symfony\Component\DomCrawler\Form::getName` method

Commits
-------

c8a6ec5 [DomCrawler] Add hint about Form::getName method
@javiereguiluz javiereguiluz merged commit c8a6ec5 into symfony:4.4 Oct 1, 2019
@javiereguiluz
Copy link
Member

Dmitriy, thanks a lot for contributing this nice little feature and thanks for providing the docs too! We merged it with some very minor rewords as proposed by @xabbuh.

Congrats on your first Symfony Docs contribution!

@JustBlackBird JustBlackBird deleted the dom-crawler-form-name branch October 26, 2019 13:13
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