菜谱项目

UuidTest.php 769B

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