Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12740877
RandomTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
RandomTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Tests\Identifiers
;
use
Keruald\OmniTools\Identifiers\Random
;
use
PHPUnit\Framework\Attributes\DataProvider
;
use
PHPUnit\Framework\TestCase
;
class
RandomTest
extends
TestCase
{
///
/// Tests
///
public
function
testGenerateHexadecimalHash
()
:
void
{
$hash
=
Random
::
generateHexHash
();
$this
->
assertEquals
(
32
,
strlen
(
$hash
),
"$hash size must be 32 characters"
);
$this
->
assertMatchesRegularExpression
(
"/[0-9a-f]{32}/"
,
$hash
);
}
public
function
testHexadecimalHashesAreUnique
()
:
void
{
$this
->
assertNotEquals
(
Random
::
generateHexHash
(),
Random
::
generateHexHash
()
);
}
#[DataProvider('provideRandomStringFormats')]
public
function
testRandomString
(
$format
,
$re
,
$len
)
:
void
{
$string
=
Random
::
generateString
(
$format
);
$this
->
assertEquals
(
$len
,
strlen
(
$format
));
$this
->
assertMatchesRegularExpression
(
$re
,
$string
);
}
public
function
testGenerateIdentifier
()
:
void
{
$identifier
=
Random
::
generateIdentifier
(
20
);
$this
->
assertEquals
(
27
,
strlen
(
$identifier
));
$this
->
assertMatchesRegularExpression
(
"/^[A-Z0-9
\-
_]*$/i"
,
$identifier
);
}
///
/// Data providers
///
public
static
function
provideRandomStringFormats
()
:
iterable
{
yield
[
"AAA111"
,
"/^[A-Z]{3}[0-9]{3}$/"
,
6
];
yield
[
"AAA123"
,
"/^[A-Z]{3}[0-9]{3}$/"
,
6
];
yield
[
"ABC123"
,
"/^[A-Z]{3}[0-9]{3}$/"
,
6
];
yield
[
""
,
"/^$/"
,
0
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 16, 13:10 (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3141436
Default Alt Text
RandomTest.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment