Skip to content

Commit 022bd2f

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: Corrected titles of test tools and use safe url for phpspec Add 2 solutions for the 'option with optional argument' problem Simplify the explanation leaving just one solution Add 2 solutions for the 'option with optional argument' problem Fix a typo in the HTML5 date form property Remove extra brace in the release schedule
2 parents dca1fa0 + ac45677 commit 022bd2f

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

best_practices/tests.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Unit Tests
1212
Unit tests are used to test your "business logic", which should live in classes
1313
that are independent of Symfony. For that reason, Symfony doesn't really
1414
have an opinion on what tools you use for unit testing. However, the most
15-
popular tools are `PhpUnit`_ and `PhpSpec`_.
15+
popular tools are `PHPUnit`_ and `PHPSpec`_.
1616

1717
Functional Tests
1818
----------------
@@ -112,8 +112,8 @@ Learn More about Functional Tests
112112
Consider using the `HautelookAliceBundle`_ to generate real-looking data for
113113
your test fixtures using `Faker`_ and `Alice`_.
114114

115-
.. _`PhpUnit`: https://phpunit.de/
116-
.. _`PhpSpec`: http://www.phpspec.net/
115+
.. _`PHPUnit`: https://phpunit.de/
116+
.. _`PHPSpec`: https://www.phpspec.net/
117117
.. _`smoke testing`: https://en.wikipedia.org/wiki/Smoke_testing_(software)
118118
.. _`Mink`: http://mink.behat.org
119119
.. _`HautelookAliceBundle`: https://github.com/hautelook/AliceBundle

console/input.rst

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ values after a white space or an ``=`` sign (e.g. ``--iterations 5`` or
179179
``--iterations=5``), but short options can only use white spaces or no
180180
separation at all (e.g. ``-i 5`` or ``-i5``).
181181

182+
.. caution::
183+
184+
While it is possible to separate an option from its value with a white space,
185+
using this form leads to an ambiguity should the option appear before the
186+
command name. For example, ``php app/console --iterations 5 app:greet Fabien``
187+
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
188+
this situation, always place options after the command name, or avoid using
189+
a space to separate the option name from its value.
190+
182191
There are four option variants you can use:
183192

184193
``InputOption::VALUE_IS_ARRAY``
@@ -209,21 +218,53 @@ You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or
209218
array('blue', 'red')
210219
);
211220

212-
.. tip::
221+
Options with optional arguments
222+
-------------------------------
223+
224+
There is nothing forbidding you to create a command with an option that
225+
optionally accepts a value, but it's a bit tricky. Consider this example::
226+
227+
// ...
228+
use Symfony\Component\Console\Input\InputOption;
229+
230+
$this
231+
// ...
232+
->addOption(
233+
'yell',
234+
null,
235+
InputOption::VALUE_OPTIONAL,
236+
'Should I yell while greeting?'
237+
);
238+
239+
This option can be used in 3 ways: ``--yell``, ``yell=louder``, and not passing
240+
the option at all. However, it's hard to distinguish between passing the option
241+
without a value (``greet --yell``) and not passing the option (``greet``).
242+
243+
To solve this issue, you have to set the option's default value to ``false``::
244+
245+
// ...
246+
use Symfony\Component\Console\Input\InputOption;
247+
248+
$this
249+
// ...
250+
->addOption(
251+
'yell',
252+
null,
253+
InputOption::VALUE_OPTIONAL,
254+
'Should I yell while greeting?',
255+
false // this is the new default value, instead of null
256+
);
213257

214-
There is nothing forbidding you to create a command with an option that
215-
optionally accepts a value. However, there is no way you can distinguish
216-
when the option was used without a value (``command --language``) or when
217-
it wasn't used at all (``command``). In both cases, the value retrieved for
218-
the option will be ``null``.
258+
Now check the value of the option and keep in mind that ``false !== null``::
259+
260+
$optionValue = $input->getOptions('yell');
261+
$yell = ($optionValue !== false);
262+
$yellLouder = ($optionValue === 'louder');
219263

220264
.. caution::
221265

222-
While it is possible to separate an option from its value with a white space,
223-
using this form leads to an ambiguity should the option appear before the
224-
command name. For example, ``php bin/console --iterations 5 app:greet Fabien``
225-
is ambiguous; Symfony would interpret ``5`` as the command name. To avoid
226-
this situation, always place options after the command name, or avoid using
227-
a space to separate the option name from its value.
266+
Due to a PHP limitation, passing an empty string is indistinguishable from
267+
not passing any value at all. In ``command --prefix`` and ``command --prefix=''``
268+
cases, the value of the ``prefix`` option will be ``null``.
228269

229270
.. _`docopt standard`: http://docopt.org/

contributing/community/releases.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Version Feature Freeze Release End of Maintenance End of Life
122122
`2.6`_ 09/2014 11/2014 07/2015 (8 months) 01/2016
123123
`2.7`_ (LTS) 03/2015 05/2015 05/2018 (36 months) 05/2019
124124
`2.8`_ (LTS) 09/2015 11/2015 11/2018 (36 months [2]_) 11/2019
125-
`3.0`_ 09/2015 11/2015 07/2016 (8 months) [3]_) 01/2017
125+
`3.0`_ 09/2015 11/2015 07/2016 (8 months [3]_) 01/2017
126126
`3.1`_ 03/2016 05/2016 01/2017 (8 months) 07/2017
127127
`3.2`_ 09/2016 11/2016 07/2017 (8 months) 01/2018
128128
`3.3`_ 03/2017 05/2017 01/2018 (8 months) 07/2018
@@ -194,7 +194,7 @@ version is published every two years and there is a year to upgrade.
194194

195195
.. _Semantic Versioning: https://semver.org/
196196
.. _Git repository: https://github.com/symfony/symfony
197-
.. _SensioLabs: http://sensiolabs.com/
197+
.. _SensioLabs: https://sensiolabs.com/
198198
.. _roadmap notification: https://symfony.com/roadmap
199199
.. _extended to September 2014: https://symfony.com/blog/extended-maintenance-for-symfony-2-4
200200
.. _timeline calculator: https://symfony.com/roadmap#checker

reference/forms/types/options/html5.rst.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ html5
66
If this is set to ``true`` (the default), it'll use the HTML5 type (date, time
77
or datetime) to render the field. When set to ``false``, it'll use the text type.
88

9-
This is useful when you want to use a custom JavaScript datapicker, which
9+
This is useful when you want to use a custom JavaScript datepicker, which
1010
often requires a text type instead of an HTML5 type.

0 commit comments

Comments
 (0)