UuidTest.php 904 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Faker\Test\Provider;
  3. use Faker\Generator;
  4. use Faker\Provider\Uuid as BaseProvider;
  5. use PHPUnit\Framework\TestCase;
  6. class UuidTest extends TestCase
  7. {
  8. public function testUuidReturnsUuid()
  9. {
  10. $uuid = BaseProvider::uuid();
  11. $this->assertTrue($this->isUuid($uuid));
  12. }
  13. public function testUuidExpectedSeed()
  14. {
  15. if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {
  16. $this->markTestSkipped('Big Endian');
  17. }
  18. $faker = new Generator();
  19. $faker->seed(123);
  20. $this->assertEquals("8e2e0c84-50dd-367c-9e66-f3ab455c78d6", BaseProvider::uuid());
  21. $this->assertEquals("073eb60a-902c-30ab-93d0-a94db371f6c8", BaseProvider::uuid());
  22. }
  23. protected function isUuid($uuid)
  24. {
  25. 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);
  26. }
  27. }