Skip to content

Commit 8f80889

Browse files
committed
[Uid] Tweak MockUuidFactory docs
1 parent 5fdca73 commit 8f80889

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

components/uid.rst

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,16 @@ of the UUID parameters::
445445
}
446446
}
447447

448-
MockUuidFactory
449-
===============
448+
Testing UUIDs
449+
~~~~~~~~~~~~~
450450

451-
.. versionadded:: 7.4
452-
453-
The :class:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory` class was introduced in Symfony 7.4.
454-
455-
The :class:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory` class allows you to
456-
control the UUIDs generated during your tests, making them predictable and reproducible.
451+
Many UUID versions include random or time-dependent parts, which makes them
452+
hard to use in tests. The :class:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory`
453+
class allows you to control the UUIDs generated during your tests, making them
454+
predictable and reproducible.
457455

458-
Suppose you have a service that generates a UUID for each new user::
456+
First, make sure that your service generates UUID values using the
457+
:class:`Symfony\\Component\\Uid\\Factory\\UuidFactory`::
459458

460459
use Symfony\Component\Uid\Factory\UuidFactory;
461460
use Symfony\Component\Uid\Uuid;
@@ -473,15 +472,16 @@ Suppose you have a service that generates a UUID for each new user::
473472
}
474473
}
475474

476-
In your tests, you can use ``MockUuidFactory`` to inject predictable UUIDs and verify the expected behavior::
475+
Then, in your tests, you can use ``MockUuidFactory`` to define a sequence of the
476+
UUIDs that will be returned each time you generate one::
477477

478478
use PHPUnit\Framework\TestCase;
479479
use Symfony\Component\Uid\Factory\MockUuidFactory;
480480
use Symfony\Component\Uid\UuidV4;
481481

482482
class UserServiceTest extends TestCase
483483
{
484-
public function testCreateUserIdReturnsExpectedUuid()
484+
public function testCreateUserId(): void
485485
{
486486
$factory = new MockUuidFactory([
487487
UuidV4::fromString('11111111-1111-4111-8111-111111111111'),
@@ -495,15 +495,14 @@ In your tests, you can use ``MockUuidFactory`` to inject predictable UUIDs and v
495495
}
496496
}
497497

498-
.. warning::
499-
500-
``MockUuidFactory`` is intended for use in tests only and should never be used in production.
498+
In addition to the ``create()`` method, the ``MockUuidFactory`` also works for
499+
the ``randomBased()``, ``timeBased()``, and ``nameBased()`` methods. You can even
500+
mix different UUID versions in the same sequence.
501501

502502
.. note::
503503

504-
- Supports the :method:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory::create`, :method:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory::randomBased`, :method:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory::timeBased`, and :method:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory::nameBased` methods.
505-
- You can mix different UUID versions in the same sequence.
506-
- Throws an exception if the sequence is exhausted or the type does not match.
504+
``MockUuidFactory`` throws an exception if the sequence is exhausted or the
505+
available UUID types don't match the requested type.
507506

508507
.. _ulid:
509508

0 commit comments

Comments
 (0)