Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793912
DateStampTest.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
DateStampTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Tests\DateTime
;
use
Keruald\OmniTools\DateTime\DateStamp
;
use
PHPUnit\Framework\TestCase
;
use
DateTime
;
class
DateStampTest
extends
TestCase
{
///
/// Private members
///
/**
* @var DateStamp
*/
private
$dateStamp
;
///
/// Fixtures
///
protected
function
setUp
()
:
void
{
$this
->
dateStamp
=
new
DateStamp
(
2010
,
11
,
25
);
// 25 November 2010
}
///
/// Tests
///
public
function
testToUnixTime
()
:
void
{
$this
->
assertEquals
(
1290643200
,
$this
->
dateStamp
->
toUnixTime
());
}
public
function
testToDateTime
()
:
void
{
$expectedDateTime
=
new
DateTime
(
"2010-11-25"
);
$this
->
assertEquals
(
$expectedDateTime
,
$this
->
dateStamp
->
toDateTime
());
}
public
function
testToShortString
()
:
void
{
$this
->
assertEquals
(
"20101125"
,
$this
->
dateStamp
->
toShortString
());
}
public
function
testToString
()
:
void
{
$this
->
assertEquals
(
"2010-11-25"
,
(
string
)
$this
->
dateStamp
);
}
public
function
testFromUnixTime
()
:
void
{
$this
->
assertEquals
(
$this
->
dateStamp
,
DateStamp
::
fromUnixTime
(
1290643200
)
);
}
public
function
testParse
()
:
void
{
$this
->
assertEquals
(
$this
->
dateStamp
,
DateStamp
::
parse
(
"2010-11-25"
)
);
$this
->
assertEquals
(
$this
->
dateStamp
,
DateStamp
::
parse
(
"20101125"
)
);
}
/**
* @dataProvider provideInvalidDateStamps
*/
public
function
testParseWithInvalidFormat
(
$dateStamp
)
:
void
{
$this
->
expectException
(
"InvalidArgumentException"
);
DateStamp
::
parse
(
$dateStamp
);
}
///
/// Data provider
///
public
function
provideInvalidDateStamps
()
:
iterable
{
yield
[
"10-11-25"
];
yield
[
"2010-41-25"
];
yield
[
"2010-11-99"
];
yield
[
"20104125"
];
yield
[
"20101199"
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 22:47 (23 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2437261
Default Alt Text
DateStampTest.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment