DateTime::dateStringFormat Add new flag after show microtime to add microtime with . as a float type instead of string with ms Uids creation with alder32 and ripedm160 for 8 and 40 char long uids Support class with new method getCallerMethodList to return an array of all methods and not only one point reference
115 lines
2.2 KiB
PHP
115 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Test class for Create\Uids
|
|
* @coversDefaultClass \CoreLibs\Create\Uids
|
|
* @testdox \CoreLibs\Create\Uids method tests
|
|
*/
|
|
final class CoreLibsCreateUidsTest extends TestCase
|
|
{
|
|
public function uniqIdProvider(): array
|
|
{
|
|
return [
|
|
'md5 hash' => [
|
|
0 => 'md5',
|
|
1 => 32,
|
|
],
|
|
'sha256 hash' => [
|
|
0 => 'sha256',
|
|
1 => 64
|
|
],
|
|
'ripemd160 hash' => [
|
|
0 => 'ripemd160',
|
|
1 => 40
|
|
],
|
|
'adler32 hash' => [
|
|
0 => 'adler32',
|
|
1 => 8
|
|
],
|
|
'default hash not set' => [
|
|
0 => null,
|
|
1 => 64,
|
|
],
|
|
'invalid name' => [
|
|
0 => 'iamnotavalidhash',
|
|
1 => 64,
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* must match 7e78fe0d-59b8-4637-af7f-e88d221a7d1e
|
|
*
|
|
* @covers ::uuidv4
|
|
* @testdox uuidv4 check that return is matching regex [$_dataName]
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testUuidv4(): void
|
|
{
|
|
$uuid = \CoreLibs\Create\Uids::uuidv4();
|
|
$this->assertMatchesRegularExpression(
|
|
'/^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$/',
|
|
$uuid
|
|
);
|
|
// $this->assertStringMatchesFormat(
|
|
// '%4s%4s-%4s-%4s-%4s-%4s%4s%4s',
|
|
// $uuid
|
|
// );
|
|
}
|
|
|
|
/**
|
|
* Undocumented function
|
|
*
|
|
* @covers ::uniqId
|
|
* @dataProvider uniqIdProvider
|
|
* @testdox uniqId $input will be length $expected [$_dataName]
|
|
*
|
|
* @param string|null $input
|
|
* @param string $expected
|
|
* @return void
|
|
*/
|
|
public function testUniqId(?string $input, int $expected): void
|
|
{
|
|
if ($input === null) {
|
|
$this->assertEquals(
|
|
$expected,
|
|
strlen(\CoreLibs\Create\Uids::uniqId())
|
|
);
|
|
} else {
|
|
$this->assertEquals(
|
|
$expected,
|
|
strlen(\CoreLibs\Create\Uids::uniqId($input))
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Because we set a constant here, we can only run one test
|
|
* so we test invalid one to force check
|
|
*
|
|
* @covers ::uniqId
|
|
* @#dataProvider uniqIdProvider
|
|
* @testWith ["invalidhash", 64]
|
|
* @testdox uniqId use DEFAULT_HASH set $input with length $expected [$_dataName]
|
|
*
|
|
* @return void
|
|
*/
|
|
public function testUnidIdDefaultHash(string $input, int $expected): void
|
|
{
|
|
define('DEFAULT_HASH', $input);
|
|
$this->assertEquals(
|
|
$expected,
|
|
strlen(\CoreLibs\Create\Uids::uniqId())
|
|
);
|
|
}
|
|
}
|
|
|
|
// __END__
|