Skip to content

Commit

Permalink
Removed UUID from Generator to be able to extend it (#441)
Browse files Browse the repository at this point in the history
Co-authored-by: Pim Jansen <[email protected]>
  • Loading branch information
pimjansen and pimjansen authored Feb 2, 2022
1 parent 3a50490 commit 348757a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
2 changes: 2 additions & 0 deletions roave-bc-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ parameters:
- '#\[BC\] CHANGED: The parameter \$generator of Faker\\UniqueGenerator\#\_\_construct\(\) changed from Faker\\Generator to no type#'
- '#\[BC\] CHANGED: The return type of Faker\\Extension\\PersonExtension\#name\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$max of Faker\\Extension\\NumberExtension\#randomFloat\(\) changed from float to float\|null#'
- '#\[BC\] REMOVED: Method Faker\\Generator\#uuid\(\) was removed#'
- '#\[BC\] REMOVED: Method Faker\\Generator\#uuid3\(\) was removed#'
28 changes: 0 additions & 28 deletions src/Faker/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -797,34 +797,6 @@ public function bloodGroup(): string
return $this->ext(Extension\BloodExtension::class)->bloodGroup();
}

/**
* Get a random v3 uuid
*
* @example '7e57d004-2b97-0e7a-b45f-5387367791cd'
*
* @deprecated call uuid3() instead
*/
public function uuid(): string
{
trigger_deprecation(
'fakerphp/faker',
'1.18',
'Method uuid() is deprecated, call uuid3() instead'
);

return $this->uuid3();
}

/**
* Get a random v3 uuid
*
* @example '7e57d004-2b97-0e7a-b45f-5387367791cd'
*/
public function uuid3(): string
{
return $this->ext(Extension\UuidExtension::class)->uuid3();
}

/**
* Get a random EAN13 barcode.
*
Expand Down
17 changes: 12 additions & 5 deletions test/Faker/Core/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,35 @@

namespace Faker\Test\Core;

use Faker\Core\Uuid;
use Faker\Test\TestCase;

final class UuidTest extends TestCase
{
public function testUuidReturnsUuid()
{
$uuid = $this->faker->uuid3();
$instance = new Uuid();
$uuid = $instance->uuid3();
self::assertTrue($this->isUuid($uuid));
}

public function testUuidExpectedSeed()
{
$instance = new Uuid();

if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {
self::markTestSkipped('Big Endian');
}
$this->faker->seed(123);
self::assertEquals('8e2e0c84-50dd-367c-9e66-f3ab455c78d6', $this->faker->uuid3());
self::assertEquals('073eb60a-902c-30ab-93d0-a94db371f6c8', $this->faker->uuid3());
self::assertEquals('8e2e0c84-50dd-367c-9e66-f3ab455c78d6', $instance->uuid3());
self::assertEquals('073eb60a-902c-30ab-93d0-a94db371f6c8', $instance->uuid3());
}

protected function isUuid($uuid)
protected function isUuid(string $uuid)
{
return is_string($uuid) && (bool) preg_match('/^[a-f0-9]{8,8}-(?:[a-f0-9]{4,4}-){3,3}[a-f0-9]{12,12}$/i', $uuid);
return is_string($uuid) && (bool) preg_match(
'/^[a-f0-9]{8,8}-(?:[a-f0-9]{4,4}-){3,3}[a-f0-9]{12,12}$/i',
$uuid
);
}
}

0 comments on commit 348757a

Please sign in to comment.