Skip to content

Instantly share code, notes, and snippets.

@matthewbdaly
Created October 5, 2018 08:36
Show Gist options
  • Save matthewbdaly/d5cd339f3f2c40afa95e1a5dfa7ca5db to your computer and use it in GitHub Desktop.
Save matthewbdaly/d5cd339f3f2c40afa95e1a5dfa7ca5db to your computer and use it in GitHub Desktop.
PHPUnit custom assertion for checking a string is a valid UUID
<?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