88
99namespace SteveGrunwell \PHPUnit_Markup_Assertions ;
1010
11- use DOMDocument ;
12- use Laminas \Dom \Document ;
13- use Laminas \Dom \Document \Query ;
1411use PHPUnit \Framework \RiskyTestError ;
12+ use Symfony \Component \DomCrawler \Crawler ;
1513
1614trait MarkupAssertionsTrait
1715{
@@ -75,10 +73,11 @@ public function assertSelectorCount($count, $selector, $markup = '', $message =
7573 *
7674 * @since 1.0.0
7775 *
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.
8281 *
8382 * @return void
8483 */
@@ -96,10 +95,11 @@ public function assertHasElementWithAttributes($attributes = [], $markup = '', $
9695 *
9796 * @since 1.0.0
9897 *
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.
103103 *
104104 * @return void
105105 */
@@ -220,15 +220,13 @@ public function assertElementNotRegExp($regexp, $selector = '', $markup = '', $m
220220 * @param string $markup The HTML for the DOMDocument.
221221 * @param string $query The DOM selector query.
222222 *
223- * @return \Laminas\Dom\Document\NodeList
223+ * @return Crawler
224224 */
225- protected function executeDomQuery ($ markup , $ query )
225+ private function executeDomQuery ($ markup , $ query )
226226 {
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 );
232230 }
233231
234232 /**
@@ -238,11 +236,11 @@ protected function executeDomQuery($markup, $query)
238236 *
239237 * @throws RiskyTestError When the $attributes array is empty.
240238 *
241- * @param array $attributes HTML attributes and their values.
239+ * @param array<string, scalar> $attributes HTML attributes and their values.
242240 *
243241 * @return string A XPath attribute query selector.
244242 */
245- protected function flattenAttributeArray (array $ attributes )
243+ private function flattenAttributeArray (array $ attributes )
246244 {
247245 if (empty ($ attributes )) {
248246 throw new RiskyTestError ('Attributes array is empty. ' );
@@ -270,14 +268,14 @@ protected function flattenAttributeArray(array $attributes)
270268 *
271269 * @return string The concatenated innerHTML of any matched selectors.
272270 */
273- protected function getInnerHtmlOfMatchedElements ($ markup , $ query )
271+ private function getInnerHtmlOfMatchedElements ($ markup , $ query )
274272 {
275273 $ results = $ this ->executeDomQuery ($ markup , $ query );
276274 $ contents = [];
277275
278276 // Loop through results and collect their innerHTML values.
279277 foreach ($ results as $ result ) {
280- $ document = new DOMDocument ();
278+ $ document = new \ DOMDocument ();
281279 $ document ->appendChild ($ document ->importNode ($ result ->firstChild , true ));
282280
283281 $ contents [] = trim (html_entity_decode ($ document ->saveHTML ()));
0 commit comments