Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4155543
RootElementMatcher.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
RootElementMatcher.php
View Options
<?php
namespace
WMDE\HamcrestHtml
;
use
DOMDocument
;
use
Hamcrest\Description
;
use
Hamcrest\Matcher
;
use
Hamcrest\TypeSafeDiagnosingMatcher
;
class
RootElementMatcher
extends
TypeSafeDiagnosingMatcher
{
/**
* @var Matcher|null
*/
private
$tagMatcher
;
/**
* @param Matcher|null $tagMatcher
*
* @return static
*/
public
static
function
havingRootElement
(
?
Matcher
$tagMatcher
=
null
)
{
return
new
static
(
$tagMatcher
);
}
public
function
__construct
(
?
Matcher
$tagMatcher
=
null
)
{
parent
::
__construct
(
self
::
TYPE_OBJECT
,
DOMDocument
::
class
);
$this
->
tagMatcher
=
$tagMatcher
;
}
public
function
describeTo
(
Description
$description
)
{
$description
->
appendText
(
'having root element '
);
if
(
$this
->
tagMatcher
)
{
$description
->
appendDescriptionOf
(
$this
->
tagMatcher
);
}
}
/**
* @param DOMDocument $item
* @param Description $mismatchDescription
*
* @return bool
*/
protected
function
matchesSafelyWithDiagnosticDescription
(
$item
,
Description
$mismatchDescription
)
{
$DOMNodeList
=
$item
->
documentElement
->
childNodes
->
item
(
0
)->
childNodes
;
if
(
$DOMNodeList
->
length
>
1
)
{
// TODO Test this description
$mismatchDescription
->
appendText
(
'having '
.
$DOMNodeList
->
length
.
' root elements '
);
return
false
;
}
$target
=
$DOMNodeList
->
item
(
0
);
if
(
!
$target
)
{
// TODO Reproduce?
$mismatchDescription
->
appendText
(
'having no root elements '
);
return
false
;
}
if
(
$this
->
tagMatcher
)
{
$mismatchDescription
->
appendText
(
'root element '
);
$this
->
tagMatcher
->
describeMismatch
(
$target
,
$mismatchDescription
);
return
$this
->
tagMatcher
->
matches
(
$target
);
}
return
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 19 2026, 21:48 (7 w, 6 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f8/b4/7ffb10c2ddef416470c68cb6dca4
Default Alt Text
RootElementMatcher.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment