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

Commitb352ce0

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: [Uid] Tweak MockUuidFactory docs
2 parents8893cbb +cec4145 commitb352ce0

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

‎components/uid.rst‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,16 @@ of the UUID parameters::
398398
}
399399
}
400400

401-
MockUuidFactory
402-
===============
401+
Testing UUIDs
402+
~~~~~~~~~~~~~
403403

404-
The:class:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory` class allows you to
405-
control the UUIDs generated during your tests, making them predictable and reproducible.
404+
Many UUID versions include random or time-dependent parts, which makes them
405+
hard to use in tests. The:class:`Symfony\\Component\\Uid\\Factory\\MockUuidFactory`
406+
class allows you to control the UUIDs generated during your tests, making them
407+
predictable and reproducible.
406408

407-
Suppose you have a service that generates a UUID for each new user::
409+
First, make sure that your service generates UUID values using the
410+
:class:`Symfony\\Component\\Uid\\Factory\\UuidFactory`::
408411

409412
use Symfony\Component\Uid\Factory\UuidFactory;
410413
use Symfony\Component\Uid\Uuid;
@@ -422,15 +425,16 @@ Suppose you have a service that generates a UUID for each new user::
422425
}
423426
}
424427

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

427431
use PHPUnit\Framework\TestCase;
428432
use Symfony\Component\Uid\Factory\MockUuidFactory;
429433
use Symfony\Component\Uid\UuidV4;
430434

431435
class UserServiceTest extends TestCase
432436
{
433-
public functiontestCreateUserIdReturnsExpectedUuid()
437+
public functiontestCreateUserId(): void
434438
{
435439
$factory = new MockUuidFactory([
436440
UuidV4::fromString('11111111-1111-4111-8111-111111111111'),
@@ -444,15 +448,14 @@ In your tests, you can use ``MockUuidFactory`` to inject predictable UUIDs and v
444448
}
445449
}
446450

447-
..warning::
448-
449-
``MockUuidFactory`` is intended for useintests only and should never be used in production.
451+
In addition to the ``create()`` method, the ``MockUuidFactory`` also works for
452+
the ``randomBased()``, ``timeBased()``, and ``nameBased()`` methods. You can even
453+
mix different UUID versionsinthe same sequence.
450454

451455
..note::
452456

453-
- 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.
454-
- You can mix different UUID versions in the same sequence.
455-
- Throws an exception if the sequence is exhausted or the type does not match.
457+
``MockUuidFactory`` throws an exception if the sequence is exhausted or the
458+
available UUID types don't match the requested type.
456459

457460
.. _ulid:
458461

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp