Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F1136914
StringViewTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
StringViewTest.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Zed\Tests\Engines\API\Format
;
use
PHPUnit\Framework\Attributes\DataProvider
;
use
PHPUnit\Framework\TestCase
;
use
Zed\Engines\API\Format\StringView
;
use
stdClass
;
class
StringViewTest
extends
TestCase
{
///
/// Tests
///
#[DataProvider('provideScalarViews')]
public
function
testToString
(
$data
,
$expected
)
:
void
{
$this
->
assertEquals
(
$expected
,
StringView
::
toString
(
$data
));
}
#[DataProvider('provideScalarElements')]
public
function
testGetScalarElement
(
$data
,
$expected
)
:
void
{
$this
->
assertEquals
(
$expected
,
StringView
::
getScalarElement
(
$data
));
}
///
/// Data providers
///
public
static
function
provideScalarViews
()
:
iterable
{
// Lists
yield
[[],
"[]"
];
yield
[[
1
,
2
,
3
],
"[1, 2, 3]"
];
yield
[[
"foo"
,
"bar"
],
"[foo, bar]"
];
yield
[[
1
,
2
,
3
,
"foo"
,
"bar"
],
"[1, 2, 3, foo, bar]"
];
// Objects
$shipA
=
new
stdClass
;
$shipA
->
name
=
"Demios"
;
$shipA
->
id
=
400
;
yield
[
$shipA
,
"{name: Demios, id: 400}"
];
$shipB
=
new
stdClass
;
$shipB
->
name
=
"Demios"
;
$shipB
->
id
=
400
;
$shipB
->
manifest
=
[
12
,
50
,
97
];
yield
[
$shipB
,
"{name: Demios, id: 400, manifest: [12, 50, 97]}"
];
// List of objects
yield
[
[
$shipA
,
$shipB
],
"[{name: Demios, id: 400}, {name: Demios, id: 400, manifest: [12, 50, 97]}]"
,
];
// Scalar elements should be rendered as is
foreach
(
self
::
provideScalarElements
()
as
$testParameters
)
{
yield
$testParameters
;
}
}
public
static
function
provideScalarElements
()
:
iterable
{
yield
[
true
,
"true"
];
yield
[
false
,
"false"
];
yield
[
null
,
""
];
yield
[
42
,
"42"
];
yield
[
42.5
,
"42.5"
];
yield
[
""
,
""
];
yield
[
"foo"
,
"foo"
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Jul 11, 10:40 (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21319
Default Alt Text
StringViewTest.php (1 KB)
Attached To
rZED Zed
Event Timeline
Log In to Comment