8
8
9
9
namespace SteveGrunwell \PHPUnit_Markup_Assertions ;
10
10
11
- use DOMDocument ;
12
- use Laminas \Dom \Document ;
13
- use Laminas \Dom \Document \Query ;
14
11
use PHPUnit \Framework \RiskyTestError ;
12
+ use Symfony \Component \DomCrawler \Crawler ;
15
13
16
14
trait MarkupAssertionsTrait
17
15
{
@@ -75,10 +73,11 @@ public function assertSelectorCount($count, $selector, $markup = '', $message =
75
73
*
76
74
* @since 1.0.0
77
75
*
78
- * @param array $attributes An array of HTML attributes that should be found on the element.
79
- * @param string $markup The output that should contain an element with the
80
- * provided $attributes.
81
- * @param string $message A message to display if the assertion fails.
76
+ * @param array<string, scalar> $attributes An array of HTML attributes that should be found
77
+ * on the element.
78
+ * @param string $markup The output that should contain an element with the
79
+ * provided $attributes.
80
+ * @param string $message A message to display if the assertion fails.
82
81
*
83
82
* @return void
84
83
*/
@@ -96,10 +95,11 @@ public function assertHasElementWithAttributes($attributes = [], $markup = '', $
96
95
*
97
96
* @since 1.0.0
98
97
*
99
- * @param array $attributes An array of HTML attributes that should be found on the element.
100
- * @param string $markup The output that should not contain an element with the
101
- * provided $attributes.
102
- * @param string $message A message to display if the assertion fails.
98
+ * @param array<string, scalar> $attributes An array of HTML attributes that should be found
99
+ * on the element.
100
+ * @param string $markup The output that should not contain an element with
101
+ * the provided $attributes.
102
+ * @param string $message A message to display if the assertion fails.
103
103
*
104
104
* @return void
105
105
*/
@@ -220,15 +220,13 @@ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $m
220
220
* @param string $markup The HTML for the DOMDocument.
221
221
* @param string $query The DOM selector query.
222
222
*
223
- * @return \Laminas\Dom\Document\NodeList
223
+ * @return Crawler
224
224
*/
225
- protected function executeDomQuery ($ markup , $ query )
225
+ private function executeDomQuery ($ markup , $ query )
226
226
{
227
- return Query::execute (
228
- $ query ,
229
- new Document ('<?xml encoding="UTF-8"> ' . $ markup , Document::DOC_HTML , 'UTF-8 ' ),
230
- Query::TYPE_CSS
231
- );
227
+ $ dom = new Crawler ($ markup );
228
+
229
+ return $ dom ->filter ($ query );
232
230
}
233
231
234
232
/**
@@ -238,11 +236,11 @@ protected function executeDomQuery($markup, $query)
238
236
*
239
237
* @throws RiskyTestError When the $attributes array is empty.
240
238
*
241
- * @param array $attributes HTML attributes and their values.
239
+ * @param array<string, scalar> $attributes HTML attributes and their values.
242
240
*
243
241
* @return string A XPath attribute query selector.
244
242
*/
245
- protected function flattenAttributeArray (array $ attributes )
243
+ private function flattenAttributeArray (array $ attributes )
246
244
{
247
245
if (empty ($ attributes )) {
248
246
throw new RiskyTestError ('Attributes array is empty. ' );
@@ -270,14 +268,14 @@ protected function flattenAttributeArray(array $attributes)
270
268
*
271
269
* @return string The concatenated innerHTML of any matched selectors.
272
270
*/
273
- protected function getInnerHtmlOfMatchedElements ($ markup , $ query )
271
+ private function getInnerHtmlOfMatchedElements ($ markup , $ query )
274
272
{
275
273
$ results = $ this ->executeDomQuery ($ markup , $ query );
276
274
$ contents = [];
277
275
278
276
// Loop through results and collect their innerHTML values.
279
277
foreach ($ results as $ result ) {
280
- $ document = new DOMDocument ();
278
+ $ document = new \ DOMDocument ();
281
279
$ document ->appendChild ($ document ->importNode ($ result ->firstChild , true ));
282
280
283
281
$ contents [] = trim (html_entity_decode ($ document ->saveHTML ()));
0 commit comments