Skip to content

Commit 420b34e

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: [Validation] Documented the intlCompatible option in Timezone constraint Removed old versionadded directive [PhpUnitBridge] Add docs for ClassExistsMock Progress Bar Section -- Change CodeBlock Use versionadded instead of note directive
2 parents 5a6c448 + c80c38f commit 420b34e

File tree

5 files changed

+107
-23
lines changed

5 files changed

+107
-23
lines changed

components/cache/adapters/chain_adapter.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,5 @@ incompatible adapters are silently ignored::
5858
new FilesystemAdapter(), // DOES implement PruneableInterface
5959
]);
6060

61-
// prune will proxy the call to FilesystemAdapter while silently skipping ApcuAdapter
61+
// prune will proxy the call to FilesystemAdapter while silently skip ApcuAdapter
6262
$cache->prune();
63-
64-
.. note::
65-
66-
Since Symfony 3.4, this adapter implements :class:`Symfony\\Component\\Cache\\PruneableInterface`,
67-
allowing for manual :ref:`pruning of expired cache entries <component-cache-cache-pool-prune>` by
68-
calling its ``prune()`` method.

components/console/helpers/progressbar.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ which starts, advances and finishes the progress bar automatically::
112112

113113
If ``$iterable = [1, 2]``, the previous code will output the following:
114114

115-
.. code-block:: terminal
115+
.. code-block:: console
116116
117117
0/2 [>---------------------------] 0%
118118
1/2 [==============>-------------] 50%

components/intl.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ to catching the exception, you can also check if a given currency code is valid:
254254

255255
The ``Currencies`` class was introduced in Symfony 4.3.
256256

257+
.. _component-intl-timezones:
258+
257259
Timezones
258260
~~~~~~~~~
259261

components/phpunit_bridge.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,78 @@ conditions::
593593
],
594594
]);
595595

596+
Class Existence Based Tests
597+
---------------------------
598+
599+
Tests that behave differently depending on existing classes, for example Composer's
600+
development dependencies, are often hard to test for the alternate case. For that
601+
reason, this component also provides mocks for these PHP functions:
602+
603+
* :phpfunction:`class_exists`
604+
* :phpfunction:`interface_exists`
605+
* :phpfunction:`trait_exists`
606+
607+
Use Case
608+
~~~~~~~~
609+
610+
Consider the following example that relies on the ``Vendor\DependencyClass`` to
611+
toggle a behavior::
612+
613+
use Vendor\DependencyClass;
614+
615+
class MyClass
616+
{
617+
public function hello(): string
618+
{
619+
if (class_exists(DependencyClass::class)) {
620+
return 'The dependency bahavior.';
621+
}
622+
623+
return 'The default behavior.';
624+
}
625+
}
626+
627+
A regular test case for ``MyClass`` (assuming the development dependencies
628+
are installed during tests) would look like::
629+
630+
use MyClass;
631+
use PHPUnit\Framework\TestCase;
632+
633+
class MyClassTest extends TestCase
634+
{
635+
public function testHello()
636+
{
637+
$class = new MyClass();
638+
$result = $class->hello(); // "The dependency bahavior."
639+
640+
// ...
641+
}
642+
}
643+
644+
In order to test the default behavior instead use the
645+
``ClassExistsMock::withMockedClasses()`` to configure the expected
646+
classes, interfaces and/or traits for the code to run::
647+
648+
use MyClass;
649+
use PHPUnit\Framework\TestCase;
650+
use Vendor\DependencyClass;
651+
652+
class MyClassTest extends TestCase
653+
{
654+
// ...
655+
656+
public function testHelloDefault()
657+
{
658+
ClassExistsMock::register(MyClass::class);
659+
ClassExistsMock::withMockedClasses([DependencyClass::class => false]);
660+
661+
$class = new MyClass();
662+
$result = $class->hello(); // "The default bahavior."
663+
664+
// ...
665+
}
666+
}
667+
596668
Troubleshooting
597669
---------------
598670

reference/constraints/Timezone.rst

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ Validates that a value is a valid timezone identifier (e.g. ``Europe/Paris``).
99

1010
========== ======================================================================
1111
Applies to :ref:`property or method <validation-property-target>`
12-
Options - `groups`_
12+
Options - `countryCode`_
13+
- `groups`_
14+
- `intlCompatible`_
1315
- `message`_
1416
- `payload`_
1517
- `zone`_
16-
- `countryCode`_
1718
Class :class:`Symfony\\Component\\Validator\\Constraints\\Timezone`
1819
Validator :class:`Symfony\\Component\\Validator\\Constraints\\TimezoneValidator`
1920
========== ======================================================================
@@ -22,7 +23,7 @@ Basic Usage
2223
-----------
2324

2425
Suppose you have a ``UserSettings`` class, with a ``timezone`` field that is a
25-
string meant to contain a timezone identifier (e.g. ``America/New_York``):
26+
string which contains any of the `PHP timezone identifiers`_ (e.g. ``America/New_York``):
2627

2728
.. configuration-block::
2829

@@ -85,8 +86,34 @@ string meant to contain a timezone identifier (e.g. ``America/New_York``):
8586
Options
8687
-------
8788

89+
countryCode
90+
~~~~~~~~~~~
91+
92+
**type**: ``string`` **default**: ``null``
93+
94+
If the ``zone`` option is set to ``\DateTimeZone::PER_COUNTRY``, this option
95+
restricts the valid timezone identifiers to the ones that belong to the given
96+
country.
97+
98+
The value of this option must be a valid `ISO 3166-1 alpha-2`_ country code
99+
(e.g. ``CN`` for China).
100+
88101
.. include:: /reference/constraints/_groups-option.rst.inc
89102

103+
intlCompatible
104+
~~~~~~~~~~~~~~
105+
106+
**type**: ``boolean`` **default**: ``false``
107+
108+
This constraint considers valid both the `PHP timezone identifiers`_ and the
109+
:ref:`ICU timezones <component-intl-timezones>` provided by Symfony's
110+
:doc:`Intl component </components/intl>`
111+
112+
However, the timezones provided by the Intl component can be different from the
113+
timezones provided by PHP's Intl extension (because they use different ICU
114+
versions). If this option is set to ``true``, this constraint only considers
115+
valid the values created with the PHP ``\IntlTimeZone::createTimeZone()`` method.
116+
90117
message
91118
~~~~~~~
92119

@@ -131,17 +158,6 @@ In addition, there are some special zone values:
131158
* ``\DateTimeZone::PER_COUNTRY`` restricts the valid timezones to a certain
132159
country (which is defined using the ``countryCode`` option).
133160

134-
countryCode
135-
~~~~~~~~~~~
136-
137-
**type**: ``string`` **default**: ``null``
138-
139-
If the ``zone`` option is set to ``\DateTimeZone::PER_COUNTRY``, this option
140-
restricts the valid timezone identifiers to the ones that belong to the given
141-
country.
142-
143-
The value of this option must be a valid `ISO 3166-1 alpha-2`_ country code
144-
(e.g. ``CN`` for China).
145-
161+
.. _`PHP timezone identifiers`: https://www.php.net/manual/en/timezones.php
146162
.. _`DateTimeZone`: https://www.php.net/datetimezone
147163
.. _`ISO 3166-1 alpha-2`: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

0 commit comments

Comments
 (0)