8000 Merge branch '3.4' into 4.1 · symfony/symfony-docs@5d33840 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d33840

Browse files
committed
Merge branch '3.4' into 4.1
* 3.4: [#10259] minor tweaks Unexpected PHP behavior [#10514] remove trailing whitespaces Added description for the "validation_groups" option Tip about using stopwatch to show in profiler page
2 parents ba29ecb + 9b7f158 commit 5d33840

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

components/phpunit_bridge.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
515515
</listener>
516516
</listeners>
517517
</phpunit>
518+
519+
Under the hood, a PHPUnit listener injects the mocked functions in the tested
520+
classes' namespace. In order to work as expected, the listener has to run before
521+
the tested class ever runs. By default, the mocked functions are created when the
522+
annotation are found and the corresponding tests are run. Depending on how your
523+
tests are constructed, this might be too late. In this case, you will need to declare
524+
the namespaces of the tested classes in your phpunit.xml.dist
525+
526+
.. code-block:: xml
527+
528+
<!-- phpunit.xml.dist -->
529+
<!-- ... -->
530+
<listeners>
531+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
532+
<arguments>
533+
<array>
534+
<element key="time-sensitive"><string>Acme\MyClassTest</string></element>
535+
</array>
536+
</arguments>
537+
</listener>
538+
</listeners>
518539
519540
Modified PHPUnit script
520541
-----------------------

components/stopwatch.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ You can also provide a category name to an event::
6161
You can consider categories as a way of tagging events. For example, the
6262
Symfony Profiler tool uses categories to nicely color-code different events.
6363

64+
.. tip::
65+
66+
When you want to show events in the Symfony profiler, autowire
67+
``Symfony\Component\Stopwatch\Stopwatch`` into your service. Each category
68+
is shown on a separate line.
69+
6470
Periods
6571
-------
6672

reference/forms/types/form.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ on all types for which ``FormType`` is the parent.
3131
| | - `property_path`_ |
3232
| | - `required`_ |
3333
| | - `trim`_ |
34+
| | - `validation_groups`_ |
3435
+-----------+--------------------------------------------------------------------+
3536
| Inherited | - `attr`_ |
3637
| options | - `auto_initialize`_ |
@@ -133,6 +134,8 @@ The actual default value of this option depends on other field options:
133134

134135
.. include:: /reference/forms/types/options/trim.rst.inc
135136

137+
.. include:: /reference/forms/types/options/validation_groups.rst.inc
138+
136139
Inherited Options
137140
-----------------
138141

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
validation_groups
2+
~~~~~~~~~~~~~~~~~
3+
4+
**type**: ``array``, ``string``, ``callable``, :class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence` or ``null`` **default**: ``null``
5+
6+
This option is only valid on the root form and is used to specify which
7+
groups will be used by the validator.
8+
9+
For ``null`` the validator will just use the ``Default`` group.
10+
11+
If you specify the groups as an array or string they will be used by the
12+
validator as they are::
13+
14+
public function configureOptions(OptionsResolver $resolver)
15+
{
16+
$resolver->setDefaults(array(
17+
'validation_groups' => 'Registration',
18+
));
19+
}
20+
21+
This is equivalent to passing the group as array::
22+
23+
'validation_groups' => array('Registration'),
24+
25+
The form's data will be :doc:`validated against all given groups </form/validation_groups>`.
26+
27+
If the validation groups depend on the form's data a callable may be passed to
28+
the option. Symfony will then pass the form when calling it::
29+
30+
use Symfony\Component\Form\FormInterface;
31+
use Symfony\Component\OptionsResolver\OptionsResolver;
32+
33+
// ...
34+
public function configureOptions(OptionsResolver $resolver)
35+
{
36+
$resolver->setDefaults(array(
37+
'validation_groups' => function (FormInterface $form) {
38+
$entity = $form->getData();
39+
40+
return $entity->isUser() ? array('User') : array('Company');
41+
},
42+
));
43+
}
44+
45+
.. seealso::
46+
47+
You can read more about this in :doc:`/form/data_based_validation`.
48+
49+
.. note::
50+
51+
When your form contains multiple submit buttons, you can change the
52+
validation group depending on :doc:`which button is used</form/button_based_validation>`
53+
to submit the form.
54+
55+
If you need advanced logic to determine the validation groups have
56+
a look at :doc:`/form/validation_group_service_resolver`.
57+
58+
In some cases, you want to validate your groups step by step. To do this, you
59+
can pass a :class:`Symfony\\Component\\Validator\\Constraints\\GroupSequence`
60+
to this option. This enables you to validate against multiple groups,
61+
like when you pass multiple groups in an array, but with the difference that
62+
a group is only validated if the previous groups pass without errors.
63+
Here's an example::
64+
65+
use Symfony\Component\Validator\Constraints\GroupSequence;
66+
use Symfony\Component\Form\AbstractType;
67+
// ...
68+
69+
class MyType extends AbstractType
70+
{
71+
// ...
72+
public function configureOptions(OptionsResolver $resolver)
73+
{
74+
$resolver->setDefaults([
75+
'validation_groups' => new GroupSequence(['First', 'Second']),
76+
]);
77+
}
78+
}
79+
80+
.. seealso::
81+
82+
Read the article :doc:`/validation/sequence_provider` to find out more about this.

0 commit comments

Comments
 (0)
0