Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12944890
CallableElementTest.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
CallableElementTest.php
View Options
<?php
namespace
Keruald\OmniTools\Tests\Reflection
;
use
InvalidArgumentException
;
use
Keruald\OmniTools\Reflection\CallableElement
;
use
PHPUnit\Framework\TestCase
;
class
CallableElementTest
extends
TestCase
{
private
CallableElement
$closure
;
protected
function
setUp
()
:
void
{
$fn
=
fn
(
int
$a
,
int
$b
)
:
int
=>
$a
+
$b
;
$this
->
closure
=
new
CallableElement
(
$fn
);
}
public
function
testCountArguments
()
:
void
{
$this
->
assertEquals
(
2
,
$this
->
closure
->
countArguments
());
}
public
function
testCountArgumentsWhenThereIsNone
()
:
void
{
$fn
=
fn
()
=>
null
;
$closure
=
new
CallableElement
(
$fn
);
$this
->
assertEquals
(
0
,
$closure
->
countArguments
());
}
public
function
testHasReturnType
()
:
void
{
$this
->
assertTrue
(
$this
->
closure
->
hasReturnType
(
"int"
));
$this
->
assertFalse
(
$this
->
closure
->
hasReturnType
(
"quux"
));
}
public
function
testHasReturnTypeWhenThereIsNone
()
:
void
{
// Closure without any explicit return type
$fn
=
fn
(
int
$a
,
int
$b
)
=>
$a
+
$b
;
$closure
=
new
CallableElement
(
$fn
);
$this
->
assertFalse
(
$closure
->
hasReturnType
(
"int"
));
}
public
function
testGetReturnType
()
:
void
{
$this
->
assertEquals
(
"int"
,
$this
->
closure
->
getReturnType
());
}
public
function
testGetReturnTypeWhenThereIsNone
()
:
void
{
// Closure without any explicit return type
$fn
=
fn
(
int
$a
,
int
$b
)
=>
$a
+
$b
;
$closure
=
new
CallableElement
(
$fn
);
$this
->
expectException
(
InvalidArgumentException
::
class
);
$closure
->
getReturnType
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Nov 18, 17:23 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3119773
Default Alt Text
CallableElementTest.php (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment