Skip to content

Commit 40d0fa3

Browse files
committed
Merge branch '4.4'
* 4.4: [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 20b5432 + 420b34e commit 40d0fa3

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
@@ -234,6 +234,8 @@ to catching the exception, you can also check if a given currency code is valid:
234234

235235
$isValidCurrency = Currencies::exists($currencyCode);
236236

237+
.. _component-intl-timezones:
238+
237239
Timezones
238240
~~~~~~~~~
239241

components/phpunit_bridge.rst

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,78 @@ conditions::
589589
],
590590
]);
591591

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

reference/constraints/Timezone.rst

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

66
========== ======================================================================
77
Applies to :ref:`property or method <validation-property-target>`
8-
Options - `groups`_
8+
Options - `countryCode`_
9+
- `groups`_
10+
- `intlCompatible`_
911
- `message`_
1012
- `payload`_
1113
- `zone`_
12-
- `countryCode`_
1314
Class :class:`Symfony\\Component\\Validator\\Constraints\\Timezone`
1415
Validator :class:`Symfony\\Component\\Validator\\Constraints\\TimezoneValidator`
1516
========== ======================================================================
@@ -18,7 +19,7 @@ Basic Usage
1819
-----------
1920

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

2324
.. configuration-block::
2425

@@ -81,8 +82,34 @@ string meant to contain a timezone identifier (e.g. ``America/New_York``):
8182
Options
8283
-------
8384

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

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

@@ -127,17 +154,6 @@ In addition, there are some special zone values:
127154
* ``\DateTimeZone::PER_COUNTRY`` restricts the valid timezones to a certain
128155
country (which is defined using the ``countryCode`` option).
129156

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

0 commit comments

Comments
 (0)