Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F8321590
UUIDv1TimeStampTest.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
UUIDv1TimeStampTest.php
View Options
<?php
namespace
Keruald\OmniTools\Tests\DateTime
;
use
DateTime
;
use
InvalidArgumentException
;
use
Keruald\OmniTools\Collections\BitsVector
;
use
Keruald\OmniTools\DateTime\UUIDv1TimeStamp
;
use
PHPUnit\Framework\TestCase
;
class
UUIDv1TimeStampTest
extends
TestCase
{
public
function
testToUnixTime
()
{
$time
=
time
();
$actual
=
UUIDv1TimeStamp
::
fromUnixTime
(
$time
)->
toUnixTime
();
$this
->
assertEquals
(
$time
,
$actual
);
}
public
function
testFromBits
()
{
$bits
=
BitsVector
::
fromInteger
(
0x1EC9414C232AB00
)
->
shapeCapacity
(
60
);
$timestamp
=
UUIDv1TimeStamp
::
fromBits
(
$bits
);
$this
->
assertEquals
(
1645557742
,
$timestamp
->
toUnixTime
());
}
public
function
testFromUnixTime
()
{
$timestamp
=
UUIDv1TimeStamp
::
fromUnixTime
(
1645557742
);
$this
->
assertEquals
(
1645557742
,
$timestamp
->
toUnixTime
());
}
public
function
testFromDateTime
()
{
$time
=
DateTime
::
createFromFormat
(
"Y-m-d H:i:s"
,
'2022-02-22 19:22:22'
);
$timestamp
=
UUIDv1TimeStamp
::
fromDateTime
(
$time
);
$this
->
assertEquals
(
1645557742
,
$timestamp
->
toUnixTime
());
}
public
function
testFromBitsWhenCountIsWrong
()
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$bits
=
BitsVector
::
new
(
0
);
// too small, we need 60
UUIDv1TimeStamp
::
fromBits
(
$bits
);
}
public
function
testToBitsVector
()
{
$expected
=
BitsVector
::
fromInteger
(
0x1EC9414C232AB00
)
->
shapeCapacity
(
60
);
$timestamp
=
UUIDv1TimeStamp
::
fromUnixTime
(
1645557742
);
$this
->
assertEquals
(
$expected
->
toArray
(),
$timestamp
->
toBitsVector
()->
toArray
(),
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 13, 16:46 (17 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2565683
Default Alt Text
UUIDv1TimeStampTest.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment