Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7453031
JsonSchemaAssertionTraitTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
JsonSchemaAssertionTraitTest.php
View Options
<?php
use
PHPUnit\Framework\AssertionFailedError
;
/**
* @covers \JsonSchemaAssertionTrait
* @group MediaWikiIntegrationTestCaseTest
*/
class
JsonSchemaAssertionTraitTest
extends
MediaWikiUnitTestCase
{
use
JsonSchemaAssertionTrait
;
public
static
function
provideValidJson
()
{
$dir
=
__DIR__
.
'/json'
;
yield
[
"$dir/valid1.json"
,
"$dir/schema1.json"
];
yield
[
"$dir/valid2.json"
,
"$dir/schema2.json"
];
}
/**
* @dataProvider provideValidJson
*/
public
function
testAssertMatchesJsonSchema_valid
(
$dataFile
,
$schemaFile
)
{
$jsonString
=
file_get_contents
(
$dataFile
);
$dir
=
__DIR__
.
'/json'
;
$this
->
assertMatchesJsonSchema
(
$schemaFile
,
$jsonString
,
[
'https://www.mediawiki.org/test-schema/test1#'
=>
"$dir/schema1.json"
,
'https://www.mediawiki.org/test-schema/test2#'
=>
"$dir/schema2.json"
,
'https://www.mediawiki.org/test-schema/test3#'
=>
"$dir/schema3.json"
,
]
);
}
public
static
function
provideInvalidJson
()
{
$dir
=
__DIR__
.
'/json'
;
// T391586 - Malformed JSON doesn't pass linting while making releases, so
// to have a txt file extension.
foreach
(
glob
(
__DIR__
.
'/json/invalid*.{txt,json}'
,
GLOB_BRACE
)
as
$file
)
{
yield
$file
=>
[
$file
,
"$dir/schema1.json"
];
}
}
/**
* @dataProvider provideInvalidJson
*/
public
function
testAssertMatchesJsonSchema_invalid
(
$dataFile
,
$schemaFile
)
{
$dir
=
__DIR__
.
'/json'
;
$jsonString
=
file_get_contents
(
$dataFile
);
$this
->
expectException
(
AssertionFailedError
::
class
);
$this
->
assertMatchesJsonSchema
(
$schemaFile
,
$jsonString
,
[
'https://www.mediawiki.org/test-schema/test1#'
=>
"$dir/schema1.json"
,
'https://www.mediawiki.org/test-schema/test2#'
=>
"$dir/schema2.json"
,
'https://www.mediawiki.org/test-schema/test3#'
=>
"$dir/schema3.json"
,
]
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 22, 22:35 (2 d, 7 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
44/c0/1501f24b6a7dde116e77648962f1
Default Alt Text
JsonSchemaAssertionTraitTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment