Created
October 5, 2018 08:36
-
-
Save matthewbdaly/d5cd339f3f2c40afa95e1a5dfa7ca5db to your computer and use it in GitHub Desktop.
PHPUnit custom assertion for checking a string is a valid UUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | |
use PHPUnit\Framework\TestCase as BaseTestCase; | |
class SimpleTestCase extends BaseTestCase | |
{ | |
use MockeryPHPUnitIntegration; | |
public function assertIsValidUuid($uuid, string $message = '') | |
{ | |
$pattern = '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i'; | |
self::assertRegExp($pattern, $uuid, $message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment