Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12740745
CodeVariableTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
CodeVariableTest.php
View Options
<?php
namespace
Keruald\OmniTools\Tests\Reflection
;
use
Keruald\OmniTools\Collections\Vector
;
use
Keruald\OmniTools\Reflection\CodeVariable
;
use
PHPUnit\Framework\Attributes\DataProvider
;
use
PHPUnit\Framework\TestCase
;
class
CodeVariableTest
extends
TestCase
{
public
function
testHasTypeWithObject
()
{
$object
=
new
Vector
;
$variable
=
CodeVariable
::
from
(
$object
);
$this
->
assertTrue
(
$variable
->
hasType
(
Vector
::
class
));
}
#[DataProvider('provideScalarsAndTypes')]
public
function
testHasTypeWithScalar
(
mixed
$scalar
,
string
$type
)
{
$variable
=
CodeVariable
::
from
(
$scalar
);
$this
->
assertTrue
(
$variable
->
hasType
(
$type
));
}
public
function
testGetTypeWithObject
()
{
$object
=
new
Vector
;
$variable
=
CodeVariable
::
from
(
$object
);
$this
->
assertEquals
(
Vector
::
class
,
$variable
->
getType
());
}
#[DataProvider('provideScalarsAndReturnedTypes')]
public
function
testGetTypeWithScalar
(
mixed
$scalar
,
string
$expected
)
{
$variable
=
CodeVariable
::
from
(
$scalar
);
$this
->
assertEquals
(
$expected
,
$variable
->
getType
());
}
#[DataProvider('provideScalars')]
public
function
testFromWithScalar
(
mixed
$scalar
)
{
$variable
=
CodeVariable
::
from
(
$scalar
);
$this
->
assertInstanceOf
(
CodeVariable
::
class
,
$variable
);
}
public
function
testFromWithObject
()
{
$object
=
new
Vector
;
$variable
=
CodeVariable
::
from
(
$object
);
$this
->
assertInstanceOf
(
CodeVariable
::
class
,
$variable
);
}
///
/// Data providers
///
public
static
function
provideScalars
()
:
iterable
{
yield
[
0
];
yield
[
""
];
yield
[
19
];
yield
[
"This is Sparta."
];
yield
[
true
];
yield
[
false
];
yield
[
null
];
}
public
static
function
provideScalarsAndTypes
()
:
iterable
{
yield
[
0
,
"integer"
];
yield
[
""
,
"string"
];
yield
[
19
,
"integer"
];
yield
[
"This is Sparta."
,
"string"
];
yield
[
true
,
"boolean"
];
yield
[
false
,
"boolean"
];
yield
[
null
,
"NULL"
];
}
public
static
function
provideScalarsAndReturnedTypes
()
:
iterable
{
yield
[
0
,
"int"
];
yield
[
""
,
"string"
];
yield
[
19
,
"int"
];
yield
[
"This is Sparta."
,
"string"
];
yield
[
true
,
"bool"
];
yield
[
false
,
"bool"
];
yield
[
null
,
"NULL"
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 16, 13:05 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3101459
Default Alt Text
CodeVariableTest.php (2 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment