8000 Merge branch '4.1' into 4.2 · symfony/symfony-docs@2086b16 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 2086b16

Browse files
committed
Merge branch '4.1' into 4.2
* 4.1: [#10704] fix the line length [#10259] minor tweaks Unexpected PHP behavior [#10514] remove trailing whitespaces Added description for the "validation_groups" option Don't recommend requiring with Composer Tip about using stopwatch to show in profiler page
2 parents 8da7d97 + 5d33840 commit 2086b16

File tree

5 files changed

+115
-11
lines changed

5 files changed

+115
-11
lines changed

components/phpunit_bridge.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,27 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
540540
</listener>
541541
</listeners>
542542
</phpunit>
543+
544+
Under the hood, a PHPUnit 10000 listener injects the mocked functions in the tested
545+
classes' namespace. In order to work as expected, the listener has to run before
546+
the tested class ever runs. By default, the mocked functions are created when the
547+
annotation are found and the corresponding tests are run. Depending on how your
548+
tests are constructed, this might be too late. In this case, you will need to declare
549+
the namespaces of the tested classes in your phpunit.xml.dist
550+
551+
.. code-block:: xml
552+
553+
<!-- phpunit.xml.dist -->
554+
<!-- ... -->
555+
<listeners>
556+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
557+
<arguments>
558+
<array>
559+
<element key="time-sensitive"><string>Acme\MyClassTest</string></element>
560+
</array>
561+
</arguments>
562+
</listener>
563+
</listeners>
543564
544565
Modified PHPUnit script
545566
-----------------------

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
@@ -32,6 +32,7 @@ on all types for which ``FormType`` is the parent.
3232
| | - `property_path`_ |
3333
| | - `required`_ |
3434
| | - `trim`_ |
35+
| | - `validation_groups`_ |
3536
+-----------+--------------------------------------------------------------------+
3637
| Inherited | - `attr`_ |
3738
| options | - `auto_initialize`_ |
@@ -136,6 +137,8 @@ The actual default value of this option depends on other field options:
136137

137138
.. include:: /reference/forms/types/options/trim.rst.inc
138139

140+
.. include:: /reference/forms/types/options/validation_groups.rst.inc
141+
139142
Inherited Options
140143
-----------------
141144

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.

setup.rst

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,8 @@ Checking for Security Vulnerabilities
116116
-------------------------------------
117117

118118
Symfony provides a utility called the "Security Checker" to check whether your
119-
project's dependencies contain any known security vulnerability. Run this
120-
command to install it in your application:
121-
122-
.. code-block:: terminal
123-
124-
$ cd my-project/
125-
$ composer require sensiolabs/security-checker --dev
126-
127-
From now on, this utility will be run automatically whenever you install or
128-
update any dependency in the application. If a dependency contains a vulnerability,
129-
you'll see a clear message.
119+
project's dependencies contain any known security vulnerability. Check out
120+
the integration instructions for `the Security Checker`_ to set it up.
130121

131122
The Symfony Demo application
132123
----------------------------
@@ -162,5 +153,6 @@ Go Deeper with Setup
162153

163154
.. _`Stellar Development with Symfony`: http://symfonycasts.com/screencast/symfony
164155
.. _`Composer`: https://getcomposer.org/
156+
.. _`the Security Checker`: https://github.com/sensiolabs/security-checker#integration
165157
.. _`The Symfony Demo application`: https://github.com/symfony/demo
166158
.. _`symfony/symfony-demo`: https://github.com/symfony/demo

0 commit comments

Comments
 (0)
0