Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcec4145

Browse files
committed
minor#21518 [Uid] Tweak MockUuidFactory docs (javiereguiluz)
This PR was merged into the 7.4 branch.Discussion----------[Uid] Tweak MockUuidFactory docsChanges compared to#21422:* The title of the section was demoted to h3 from h1* The section title is now more friendly to SEO and AI* Updated the intro to better explain the problem of testing UUIDs* Reworded the note contents because we usually put most of the information outside of notes/tips admonitions.Commits-------8f80889 [Uid] Tweak MockUuidFactory docs
2 parentsdffc9ee +8f80889 commitcec4145

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 functiontestCreateUserIdReturnsExpectedUuid()
484+
public functiontestCreateUserId(): 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 useintests 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 versionsinthe 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)

[8]ページ先頭

©2009-2025 Movatter.jp