2525use Symfony \Component \DomCrawler \Crawler ;
2626use Symfony \Component \DomCrawler \Field \ChoiceFormField ;
2727use Symfony \Component \DomCrawler \Field \FileFormField ;
28+ use Symfony \Component \DomCrawler \Field \FormField ;
2829use Symfony \Component \DomCrawler \Field \InputFormField ;
2930use Symfony \Component \DomCrawler \Field \TextareaFormField ;
3031use Symfony \Component \DomCrawler \Form ;
@@ -57,7 +58,7 @@ class InnerBrowser extends Module implements Web, PageSourceSaver, ElementLocato
5758
5859 protected $ defaultCookieParameters = ['expires ' => null , 'path ' => '/ ' , 'domain ' => '' , 'secure ' => false ];
5960
60- protected $ internalDomains = null ;
61+ protected $ internalDomains ;
6162
6263 private $ baseUrl ;
6364
@@ -73,7 +74,7 @@ public function _failed(TestInterface $test, $fail)
7374 return ;
7475 }
7576 $ filename = preg_replace ('~\W~ ' , '. ' , Descriptor::getTestSignatureUnique ($ test ));
76-
77+
7778 $ extensions = [
7879 'application/json ' => 'json ' ,
7980 'text/xml ' => 'xml ' ,
@@ -86,12 +87,12 @@ public function _failed(TestInterface $test, $fail)
8687 } catch (BadMethodCallException $ e ) {
8788 $ internalResponse = false ;
8889 }
89-
90+
9091 $ responseContentType = $ internalResponse ? $ internalResponse ->getHeader ('content-type ' ) : '' ;
9192 list ($ responseMimeType ) = explode ('; ' , $ responseContentType );
92-
93+
9394 $ extension = isset ($ extensions [$ responseMimeType ]) ? $ extensions [$ responseMimeType ] : 'html ' ;
94-
95+
9596 $ filename = mb_strcut ($ filename , 0 , 244 , 'utf-8 ' ) . '.fail. ' . $ extension ;
9697 $ this ->_savePageSource ($ report = codecept_output_dir () . $ filename );
9798 $ test ->getMetadata ()->addReport ('html ' , $ report );
@@ -444,7 +445,9 @@ protected function clickByLocator($link)
444445 if ($ tag === 'a ' ) {
445446 $ this ->openHrefFromDomNode ($ node );
446447 return true ;
447- } elseif (in_array ($ tag , ['input ' , 'button ' ]) && in_array ($ type , ['submit ' , 'image ' ])) {
448+ }
449+
450+ if (in_array ($ tag , ['input ' , 'button ' ]) && in_array ($ type , ['submit ' , 'image ' ])) {
448451 return $ this ->clickButton ($ node );
449452 }
450453 }
@@ -490,15 +493,15 @@ private function clickButton(\DOMNode $node)
490493 $ formParams
491494 );
492495 return true ;
493- } else {
494- // Check if the button is inside an anchor.
495- $ currentNode = $ node ;
496- while ( $ currentNode-> parentNode !== null ) {
497- $ currentNode = $ currentNode ->parentNode ;
498- if ( $ currentNode ->nodeName === ' a ' ) {
499- $ this -> openHrefFromDomNode ($ currentNode);
500- return true ;
501- }
496+ }
497+
498+ // Check if the button is inside an anchor.
499+ $ currentNode = $ node ;
500+ while ( $ currentNode ->parentNode !== null ) {
501+ $ currentNode = $ currentNode ->parentNode ;
502+ if ($ currentNode-> nodeName === ' a ' ) {
503+ $ this -> openHrefFromDomNode ( $ currentNode ) ;
504+ return true ;
502505 }
503506 }
504507 throw new TestRuntimeException ('Button is not inside a link or a form ' );
@@ -523,7 +526,7 @@ private function retrieveBaseUrl()
523526 if (count ($ baseHref ) > 0 ) {
524527 $ baseUrl = $ baseHref ->getNode (0 )->getAttribute ('href ' );
525528 }
526- if ($ baseUrl == '' ) {
529+ if ($ baseUrl === '' ) {
527530 $ baseUrl = $ this ->_getCurrentUri ();
528531 }
529532 return $ this ->getAbsoluteUrlFor ($ baseUrl );
@@ -579,10 +582,8 @@ public function seeLink($text, $url = null)
579582 public function dontSeeLink ($ text , $ url = '' )
580583 {
581584 $ crawler = $ this ->getCrawler ()->selectLink ($ text );
582- if (!$ url ) {
583- if ($ crawler ->count () > 0 ) {
584- $ this ->fail ("Link containing text ' $ text' was found in page " . $ this ->_getCurrentUri ());
585- }
585+ if (!$ url && $ crawler ->count () > 0 ) {
586+ $ this ->fail ("Link containing text ' $ text' was found in page " . $ this ->_getCurrentUri ());
586587 }
587588 $ crawler = $ crawler ->filterXPath (
588589 sprintf ('.//a[substring(@href, string-length(@href) - string-length(%1$s) + 1)=%1$s] ' ,
@@ -624,12 +625,12 @@ public function dontSeeCurrentUrlEquals($uri)
624625
625626 public function seeCurrentUrlMatches ($ uri )
626627 {
627- \ PHPUnit \ Framework \Assert:: assertRegExp ($ uri , $ this ->_getCurrentUri ());
628+ $ this -> assertRegExp ($ uri , $ this ->_getCurrentUri ());
628629 }
629630
630631 public function dontSeeCurrentUrlMatches ($ uri )
631632 {
632- \ PHPUnit \ Framework \Assert:: assertNotRegExp ($ uri , $ this ->_getCurrentUri ());
633+ $ this -> assertNotRegExp ($ uri , $ this ->_getCurrentUri ());
633634 }
634635
635636 public function grabFromCurrentUrl ($ uri = null )
@@ -694,9 +695,7 @@ protected function proceedSeeInFormFields($formSelector, array $params, $assertN
694695 $ this ->pushFormField ($ fields , $ form , $ name , $ values );
695696 }
696697
697- foreach ($ fields as $ element ) {
698- list ($ field , $ values ) = $ element ;
699-
698+ foreach ($ fields as list ($ field , $ values )) {
700699 if (!is_array ($ values )) {
701700 $ values = [$ values ];
702701 }
@@ -805,7 +804,8 @@ protected function getValueAndTextFromField(Crawler $nodes)
805804 */
806805 protected function getInputValue ($ input )
807806 {
808- if ($ input ->attr ('type ' ) == 'checkbox ' or $ input ->attr ('type ' ) == 'radio ' ) {
807+ $ inputType = $ input ->attr ('type ' );
808+ if ($ inputType === 'checkbox ' || $ inputType === 'radio ' ) {
809809 $ values = [];
810810
811811 foreach ($ input ->filter (':checked ' ) as $ checkbox ) {
@@ -854,10 +854,12 @@ protected function setCheckboxBoolValues(Crawler $form, array $params)
854854 foreach ($ checkboxes as $ box ) {
855855 $ fieldName = $ this ->getSubmissionFormFieldName ($ box ->getAttribute ('name ' ));
856856 $ pos = (!isset ($ chFoundByName [$ fieldName ])) ? 0 : $ chFoundByName [$ fieldName ];
857- $ skip = ( !isset ($ params [$ fieldName ]) )
857+ $ skip = !isset ($ params [$ fieldName ])
858858 || (!is_array ($ params [$ fieldName ]) && !is_bool ($ params [$ fieldName ]))
859- || (is_array ($ params [$ fieldName ]) && $ pos >= count ($ params [$ fieldName ])
860- || (is_array ($ params [$ fieldName ]) && !is_bool ($ params [$ fieldName ][$ pos ])));
859+ || (is_array ($ params [$ fieldName ]) &&
860+ ($ pos >= count ($ params [$ fieldName ]) || !is_bool ($ params [$ fieldName ][$ pos ]))
861+ );
862+
861863 if ($ skip ) {
862864 continue ;
863865 }
@@ -914,7 +916,7 @@ protected function proceedSubmitForm(Crawler $frmCrawl, array $params, $button =
914916 if (!$ url ) {
915917 $ url = $ this ->getFormUrl ($ frmCrawl );
916918 }
917-
919+
918920 if (strcasecmp ($ form ->getMethod (), 'GET ' ) === 0 ) {
919921 $ url = Uri::mergeUrls ($ url , '? ' . http_build_query ($ requestParams ));
920922 }
@@ -957,7 +959,7 @@ public function submitForm($selector, array $params, $button = null)
957959 protected function getAbsoluteUrlFor ($ uri )
958960 {
959961 $ currentUrl = $ this ->getRunningClient ()->getHistory ()->current ()->getUri ();
960- if (empty ($ uri ) || $ uri[ 0 ] === ' # ' ) {
962+ if (empty ($ uri ) || strpos ( $ uri, ' # ' ) === 0 ) {
961963 return $ currentUrl ;
962964 }
963965 return Uri::mergeUrls ($ currentUrl , $ uri );
@@ -1052,7 +1054,7 @@ protected function getFormValuesFor(Form $form)
10521054 $ values = [];
10531055 $ fields = $ form ->all ();
10541056 foreach ($ fields as $ field ) {
1055- if ($ field ->isDisabled () || !$ field ->hasValue () || $ field instanceof FileFormField ) {
1057+ if ($ field instanceof FileFormField || $ field ->isDisabled () || !$ field ->hasValue ()) {
10561058 continue ;
10571059 }
10581060 $ fieldName = $ this ->getSubmissionFormFieldName ($ field ->getName ());
@@ -1074,13 +1076,13 @@ public function fillField($field, $value)
10741076 $ form = $ this ->getFormFor ($ input );
10751077 $ name = $ input ->attr ('name ' );
10761078
1077- $ dynamicField = $ input ->getNode (0 )->tagName == 'textarea '
1079+ $ dynamicField = $ input ->getNode (0 )->tagName === 'textarea '
10781080 ? new TextareaFormField ($ input ->getNode (0 ))
10791081 : new InputFormField ($ input ->getNode (0 ));
10801082 $ formField = $ this ->matchFormField ($ name , $ form , $ dynamicField );
10811083 $ formField ->setValue ($ value );
10821084 $ input ->getNode (0 )->setAttribute ('value ' , htmlspecialchars ($ value ));
1083- if ($ input ->getNode (0 )->tagName == 'textarea ' ) {
1085+ if ($ input ->getNode (0 )->tagName === 'textarea ' ) {
10841086 $ input ->getNode (0 )->nodeValue = htmlspecialchars ($ value );
10851087 }
10861088 }
@@ -1327,7 +1329,7 @@ protected function debugResponse($url)
13271329 public function makeHtmlSnapshot ($ name = null )
13281330 {
13291331 if (empty ($ name )) {
1330- $ name = uniqid (date ("Y-m-d_H-i-s_ " ));
1332+ $ name = uniqid (date ("Y-m-d_H-i-s_ " ), true );
13311333 }
13321334 $ debugDir = codecept_output_dir () . 'debug ' ;
13331335 if (!is_dir ($ debugDir )) {
@@ -1410,8 +1412,8 @@ protected function filterByAttributes(Crawler $nodes, array $attributes)
14101412 {
14111413 foreach ($ attributes as $ attr => $ val ) {
14121414 $ nodes = $ nodes ->reduce (
1413- function (Crawler $ node ) use ($ attr , $ val ) {
1414- return $ node ->attr ($ attr ) == $ val ;
1415+ static function (Crawler $ node ) use ($ attr , $ val ) {
1416+ return $ node ->attr ($ attr ) === $ val ;
14151417 }
14161418 );
14171419 }
@@ -1610,7 +1612,7 @@ public function seeOptionIsSelected($selector, $optionText)
16101612 $ selected = $ this ->matchSelectedOption ($ selector );
16111613 $ this ->assertDomContains ($ selected , 'selected option ' );
16121614 //If element is radio then we need to check value
1613- $ value = $ selected ->getNode (0 )->tagName == 'option '
1615+ $ value = $ selected ->getNode (0 )->tagName === 'option '
16141616 ? $ selected ->text ()
16151617 : $ selected ->getNode (0 )->getAttribute ('value ' );
16161618 $ this ->assertEquals ($ optionText , $ value );
@@ -1624,7 +1626,7 @@ public function dontSeeOptionIsSelected($selector, $optionText)
16241626 return ;
16251627 }
16261628 //If element is radio then we need to check value
1627- $ value = $ selected ->getNode (0 )->tagName == 'option '
1629+ $ value = $ selected ->getNode (0 )->tagName === 'option '
16281630 ? $ selected ->text ()
16291631 : $ selected ->getNode (0 )->getAttribute ('value ' );
16301632 $ this ->assertNotEquals ($ optionText , $ value );
@@ -1634,7 +1636,7 @@ protected function matchSelectedOption($select)
16341636 {
16351637 $ nodes = $ this ->getFieldsByLabelOrCss ($ select );
16361638 $ selectedOptions = $ nodes ->filter ('option[selected],input:checked ' );
1637- if ($ selectedOptions ->count () == 0 ) {
1639+ if ($ selectedOptions ->count () === 0 ) {
16381640 $ selectedOptions = $ nodes ->filter ('option,input ' )->first ();
16391641 }
16401642 return $ selectedOptions ;
@@ -1821,7 +1823,7 @@ protected function assertPageSourceNotContains($needle, $message = '')
18211823 */
18221824 protected function matchFormField ($ name , $ form , $ dynamicField )
18231825 {
1824- if (substr ($ name , -2 ) != '[] ' ) {
1826+ if (substr ($ name , -2 ) !== '[] ' ) {
18251827 return $ form [$ name ];
18261828 }
18271829 $ name = substr ($ name , 0 , -2 );
@@ -1884,14 +1886,16 @@ protected function getFormPhpValues($requestParams)
18841886
18851887 /**
18861888 * @param $result
1889+ * @param $maxRedirects
1890+ * @param $redirectCount
18871891 * @return mixed
18881892 */
18891893 protected function redirectIfNecessary ($ result , $ maxRedirects , $ redirectCount )
18901894 {
18911895 $ locationHeader = $ this ->client ->getInternalResponse ()->getHeader ('Location ' );
18921896 $ statusCode = $ this ->getResponseStatusCode ();
18931897 if ($ locationHeader && $ statusCode >= 300 && $ statusCode < 400 ) {
1894- if ($ redirectCount == $ maxRedirects ) {
1898+ if ($ redirectCount === $ maxRedirects ) {
18951899 throw new \LogicException (sprintf (
18961900 'The maximum number (%d) of redirections was reached. ' ,
18971901 $ maxRedirects
@@ -2042,6 +2046,7 @@ protected function getNormalizedResponseContent()
20422046 * ```php
20432047 * $I->setServerParameters([]);
20442048 * ```
2049+ * @param array $params
20452050 */
20462051 public function setServerParameters (array $ params )
20472052 {
@@ -2054,6 +2059,8 @@ public function setServerParameters(array $params)
20542059 * ```php
20552060 * $I->haveServerParameter('name', 'value');
20562061 * ```
2062+ * @param $name
2063+ * @param $value
20572064 */
20582065 public function haveServerParameter ($ name , $ value )
20592066 {
0 commit comments