idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
41,600
private static function fsCaseStrCmp ( $ str1 , $ str2 , $ dirSep = DIRECTORY_SEPARATOR ) { $ cmpFn = self :: isWindows ( $ dirSep ) ? 'strcasecmp' : 'strcmp' ; return $ cmpFn ( $ str1 , $ str2 ) ; }
FileSystem Case String Compare compare two strings with the filesystem s case - sensitiveness
41,601
protected function load ( ) { if ( ! file_exists ( $ this -> getFileName ( ) ) ) { return ; } $ this -> dataSet = json_decode ( file_get_contents ( $ this -> getFileName ( ) ) ) ; if ( ! $ this -> dataSet ) { throw new ContentNotFound ( "Loaded snapshot is empty" ) ; } }
Loads data set from file .
41,602
protected function getFileName ( ) { if ( ! $ this -> fileName ) { $ this -> fileName = preg_replace ( '/\W/' , '.' , get_class ( $ this ) ) . '.json' ; } return codecept_data_dir ( ) . $ this -> fileName ; }
If no filename is defined generates one from class name
41,603
public function assert ( ) { $ data = $ this -> fetchData ( ) ; if ( ! $ data ) { throw new ContentNotFound ( "Fetched snapshot is empty." ) ; } $ this -> load ( ) ; if ( ! $ this -> dataSet ) { $ this -> printDebug ( 'Snapshot is empty. Updating snapshot...' ) ; $ this -> dataSet = $ data ; $ this -> save ( ) ; return...
Performs assertion for data sets
41,604
public function _restart ( $ config = [ ] ) { $ this -> webDriver -> quit ( ) ; if ( ! empty ( $ config ) ) { $ this -> _reconfigure ( $ config ) ; } $ this -> _initializeSession ( ) ; }
Restarts a web browser . Can be used with _reconfigure to open browser with different configuration
41,605
public function debugWebDriverLogs ( TestInterface $ test = null ) { if ( ! isset ( $ this -> webDriver ) ) { $ this -> debug ( 'WebDriver::debugWebDriverLogs method has been called when webDriver is not set' ) ; return ; } try { $ logs = $ this -> webDriver -> manage ( ) -> getAvailableLogTypes ( ) ; foreach ( $ logs ...
Print out latest Selenium Logs in debug mode
41,606
protected function logJSErrors ( ScenarioDriven $ test , array $ browserLogEntries ) { foreach ( $ browserLogEntries as $ logEntry ) { if ( true === isset ( $ logEntry [ 'level' ] ) && true === isset ( $ logEntry [ 'message' ] ) && $ this -> isJSError ( $ logEntry [ 'level' ] , $ logEntry [ 'message' ] ) ) { $ time = d...
Logs JavaScript errors as comments .
41,607
protected function isJSError ( $ logEntryLevel , $ message ) { return ( ( $ this -> isPhantom ( ) && $ logEntryLevel != 'INFO' ) || $ logEntryLevel === 'SEVERE' ) && strpos ( $ message , 'ERR_PROXY_CONNECTION_FAILED' ) === false ; }
Determines if the log entry is an error . The decision is made depending on browser and log - level .
41,608
public function _getCurrentUri ( ) { $ url = $ this -> webDriver -> getCurrentURL ( ) ; if ( $ url == 'about:blank' || strpos ( $ url , 'data:' ) === 0 ) { throw new ModuleException ( $ this , 'Current url is blank, no page was opened' ) ; } return Uri :: retrieveUri ( $ url ) ; }
Uri of currently opened page .
41,609
public function _savePageSource ( $ filename ) { if ( ! isset ( $ this -> webDriver ) ) { $ this -> debug ( 'WebDriver::_savePageSource method has been called when webDriver is not set' ) ; return ; } try { file_put_contents ( $ filename , $ this -> webDriver -> getPageSource ( ) ) ; } catch ( \ Exception $ e ) { $ thi...
Saves HTML source of a page to a file
41,610
public function resizeWindow ( $ width , $ height ) { $ this -> webDriver -> manage ( ) -> window ( ) -> setSize ( new WebDriverDimension ( $ width , $ height ) ) ; }
Resize the current window .
41,611
public function seeInPageSource ( $ text ) { $ this -> assertThat ( $ this -> webDriver -> getPageSource ( ) , new PageConstraint ( $ text , $ this -> _getCurrentUri ( ) ) , '' ) ; }
Checks that the page source contains the given string .
41,612
public function dontSeeInPageSource ( $ text ) { $ this -> assertThatItsNot ( $ this -> webDriver -> getPageSource ( ) , new PageConstraint ( $ text , $ this -> _getCurrentUri ( ) ) , '' ) ; }
Checks that the page source doesn t contain the given string .
41,613
public function _findClickable ( $ page , $ link ) { if ( is_array ( $ link ) or ( $ link instanceof WebDriverBy ) ) { return $ this -> matchFirstOrFail ( $ page , $ link ) ; } if ( Locator :: isPrecise ( $ link ) ) { return $ this -> matchFirstOrFail ( $ page , $ link ) ; } $ locator = Crawler :: xpathLiteral ( trim (...
Locates a clickable element .
41,614
protected function pushFormField ( & $ els , $ form , $ name , $ values ) { $ el = $ form -> findElements ( WebDriverBy :: name ( $ name ) ) ; if ( $ el ) { $ els [ ] = [ $ el , $ values ] ; } elseif ( is_array ( $ values ) ) { foreach ( $ values as $ key => $ value ) { $ this -> pushFormField ( $ els , $ form , "{$nam...
Map an array element passed to seeInFormFields to its corresponding WebDriver element recursing through array values if the field is not found .
41,615
public function _initializeSession ( ) { try { $ this -> sessions [ ] = $ this -> webDriver ; $ this -> webDriver = RemoteWebDriver :: create ( $ this -> wdHost , $ this -> capabilities , $ this -> connectionTimeoutInMs , $ this -> requestTimeoutInMs , $ this -> httpProxy , $ this -> httpProxyPort ) ; if ( ! is_null ( ...
Manually starts a new browser session .
41,616
public function _closeSession ( $ webDriver = null ) { if ( ! $ webDriver and $ this -> webDriver ) { $ webDriver = $ this -> webDriver ; } if ( ! $ webDriver ) { return ; } try { $ webDriver -> quit ( ) ; unset ( $ webDriver ) ; } catch ( UnknownServerException $ e ) { } }
Manually closes current WebDriver session .
41,617
public function unselectOption ( $ select , $ option ) { $ el = $ this -> findField ( $ select ) ; $ wdSelect = new WebDriverSelect ( $ el ) ; if ( ! is_array ( $ option ) ) { $ option = [ $ option ] ; } $ matched = false ; foreach ( $ option as $ opt ) { try { $ wdSelect -> deselectByVisibleText ( $ opt ) ; $ matched ...
Unselect an option in the given select box .
41,618
protected function getVisibleText ( ) { if ( $ this -> getBaseElement ( ) instanceof RemoteWebElement ) { return $ this -> getBaseElement ( ) -> getText ( ) ; } $ els = $ this -> getBaseElement ( ) -> findElements ( WebDriverBy :: cssSelector ( 'body' ) ) ; if ( isset ( $ els [ 0 ] ) ) { return $ els [ 0 ] -> getText (...
Grabs all visible text from the current page .
41,619
public function seeElementInDOM ( $ selector , $ attributes = [ ] ) { $ this -> enableImplicitWait ( ) ; $ els = $ this -> match ( $ this -> getBaseElement ( ) , $ selector ) ; $ els = $ this -> filterByAttributes ( $ els , $ attributes ) ; $ this -> disableImplicitWait ( ) ; $ this -> assertNotEmpty ( $ els ) ; }
Checks that the given element exists on the page even it is invisible .
41,620
public function dontSeeElementInDOM ( $ selector , $ attributes = [ ] ) { $ els = $ this -> match ( $ this -> getBaseElement ( ) , $ selector ) ; $ els = $ this -> filterByAttributes ( $ els , $ attributes ) ; $ this -> assertEmpty ( $ els ) ; }
Opposite of seeElementInDOM .
41,621
public function cancelPopup ( ) { if ( $ this -> isPhantom ( ) ) { throw new ModuleException ( $ this , 'PhantomJS does not support working with popups' ) ; } $ this -> webDriver -> switchTo ( ) -> alert ( ) -> dismiss ( ) ; }
Dismisses the active JavaScript popup as created by window . alert window . confirm or window . prompt .
41,622
public function seeInPopup ( $ text ) { if ( $ this -> isPhantom ( ) ) { throw new ModuleException ( $ this , 'PhantomJS does not support working with popups' ) ; } $ alert = $ this -> webDriver -> switchTo ( ) -> alert ( ) ; try { $ this -> assertStringContainsString ( $ text , $ alert -> getText ( ) ) ; } catch ( \ P...
Checks that the active JavaScript popup as created by window . alert | window . confirm | window . prompt contains the given string .
41,623
public function dontSeeInPopup ( $ text ) { if ( $ this -> isPhantom ( ) ) { throw new ModuleException ( $ this , 'PhantomJS does not support working with popups' ) ; } $ alert = $ this -> webDriver -> switchTo ( ) -> alert ( ) ; try { $ this -> assertStringNotContainsString ( $ text , $ alert -> getText ( ) ) ; } catc...
Checks that the active JavaScript popup as created by window . alert | window . confirm | window . prompt does NOT contain the given string .
41,624
public function typeInPopup ( $ keys ) { if ( $ this -> isPhantom ( ) ) { throw new ModuleException ( $ this , 'PhantomJS does not support working with popups' ) ; } $ this -> webDriver -> switchTo ( ) -> alert ( ) -> sendKeys ( $ keys ) ; }
Enters text into a native JavaScript prompt popup as created by window . prompt .
41,625
public function dragAndDrop ( $ source , $ target ) { $ snodes = $ this -> matchFirstOrFail ( $ this -> getBaseElement ( ) , $ source ) ; $ tnodes = $ this -> matchFirstOrFail ( $ this -> getBaseElement ( ) , $ target ) ; $ action = new WebDriverActions ( $ this -> webDriver ) ; $ action -> dragAndDrop ( $ snodes , $ t...
Performs a simple mouse drag - and - drop operation .
41,626
public function moveMouseOver ( $ cssOrXPath = null , $ offsetX = null , $ offsetY = null ) { $ where = null ; if ( null !== $ cssOrXPath ) { $ el = $ this -> matchFirstOrFail ( $ this -> getBaseElement ( ) , $ cssOrXPath ) ; $ where = $ el -> getCoordinates ( ) ; } $ this -> webDriver -> getMouse ( ) -> mouseMove ( $ ...
Move mouse over the first element matched by the given locator . If the first parameter null then the page is used . If the second and third parameters are given then the mouse is moved to an offset of the element s top - left corner . Otherwise the mouse is moved to the center of the element .
41,627
public function clickWithLeftButton ( $ cssOrXPath = null , $ offsetX = null , $ offsetY = null ) { $ this -> moveMouseOver ( $ cssOrXPath , $ offsetX , $ offsetY ) ; $ this -> webDriver -> getMouse ( ) -> click ( ) ; }
Performs click with the left mouse button on an element . If the first parameter null then the offset is relative to the actual mouse position . If the second and third parameters are given then the mouse is moved to an offset of the element s top - left corner . Otherwise the mouse is moved to the center of the elemen...
41,628
public function clickWithRightButton ( $ cssOrXPath = null , $ offsetX = null , $ offsetY = null ) { $ this -> moveMouseOver ( $ cssOrXPath , $ offsetX , $ offsetY ) ; $ this -> webDriver -> getMouse ( ) -> contextClick ( ) ; }
Performs contextual click with the right mouse button on an element . If the first parameter null then the offset is relative to the actual mouse position . If the second and third parameters are given then the mouse is moved to an offset of the element s top - left corner . Otherwise the mouse is moved to the center o...
41,629
public function doubleClick ( $ cssOrXPath ) { $ el = $ this -> matchFirstOrFail ( $ this -> getBaseElement ( ) , $ cssOrXPath ) ; $ this -> webDriver -> getMouse ( ) -> doubleClick ( $ el -> getCoordinates ( ) ) ; }
Performs a double - click on an element matched by CSS or XPath .
41,630
public function appendField ( $ field , $ value ) { $ el = $ this -> findField ( $ field ) ; switch ( $ el -> getTagName ( ) ) { case "select" : $ matched = false ; $ wdSelect = new WebDriverSelect ( $ el ) ; try { $ wdSelect -> selectByVisibleText ( $ value ) ; $ matched = true ; } catch ( NoSuchElementException $ e )...
Append the given text to the given element . Can also add a selection to a select box .
41,631
private function cookieDomainMatchesConfigUrl ( $ cookie ) { if ( ! array_key_exists ( 'domain' , $ cookie ) ) { return true ; } $ setCookie = new SetCookie ( ) ; $ setCookie -> setDomain ( $ cookie [ 'domain' ] ) ; return $ setCookie -> matchesDomain ( parse_url ( $ this -> config [ 'url' ] , PHP_URL_HOST ) ) ; }
Check if the cookie domain matches the config URL .
41,632
public function closeTab ( ) { $ prevTab = $ this -> getRelativeTabHandle ( - 1 ) ; $ this -> webDriver -> close ( ) ; $ this -> webDriver -> switchTo ( ) -> window ( $ prevTab ) ; }
Closes current browser tab and switches to previous active tab .
41,633
public function switchToNextTab ( $ offset = 1 ) { $ tab = $ this -> getRelativeTabHandle ( $ offset ) ; $ this -> webDriver -> switchTo ( ) -> window ( $ tab ) ; }
Switches to next browser tab . An offset can be specified .
41,634
public function performOn ( $ element , $ actions , $ timeout = 10 ) { $ this -> waitForElement ( $ element , $ timeout ) ; $ this -> setBaseElement ( $ element ) ; $ this -> debugSection ( 'InnerText' , $ this -> getBaseElement ( ) -> getText ( ) ) ; if ( is_callable ( $ actions ) ) { $ actions ( $ this ) ; $ this -> ...
Waits for element and runs a sequence of actions inside its context . Actions can be defined with array callback or Codeception \ Util \ ActionSequence instance .
41,635
public function _request ( $ method , $ uri , array $ parameters = [ ] , array $ files = [ ] , array $ server = [ ] , $ content = null ) { $ this -> clientRequest ( $ method , $ uri , $ parameters , $ files , $ server , $ content , true ) ; return $ this -> _getResponseContent ( ) ; }
Send custom request to a backend using method uri parameters etc . Use it in Helpers to create special request actions like accessing API Returns a string with response body .
41,636
public function _loadPage ( $ method , $ uri , array $ parameters = [ ] , array $ files = [ ] , array $ server = [ ] , $ content = null ) { $ this -> crawler = $ this -> clientRequest ( $ method , $ uri , $ parameters , $ files , $ server , $ content ) ; $ this -> baseUrl = $ this -> retrieveBaseUrl ( ) ; $ this -> for...
Opens a page with arbitrary request parameters . Useful for testing multi - step forms on a specific step .
41,637
public function amHttpAuthenticated ( $ username , $ password ) { $ this -> client -> setServerParameter ( 'PHP_AUTH_USER' , $ username ) ; $ this -> client -> setServerParameter ( 'PHP_AUTH_PW' , $ password ) ; }
Authenticates user for HTTP_AUTH
41,638
public function haveHttpHeader ( $ name , $ value ) { $ name = implode ( '-' , array_map ( 'ucfirst' , explode ( '-' , strtolower ( str_replace ( '_' , '-' , $ name ) ) ) ) ) ; $ this -> headers [ $ name ] = $ value ; }
Sets the HTTP header to the passed value - which is used on subsequent HTTP requests through PhpBrowser .
41,639
public function deleteHeader ( $ name ) { $ name = implode ( '-' , array_map ( 'ucfirst' , explode ( '-' , strtolower ( str_replace ( '_' , '-' , $ name ) ) ) ) ) ; unset ( $ this -> headers [ $ name ] ) ; }
Deletes the header with the passed name . Subsequent requests will not have the deleted header in its request .
41,640
protected function pushFormField ( & $ fields , $ form , $ name , $ values ) { $ field = $ form -> filterXPath ( sprintf ( './/*[@name=%s]' , Crawler :: xpathLiteral ( $ name ) ) ) ; if ( $ field -> count ( ) ) { $ fields [ ] = [ $ field , $ values ] ; } elseif ( is_array ( $ values ) ) { foreach ( $ values as $ key =>...
Map an array element passed to seeInFormFields to its corresponding field recursing through array values if the field is not found .
41,641
protected function getValueAndTextFromField ( Crawler $ nodes ) { if ( $ nodes -> filter ( 'textarea' ) -> count ( ) ) { return ( new TextareaFormField ( $ nodes -> filter ( 'textarea' ) -> getNode ( 0 ) ) ) -> getValue ( ) ; } $ input = $ nodes -> filter ( 'input' ) ; if ( $ input -> count ( ) ) { return $ this -> get...
Get the values of a set of fields and also the texts of selected options .
41,642
protected function getInputValue ( $ input ) { if ( $ input -> attr ( 'type' ) == 'checkbox' or $ input -> attr ( 'type' ) == 'radio' ) { $ values = [ ] ; foreach ( $ input -> filter ( ':checked' ) as $ checkbox ) { $ values [ ] = $ checkbox -> getAttribute ( 'value' ) ; } return $ values ; } return ( new InputFormFiel...
Get the values of a set of input fields .
41,643
protected function getAbsoluteUrlFor ( $ uri ) { $ currentUrl = $ this -> getRunningClient ( ) -> getHistory ( ) -> current ( ) -> getUri ( ) ; if ( empty ( $ uri ) || $ uri [ 0 ] === '#' ) { return $ currentUrl ; } return Uri :: mergeUrls ( $ currentUrl , $ uri ) ; }
Returns an absolute URL for the passed URI with the current URL as the base path .
41,644
protected function getFormUrl ( Crawler $ form ) { $ action = $ form -> form ( ) -> getUri ( ) ; return $ this -> getAbsoluteUrlFor ( $ action ) ; }
Returns the form action s absolute URL .
41,645
private function getFormFromCrawler ( Crawler $ form ) { $ fakeDom = new \ DOMDocument ( ) ; $ fakeDom -> appendChild ( $ fakeDom -> importNode ( $ form -> getNode ( 0 ) , true ) ) ; $ node = $ fakeDom -> documentElement ; $ action = ( string ) $ this -> getFormUrl ( $ form ) ; $ cloned = new Crawler ( $ node , $ actio...
Returns a crawler Form object for the form pointed to by the passed Crawler .
41,646
protected function getFormValuesFor ( Form $ form ) { $ values = [ ] ; $ fields = $ form -> all ( ) ; foreach ( $ fields as $ field ) { if ( $ field -> isDisabled ( ) || ! $ field -> hasValue ( ) || $ field instanceof FileFormField ) { continue ; } $ fieldName = $ this -> getSubmissionFormFieldName ( $ field -> getName...
Returns an array of name = > value pairs for the passed form .
41,647
public function sendAjaxRequest ( $ method , $ uri , $ params = [ ] ) { $ this -> clientRequest ( $ method , $ uri , $ params , [ ] , [ 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest' ] , null , false ) ; }
If your page triggers an ajax request you can perform it manually . This action sends an ajax request with specified method and params .
41,648
public function switchToIframe ( $ name ) { $ iframe = $ this -> match ( "iframe[name=$name]" ) -> first ( ) ; if ( ! count ( $ iframe ) ) { $ iframe = $ this -> match ( "frame[name=$name]" ) -> first ( ) ; } if ( ! count ( $ iframe ) ) { throw new ElementNotFound ( "name=$name" , 'Iframe' ) ; } $ uri = $ iframe -> get...
Switch to iframe or frame on the page .
41,649
public function moveBack ( $ numberOfSteps = 1 ) { if ( ! is_int ( $ numberOfSteps ) || $ numberOfSteps < 1 ) { throw new \ InvalidArgumentException ( 'numberOfSteps must be positive integer' ) ; } try { $ history = $ this -> getRunningClient ( ) -> getHistory ( ) ; for ( $ i = $ numberOfSteps ; $ i > 0 ; $ i -- ) { $ ...
Moves back in history .
41,650
private function initializeSymfonyCache ( ) { $ cache = Configuration :: projectDir ( ) . $ this -> config [ 'var_path' ] . DIRECTORY_SEPARATOR . 'bootstrap.php.cache' ; if ( PHP_VERSION_ID < 70000 && ! file_exists ( $ cache ) ) { throw new ModuleRequireException ( __CLASS__ , "Symfony bootstrap file not found in $cach...
Require Symfonys bootstrap . php . cache only for PHP Version < 7
41,651
public function _before ( \ Codeception \ TestInterface $ test ) { $ this -> persistentServices = array_merge ( $ this -> persistentServices , $ this -> permanentServices ) ; $ this -> client = new SymfonyConnector ( $ this -> kernel , $ this -> persistentServices , $ this -> config [ 'rebootable_client' ] ) ; }
Initialize new client instance before each test
41,652
public function _after ( \ Codeception \ TestInterface $ test ) { foreach ( $ this -> permanentServices as $ serviceName => $ service ) { $ this -> permanentServices [ $ serviceName ] = $ this -> grabService ( $ serviceName ) ; } parent :: _after ( $ test ) ; }
Update permanent services after each test
41,653
public function _getEntityManager ( ) { if ( $ this -> kernel === null ) { $ this -> fail ( 'Symfony2 platform module is not loaded' ) ; } if ( ! isset ( $ this -> permanentServices [ $ this -> config [ 'em_service' ] ] ) ) { $ this -> persistService ( $ this -> config [ 'em_service' ] , true ) ; if ( $ this -> _getCon...
Retrieve Entity Manager .
41,654
protected function getKernelClass ( ) { $ path = codecept_root_dir ( ) . $ this -> config [ 'app_path' ] ; if ( ! file_exists ( codecept_root_dir ( ) . $ this -> config [ 'app_path' ] ) ) { throw new ModuleRequireException ( __CLASS__ , "Can't load Kernel from $path.\n" . "Directory does not exists. Use `app_path` para...
Attempts to guess the kernel location .
41,655
public function seeInCurrentRoute ( $ routeName ) { $ router = $ this -> grabService ( 'router' ) ; if ( ! $ router -> getRouteCollection ( ) -> get ( $ routeName ) ) { $ this -> fail ( sprintf ( 'Route with name "%s" does not exists.' , $ routeName ) ) ; } $ uri = explode ( '?' , $ this -> grabFromCurrentUrl ( ) ) [ 0...
Checks that current url matches route . Unlike seeCurrentRouteIs this can matches without exact route parameters
41,656
public function seeEmailIsSent ( $ expectedCount = null ) { $ profile = $ this -> getProfile ( ) ; if ( ! $ profile ) { $ this -> fail ( 'Emails can\'t be tested without Profiler' ) ; } if ( ! $ profile -> hasCollector ( 'swiftmailer' ) ) { $ this -> fail ( 'Emails can\'t be tested without SwiftMailer connector' ) ; } ...
Checks if the desired number of emails was sent . If no argument is provided then at least one email must be sent to satisfy the check .
41,657
public function grabService ( $ service ) { $ container = $ this -> _getContainer ( ) ; if ( ! $ container -> has ( $ service ) ) { $ this -> fail ( "Service $service is not available in container" ) ; } return $ container -> get ( $ service ) ; }
Grabs a service from Symfony DIC container . Recommended to use for unit testing .
41,658
protected function getInternalDomains ( ) { $ internalDomains = [ ] ; $ routes = $ this -> grabService ( 'router' ) -> getRouteCollection ( ) ; foreach ( $ routes as $ route ) { if ( ! is_null ( $ route -> getHost ( ) ) ) { $ compiled = $ route -> compile ( ) ; if ( ! is_null ( $ compiled -> getHostRegex ( ) ) ) { $ in...
Returns a list of recognized domain names .
41,659
private function getPossibleKernelClasses ( ) { if ( empty ( $ this -> config [ 'kernel_class' ] ) ) { return self :: $ possibleKernelClasses ; } if ( ! is_string ( $ this -> config [ 'kernel_class' ] ) ) { throw new ModuleException ( __CLASS__ , "Parameter 'kernel_class' must have 'string' type.\n" ) ; } return [ $ th...
Returns list of the possible kernel classes based on the module configuration
41,660
public function publishBase ( $ branch = null , $ tag = null ) { if ( ! $ branch ) { $ branch = self :: STABLE_BRANCH ; } $ this -> say ( "Updating Codeception Base distribution" ) ; $ tempBranch = "tmp" . uniqid ( ) ; $ this -> taskGitStack ( ) -> checkout ( "-b $tempBranch" ) -> run ( ) ; $ this -> taskReplaceInFile ...
Publishes Codeception base
41,661
public static function combine ( $ selector1 , $ selector2 ) { $ selectors = func_get_args ( ) ; foreach ( $ selectors as $ k => $ v ) { $ selectors [ $ k ] = self :: toXPath ( $ v ) ; if ( ! $ selectors [ $ k ] ) { throw new \ Exception ( "$v is invalid CSS or XPath" ) ; } } return implode ( ' | ' , $ selectors ) ; }
Applies OR operator to any number of CSS or XPath selectors . You can mix up CSS and XPath selectors here .
41,662
public static function isXPath ( $ locator ) { $ document = new \ DOMDocument ( '1.0' , 'UTF-8' ) ; $ xpath = new \ DOMXPath ( $ document ) ; return @ $ xpath -> evaluate ( $ locator , $ document ) !== false ; }
Checks that locator is an XPath
41,663
public static function contains ( $ element , $ text ) { $ text = Translator :: getXpathLiteral ( $ text ) ; return sprintf ( '%s[%s]' , self :: toXPath ( $ element ) , "contains(., $text)" ) ; }
Locates an element containing a text inside . Either CSS or XPath locator can be passed however they will be converted to XPath .
41,664
public static function elementAt ( $ element , $ position ) { if ( is_int ( $ position ) && $ position < 0 ) { $ position ++ ; $ position = 'last()-' . abs ( $ position ) ; } if ( $ position === 0 ) { throw new \ InvalidArgumentException ( '0 is not valid element position. XPath expects first element to have index 1' )...
Locates element at position . Either CSS or XPath locator can be passed as locator position is an integer . If a negative value is provided counting starts from the last element . First element has index 1
41,665
public static function humanReadableString ( $ selector ) { if ( is_string ( $ selector ) ) { return "'$selector'" ; } if ( is_array ( $ selector ) ) { $ type = strtolower ( key ( $ selector ) ) ; $ locator = $ selector [ $ type ] ; return "$type '$locator'" ; } if ( class_exists ( '\Facebook\WebDriver\WebDriverBy' ) )...
Transforms strict locator \ Facebook \ WebDriver \ WebDriverBy into a string represenation
41,666
public function haveInCollection ( $ collection , array $ data ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; if ( $ this -> driver -> isLegacy ( ) ) { $ collection -> insert ( $ data ) ; return $ data [ '_id' ] ; } $ response = $ collection -> insertOne ( $ data ) ; return ( s...
Inserts data into collection
41,667
public function seeInCollection ( $ collection , $ criteria = [ ] ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; $ res = $ collection -> count ( $ criteria ) ; \ PHPUnit \ Framework \ Assert :: assertGreaterThan ( 0 , $ res ) ; }
Checks if collection contains an item .
41,668
public function dontSeeInCollection ( $ collection , $ criteria = [ ] ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; $ res = $ collection -> count ( $ criteria ) ; \ PHPUnit \ Framework \ Assert :: assertLessThan ( 1 , $ res ) ; }
Checks if collection doesn t contain an item .
41,669
public function grabFromCollection ( $ collection , $ criteria = [ ] ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; return $ collection -> findOne ( $ criteria ) ; }
Grabs a data from collection
41,670
public function grabCollectionCount ( $ collection , $ criteria = [ ] ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; return $ collection -> count ( $ criteria ) ; }
Grabs the documents count from a collection
41,671
public function seeElementIsObject ( $ collection , $ criteria = [ ] , $ elementToCheck = null ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; $ res = $ collection -> count ( array_merge ( $ criteria , [ $ elementToCheck => [ '$exists' => true ] , '$where' => "! Array.isArray(th...
Asserts that an element in a collection exists and is an Object
41,672
public function seeNumElementsInCollection ( $ collection , $ expected , $ criteria = [ ] ) { $ collection = $ this -> driver -> getDbh ( ) -> selectCollection ( $ collection ) ; $ res = $ collection -> count ( $ criteria ) ; \ PHPUnit \ Framework \ Assert :: assertSame ( $ expected , $ res ) ; }
Count number of records in a collection
41,673
protected static function loadEnvConfigs ( $ path ) { if ( isset ( self :: $ envConfig [ $ path ] ) ) { return self :: $ envConfig [ $ path ] ; } if ( ! is_dir ( $ path ) ) { self :: $ envConfig [ $ path ] = [ ] ; return self :: $ envConfig [ $ path ] ; } $ envFiles = Finder :: create ( ) -> files ( ) -> name ( '*.yml'...
Loads environments configuration from set directory
41,674
protected static function getConfFromContents ( $ contents , $ filename = '(.yml)' ) { if ( self :: $ params ) { $ template = new Template ( $ contents , '%' , '%' ) ; $ template -> setVars ( self :: $ params ) ; $ contents = $ template -> produce ( ) ; } try { return Yaml :: parse ( $ contents ) ; } catch ( ParseExcep...
Loads configuration from Yaml data
41,675
protected static function getConfFromFile ( $ filename , $ nonExistentValue = [ ] ) { if ( file_exists ( $ filename ) ) { $ yaml = file_get_contents ( $ filename ) ; return self :: getConfFromContents ( $ yaml , $ filename ) ; } return $ nonExistentValue ; }
Loads configuration from Yaml file or returns given value if the file doesn t exist
41,676
public static function suiteEnvironments ( $ suite ) { $ settings = self :: suiteSettings ( $ suite , self :: config ( ) ) ; if ( ! isset ( $ settings [ 'env' ] ) || ! is_array ( $ settings [ 'env' ] ) ) { return [ ] ; } $ environments = [ ] ; foreach ( $ settings [ 'env' ] as $ env => $ envConfig ) { $ environments [ ...
Returns all possible suite configurations according environment rules . Suite configurations will contain current_environment key which specifies what environment used .
41,677
public static function modules ( $ settings ) { return array_filter ( array_map ( function ( $ m ) { return is_array ( $ m ) ? key ( $ m ) : $ m ; } , $ settings [ 'modules' ] [ 'enabled' ] , array_keys ( $ settings [ 'modules' ] [ 'enabled' ] ) ) , function ( $ m ) use ( $ settings ) { if ( ! isset ( $ settings [ 'mod...
Return list of enabled modules according suite config .
41,678
public static function outputDir ( ) { if ( ! self :: $ outputDir ) { throw new ConfigurationException ( "Path for output not specified. Please, set output path in global config" ) ; } $ dir = self :: $ outputDir . DIRECTORY_SEPARATOR ; if ( strcmp ( self :: $ outputDir [ 0 ] , "/" ) !== 0 ) { $ dir = self :: $ dir . D...
Returns actual path to current _output dir . Use it in Helpers or Groups to save result or temporary files .
41,679
public static function envsDir ( ) { if ( ! self :: $ envsDir ) { return null ; } return self :: $ dir . DIRECTORY_SEPARATOR . self :: $ envsDir . DIRECTORY_SEPARATOR ; }
Return current path to _envs dir . Use it to store environment specific configuration .
41,680
public static function append ( array $ config = [ ] ) { self :: $ config = self :: mergeConfigs ( self :: $ config , $ config ) ; if ( isset ( self :: $ config [ 'paths' ] [ 'output' ] ) ) { self :: $ outputDir = self :: $ config [ 'paths' ] [ 'output' ] ; } if ( isset ( self :: $ config [ 'paths' ] [ 'data' ] ) ) { s...
Adds parameters to config
41,681
protected static function expandWildcardedIncludes ( array $ includes ) { if ( empty ( $ includes ) ) { return $ includes ; } $ expandedIncludes = [ ] ; foreach ( $ includes as $ include ) { $ expandedIncludes = array_merge ( $ expandedIncludes , self :: expandWildcardsFor ( $ include ) ) ; } return $ expandedIncludes ...
Replaces wildcarded items in include array with real paths .
41,682
protected static function expandWildcardsFor ( $ include ) { if ( 1 !== preg_match ( '/[\?\.\*]/' , $ include ) ) { return [ $ include , ] ; } try { $ configFiles = Finder :: create ( ) -> files ( ) -> name ( '/codeception(\.dist\.yml|\.yml)/' ) -> in ( self :: $ dir . DIRECTORY_SEPARATOR . $ include ) ; } catch ( \ In...
Finds config files in given wildcarded include path . Returns the expanded paths or the original if not a wildcard .
41,683
public function pushToQueue ( $ queue , $ message ) { $ message = $ message instanceof AMQPMessage ? $ message : new AMQPMessage ( $ message ) ; $ this -> getChannel ( ) -> queue_declare ( $ queue ) ; $ this -> getChannel ( ) -> basic_publish ( $ message , '' , $ queue ) ; }
Sends message to queue
41,684
public function declareExchange ( $ exchange , $ type , $ passive = false , $ durable = false , $ auto_delete = true , $ internal = false , $ nowait = false , $ arguments = null , $ ticket = null ) { return $ this -> getChannel ( ) -> exchange_declare ( $ exchange , $ type , $ passive , $ durable , $ auto_delete , $ in...
Declares an exchange
41,685
public function bindQueueToExchange ( $ queue , $ exchange , $ routing_key = '' , $ nowait = false , $ arguments = null , $ ticket = null ) { return $ this -> getChannel ( ) -> queue_bind ( $ queue , $ exchange , $ routing_key , $ nowait , $ arguments , $ ticket ) ; }
Binds a queue to an exchange
41,686
public function seeMessageInQueueContainsText ( $ queue , $ text ) { $ msg = $ this -> getChannel ( ) -> basic_get ( $ queue ) ; if ( ! $ msg ) { $ this -> fail ( "Message was not received" ) ; } if ( ! $ msg instanceof AMQPMessage ) { $ this -> fail ( "Received message is not format of AMQPMessage" ) ; } $ this -> deb...
Checks if message containing text received .
41,687
public function _countMessage ( $ queue ) { list ( $ queue , $ messageCount ) = $ this -> getChannel ( ) -> queue_declare ( $ queue , true ) ; return $ messageCount ; }
Count messages in queue .
41,688
public function seeNumberOfMessagesInQueue ( $ queue , $ expected ) { $ messageCount = $ this -> _countMessage ( $ queue ) ; $ this -> assertEquals ( $ expected , $ messageCount ) ; }
Checks that queue have expected number of message
41,689
public function purgeQueue ( $ queueName = '' ) { if ( ! in_array ( $ queueName , $ this -> config [ 'queues' ] ) ) { throw new ModuleException ( __CLASS__ , "'$queueName' doesn't exist in queues config list" ) ; } $ this -> getChannel ( ) -> queue_purge ( $ queueName , true ) ; }
Purge a specific queue defined in config .
41,690
public function registerCustomCommands ( ) { try { $ this -> readCustomCommandsFromConfig ( ) ; } catch ( ConfigurationException $ e ) { if ( $ e -> getCode ( ) === 404 ) { return ; } $ this -> renderException ( $ e , new ConsoleOutput ( ) ) ; exit ( 1 ) ; } catch ( \ Exception $ e ) { $ this -> renderException ( $ e ,...
Register commands from config file
41,691
protected function readCustomCommandsFromConfig ( ) { $ this -> getCoreArguments ( ) ; $ config = Configuration :: config ( ) ; if ( empty ( $ config [ 'extensions' ] [ 'commands' ] ) ) { return ; } foreach ( $ config [ 'extensions' ] [ 'commands' ] as $ commandClass ) { $ commandName = $ this -> getCustomCommandName (...
Search custom commands and register them .
41,692
protected function getCustomCommandName ( $ commandClass ) { if ( ! class_exists ( $ commandClass ) ) { throw new ConfigurationException ( "Extension: Command class $commandClass not found" ) ; } $ interfaces = class_implements ( $ commandClass ) ; if ( ! in_array ( 'Codeception\CustomCommandInterface' , $ interfaces )...
Validate and get the name of the command
41,693
public function run ( InputInterface $ input = null , OutputInterface $ output = null ) { if ( $ input === null ) { $ input = $ this -> getCoreArguments ( ) ; } if ( ! ini_get ( 'register_argc_argv' ) ) { throw new ConfigurationException ( 'register_argc_argv must be set to On for running Codeception' ) ; } return pare...
To cache Class ArgvInput
41,694
protected function preloadConfiguration ( $ configFile ) { try { Configuration :: config ( $ configFile ) ; } catch ( ConfigurationException $ e ) { if ( $ e -> getCode ( ) == 404 ) { throw new ConfigurationException ( "Your configuration file `{$configFile}` could not be found." , 405 ) ; } throw $ e ; } }
Pre load Configuration the config option is use .
41,695
public function haveSoapHeader ( $ header , $ params = [ ] ) { $ soap_schema_url = $ this -> config [ 'schema_url' ] ; $ xml = $ this -> xmlRequest ; $ xmlHeader = $ xml -> documentElement -> getElementsByTagNameNS ( $ soap_schema_url , 'Header' ) -> item ( 0 ) ; $ headerEl = $ xml -> createElement ( $ header ) ; SoapU...
Prepare SOAP header . Receives header name and parameters as array .
41,696
public function sendSoapRequest ( $ action , $ body = "" ) { $ soap_schema_url = $ this -> config [ 'schema_url' ] ; $ xml = $ this -> xmlRequest ; $ call = $ xml -> createElement ( 'ns:' . $ action ) ; if ( $ body ) { $ bodyXml = SoapUtils :: toXml ( $ body ) ; if ( $ bodyXml -> hasChildNodes ( ) ) { foreach ( $ bodyX...
Submits request to endpoint .
41,697
public function seeSoapResponseContainsStructure ( $ xml ) { $ xml = SoapUtils :: toXml ( $ xml ) ; $ this -> debugSection ( "Structure" , $ xml -> saveXML ( ) ) ; $ this -> assertTrue ( ( bool ) $ this -> getXmlStructure ( ) -> matchXmlStructure ( $ xml ) , "this structure is in response" ) ; }
Checks XML response contains provided structure . Response elements will be compared with XML provided . Only nodeNames are checked to see elements match .
41,698
public function dontSeeSoapResponseContainsStructure ( $ xml ) { $ xml = SoapUtils :: toXml ( $ xml ) ; $ this -> debugSection ( "Structure" , $ xml -> saveXML ( ) ) ; $ this -> assertFalse ( ( bool ) $ this -> getXmlStructure ( ) -> matchXmlStructure ( $ xml ) , "this structure is in response" ) ; }
Opposite to seeSoapResponseContainsStructure
41,699
public function haveInSession ( $ key , $ val ) { $ this -> di -> get ( 'session' ) -> set ( $ key , $ val ) ; $ this -> debugSection ( 'Session' , json_encode ( $ this -> di [ 'session' ] -> toArray ( ) ) ) ; }
Sets value to session . Use for authorization .