idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
41,400 | protected function decode ( $ job ) { $ job -> payload = json_decode ( $ job -> payload ) ; $ job -> retried_by = collect ( json_decode ( $ job -> retried_by ) ) -> sortByDesc ( 'retried_at' ) -> values ( ) ; return $ job ; } | Decode the given job . |
41,401 | public function with ( $ key , $ callback , $ seconds = 60 ) { if ( $ this -> get ( $ key , $ seconds ) ) { try { call_user_func ( $ callback ) ; } finally { $ this -> release ( $ key ) ; } } } | Execute the given callback if a lock can be acquired . |
41,402 | public function get ( $ key , $ seconds = 60 ) { $ result = $ this -> connection ( ) -> setnx ( $ key , 1 ) ; if ( $ result === 1 ) { $ this -> connection ( ) -> expire ( $ key , $ seconds ) ; } return $ result === 1 ; } | Attempt to get a lock for the given key . |
41,403 | public function show ( $ slug ) { return collect ( $ this -> metrics -> snapshotsForJob ( $ slug ) ) -> map ( function ( $ record ) { $ record -> runtime = round ( $ record -> runtime / 1000 , 3 ) ; $ record -> throughput = ( int ) $ record -> throughput ; return $ record ; } ) ; } | Get metrics for a given job . |
41,404 | public function index ( ) { return collect ( $ this -> tags -> monitoring ( ) ) -> map ( function ( $ tag ) { return [ 'tag' => $ tag , 'count' => $ this -> tags -> count ( $ tag ) + $ this -> tags -> count ( 'failed:' . $ tag ) , ] ; } ) -> sortBy ( 'tag' ) -> values ( ) ; } | Get all of the monitored tags and their job counts . |
41,405 | public function paginate ( Request $ request , $ tag ) { $ jobIds = $ this -> tags -> paginate ( $ tag , $ startingAt = $ request -> query ( 'starting_at' , 0 ) , $ request -> query ( 'limit' , 25 ) ) ; return [ 'jobs' => $ this -> getJobs ( $ jobIds , $ startingAt ) , 'total' => $ this -> tags -> count ( $ tag ) , ] ;... | Paginate the jobs for a given tag . |
41,406 | protected function getJobs ( $ jobIds , $ startingAt = 0 ) { return $ this -> jobs -> getJobs ( $ jobIds , $ startingAt ) -> map ( function ( $ job ) { $ job -> payload = json_decode ( $ job -> payload ) ; return $ job ; } ) -> values ( ) ; } | Get the jobs for the given IDs . |
41,407 | public function handle ( JobDeleted $ event ) { if ( $ event -> job -> hasFailed ( ) ) { return ; } $ time = $ this -> watch -> check ( $ event -> payload -> id ( ) ) ; $ this -> metrics -> incrementQueue ( $ event -> job -> getQueue ( ) , $ time ) ; $ this -> metrics -> incrementJob ( $ event -> payload -> displayName... | Stop gathering metrics for a job . |
41,408 | public function calculate ( $ queue = null ) { $ queues = $ this -> queueNames ( $ supervisors = collect ( $ this -> supervisors -> all ( ) ) , $ queue ) ; return $ queues -> mapWithKeys ( function ( $ queue ) use ( $ supervisors ) { $ totalProcesses = $ this -> totalProcessesFor ( $ supervisors , $ queue ) ; [ $ conne... | Calculate the time to clear per queue in seconds . |
41,409 | protected function queueNames ( $ supervisors , $ queue = null ) { $ queues = $ supervisors -> map ( function ( $ supervisor ) { return array_keys ( $ supervisor -> processes ) ; } ) -> collapse ( ) -> unique ( ) -> values ( ) ; return $ queue ? $ queues -> intersect ( [ $ queue ] ) : $ queues ; } | Get all of the queue names . |
41,410 | protected function totalProcessesFor ( $ allSupervisors , $ queue ) { return $ allSupervisors -> sum ( function ( $ supervisor ) use ( $ queue ) { return $ supervisor -> processes [ $ queue ] ?? 0 ; } ) ; } | Get the total process count for a given queue . |
41,411 | public function purge ( $ master ) { $ this -> recordOrphans ( $ master ) ; $ expired = $ this -> processes -> orphanedFor ( $ master , $ this -> supervisors -> longestActiveTimeout ( ) ) ; collect ( $ expired ) -> each ( function ( $ processId ) use ( $ master ) { $ this -> comment ( "Killing Process: {$processId}" ) ... | Purge any orphan processes . |
41,412 | protected function recordOrphans ( $ master ) { $ this -> processes -> orphaned ( $ master , $ orphans = $ this -> inspector -> orphaned ( ) ) ; foreach ( $ orphans as $ processId ) { $ this -> info ( "Observed Orphan: {$processId}" ) ; if ( ! posix_kill ( $ processId , SIGTERM ) ) { $ this -> error ( "Failed to kill p... | Record the orphaned Horizon processes . |
41,413 | protected function listenForSignals ( ) { pcntl_async_signals ( true ) ; pcntl_signal ( SIGTERM , function ( ) { $ this -> pendingSignals [ 'terminate' ] = 'terminate' ; } ) ; pcntl_signal ( SIGUSR1 , function ( ) { $ this -> pendingSignals [ 'restart' ] = 'restart' ; } ) ; pcntl_signal ( SIGUSR2 , function ( ) { $ thi... | Listen for incoming process signals . |
41,414 | protected function processPendingSignals ( ) { while ( $ this -> pendingSignals ) { $ signal = Arr :: first ( $ this -> pendingSignals ) ; $ this -> { $ signal } ( ) ; unset ( $ this -> pendingSignals [ $ signal ] ) ; } } | Process the pending signals . |
41,415 | public function add ( $ id , array $ tags ) { $ this -> connection ( ) -> pipeline ( function ( $ pipe ) use ( $ id , $ tags ) { foreach ( $ tags as $ tag ) { $ pipe -> zadd ( $ tag , $ id , $ id ) ; } } ) ; } | Store the tags for the given job . |
41,416 | public function addTemporary ( $ minutes , $ id , array $ tags ) { $ this -> connection ( ) -> pipeline ( function ( $ pipe ) use ( $ minutes , $ id , $ tags ) { foreach ( $ tags as $ tag ) { $ pipe -> zadd ( $ tag , $ id , $ id ) ; $ pipe -> expire ( $ tag , $ minutes * 60 ) ; } } ) ; } | Store the tags for the given job temporarily . |
41,417 | public function paginate ( $ tag , $ startingAt = 0 , $ limit = 25 ) { $ tags = ( array ) $ this -> connection ( ) -> zrevrange ( $ tag , $ startingAt , $ startingAt + $ limit - 1 ) ; return collect ( $ tags ) -> values ( ) -> mapWithKeys ( function ( $ tag , $ index ) use ( $ startingAt ) { return [ $ index + $ starti... | Paginate the job IDs for a given tag . |
41,418 | public function forgetJobs ( $ tags , $ ids ) { $ this -> connection ( ) -> pipeline ( function ( $ pipe ) use ( $ tags , $ ids ) { foreach ( ( array ) $ tags as $ tag ) { foreach ( ( array ) $ ids as $ id ) { $ pipe -> zrem ( $ tag , $ id ) ; } } } ) ; } | Remove the given job IDs from the given tag . |
41,419 | protected function dueToMonitor ( ) { if ( ! $ this -> lastMonitored ) { $ this -> lastMonitored = Chronos :: now ( ) ; } if ( ! $ this -> timeToMonitor ( ) ) { return false ; } $ this -> lastMonitored = Chronos :: now ( ) ; return $ this -> metrics -> acquireWaitTimeMonitorLock ( ) ; } | Determine if monitoring is due . |
41,420 | protected function preparePayload ( $ id , $ payload ) { return json_encode ( array_merge ( json_decode ( $ payload , true ) , [ 'id' => $ id , 'attempts' => 0 , 'retry_of' => $ this -> id , ] ) ) ; } | Prepare the payload for queueing . |
41,421 | public static function fromOptions ( SupervisorOptions $ options ) { $ command = str_replace ( '@php' , PhpBinary :: path ( ) , static :: $ command ) ; return sprintf ( "%s {$options->name} {$options->connection} %s" , $ command , static :: toOptionsString ( $ options ) ) ; } | Get the command - line representation of the options for a supervisor . |
41,422 | public function monitor ( ) { if ( ! $ this -> process -> isStarted ( ) ) { return $ this -> restart ( ) ; } if ( ! $ this -> process -> isRunning ( ) && $ this -> process -> getExitCode ( ) === 13 ) { return $ this -> markAsDead ( ) ; } if ( $ this -> process -> isRunning ( ) || $ this -> coolingDown ( ) ) { return ; ... | Evaluate the current state of the process . |
41,423 | protected function reprovision ( ) { app ( HorizonCommandQueue :: class ) -> push ( MasterSupervisor :: commandQueue ( ) , AddSupervisor :: class , $ this -> options -> toArray ( ) ) ; } | Re - provision this supervisor process based on the provisioning plan . |
41,424 | public function terminateWithStatus ( $ status ) { app ( HorizonCommandQueue :: class ) -> push ( $ this -> options -> name , Terminate :: class , [ 'status' => $ status ] ) ; } | Terminate the supervisor with the given status . |
41,425 | public function scale ( Supervisor $ supervisor ) { $ pools = $ this -> poolsByQueue ( $ supervisor ) ; $ workers = $ this -> numberOfWorkersPerQueue ( $ supervisor , $ this -> timeToClearPerQueue ( $ supervisor , $ pools ) ) ; $ workers -> each ( function ( $ workers , $ queue ) use ( $ supervisor , $ pools ) { $ this... | Balance the workers on the given supervisor . |
41,426 | protected function poolsByQueue ( Supervisor $ supervisor ) { return $ supervisor -> processPools -> mapWithKeys ( function ( $ pool ) { return [ $ pool -> queue ( ) => $ pool ] ; } ) ; } | Get the process pools keyed by their queue name . |
41,427 | protected function timeToClearPerQueue ( Supervisor $ supervisor , Collection $ pools ) { return $ pools -> mapWithKeys ( function ( $ pool , $ queue ) use ( $ supervisor ) { $ size = $ this -> queue -> connection ( $ supervisor -> options -> connection ) -> readyNow ( $ queue ) ; return [ $ queue => ( $ size * $ this ... | Get the times in milliseconds needed to clear the queues . |
41,428 | protected function numberOfWorkersPerQueue ( Supervisor $ supervisor , Collection $ timeToClear ) { $ timeToClearAll = $ timeToClear -> sum ( ) ; return $ timeToClear -> mapWithKeys ( function ( $ timeToClear , $ queue ) use ( $ supervisor , $ timeToClearAll ) { return $ timeToClearAll > 0 && $ supervisor -> options ->... | Get the number of workers needed per queue for proper balance . |
41,429 | protected function scalePool ( Supervisor $ supervisor , $ pool , $ workers ) { $ supervisor -> pruneTerminatingProcesses ( ) ; $ poolProcesses = $ pool -> totalProcessCount ( ) ; if ( round ( $ workers ) > $ poolProcesses && $ this -> wouldNotExceedMaxProcesses ( $ supervisor ) ) { $ pool -> scale ( $ poolProcesses + ... | Scale the given pool to the recommended number of workers . |
41,430 | public function index ( MasterSupervisorRepository $ masters , SupervisorRepository $ supervisors ) { $ masters = collect ( $ masters -> all ( ) ) -> keyBy ( 'name' ) -> sortBy ( 'name' ) ; $ supervisors = collect ( $ supervisors -> all ( ) ) -> sortBy ( 'name' ) -> groupBy ( 'master' ) ; return $ masters -> each ( fun... | Get all of the master supervisors and their underlying supervisors . |
41,431 | public function process ( MasterSupervisor $ master , array $ options ) { $ options = SupervisorOptions :: fromArray ( $ options ) ; $ master -> supervisors [ ] = new SupervisorProcess ( $ options , $ this -> createProcess ( $ master , $ options ) , function ( $ type , $ line ) use ( $ master ) { $ master -> output ( $... | Process the command . |
41,432 | protected function createProcess ( MasterSupervisor $ master , SupervisorOptions $ options ) { $ command = $ options -> toSupervisorCommand ( ) ; return Process :: fromShellCommandline ( $ command , $ options -> directory ?? base_path ( ) ) -> setTimeout ( null ) -> disableOutput ( ) ; } | Create the Symfony process instance . |
41,433 | public function get ( $ name ) { $ process = Process :: fromShellCommandline ( 'exec ps aux | grep ' . static :: $ command , null , [ 'COLUMNS' => '2000' ] ) ; $ process -> run ( ) ; return substr_count ( $ process -> getOutput ( ) , 'supervisor=' . $ name ) ; } | Get the number of Horizon workers for a given supervisor . |
41,434 | public function check ( $ key ) { if ( isset ( $ this -> timers [ $ key ] ) ) { return round ( ( microtime ( true ) - $ this -> timers [ $ key ] ) * 1000 , 2 ) ; } } | Check a given timer and get the elapsed time in milliseconds . |
41,435 | public function monitoring ( ) { return collect ( app ( SupervisorRepository :: class ) -> all ( ) ) -> pluck ( 'pid' ) -> pipe ( function ( $ processes ) { $ processes -> each ( function ( $ process ) use ( & $ processes ) { $ processes = $ processes -> merge ( $ this -> exec -> run ( "pgrep -P {$process}" ) ) ; } ) ;... | Get all of the process IDs Horizon is actively monitoring . |
41,436 | public function orphaned ( $ master , array $ processIds ) { $ time = Chronos :: now ( ) -> getTimestamp ( ) ; $ shouldRemove = array_diff ( $ this -> connection ( ) -> hkeys ( $ key = "{$master}:orphans" ) , $ processIds ) ; if ( ! empty ( $ shouldRemove ) ) { $ this -> connection ( ) -> hdel ( $ key , ... $ shouldRem... | Record the given process IDs as orphaned . |
41,437 | public function orphanedFor ( $ master , $ seconds ) { $ expiresAt = Chronos :: now ( ) -> getTimestamp ( ) - $ seconds ; return collect ( $ this -> allOrphans ( $ master ) ) -> filter ( function ( $ recordedAt , $ _ ) use ( $ expiresAt ) { return $ expiresAt > $ recordedAt ; } ) -> keys ( ) -> all ( ) ; } | Get the process IDs orphaned for at least the given number of seconds . |
41,438 | public function deploy ( $ environment ) { $ supervisors = collect ( $ this -> parsed ) -> first ( function ( $ _ , $ name ) use ( $ environment ) { return Str :: is ( $ name , $ environment ) ; } ) ; if ( empty ( $ supervisors ) ) { return ; } foreach ( $ supervisors as $ supervisor => $ options ) { $ this -> add ( $ ... | Deploy a provisioning plan to the current machine . |
41,439 | protected function add ( SupervisorOptions $ options ) { app ( HorizonCommandQueue :: class ) -> push ( MasterSupervisor :: commandQueueFor ( $ this -> master ) , AddSupervisor :: class , $ options -> toArray ( ) ) ; } | Add a supervisor with the given options . |
41,440 | public function optionsFor ( $ environment , $ supervisor ) { if ( isset ( $ this -> parsed [ $ environment ] ) && isset ( $ this -> parsed [ $ environment ] [ $ supervisor ] ) ) { return $ this -> parsed [ $ environment ] [ $ supervisor ] ; } } | Get the SupervisorOptions for a given environment and supervisor . |
41,441 | public function toSupervisorOptions ( ) { return collect ( $ this -> plan ) -> mapWithKeys ( function ( $ plan , $ environment ) { return [ $ environment => collect ( $ plan ) -> mapWithKeys ( function ( $ options , $ supervisor ) { return [ $ supervisor => $ this -> convert ( $ supervisor , $ options ) ] ; } ) ] ; } )... | Convert the provisioning plan into an array of SupervisorOptions . |
41,442 | protected function convert ( $ supervisor , $ options ) { $ options = collect ( $ options ) -> mapWithKeys ( function ( $ value , $ key ) { $ key = $ key === 'tries' ? 'max_tries' : $ key ; $ key = $ key === 'processes' ? 'max_processes' : $ key ; $ value = $ key === 'queue' && is_array ( $ value ) ? implode ( ',' , $ ... | Convert the given array of options into a SupervisorOptions instance . |
41,443 | public function index ( Request $ request ) { $ jobs = $ this -> jobs -> getRecent ( $ request -> query ( 'starting_at' , - 1 ) ) -> map ( function ( $ job ) { $ job -> payload = json_decode ( $ job -> payload ) ; return $ job ; } ) -> values ( ) ; return [ 'jobs' => $ jobs , 'total' => $ this -> jobs -> countRecent ( ... | Get all of the recent jobs . |
41,444 | protected function registerHorizonServiceProvider ( ) { $ namespace = Str :: replaceLast ( '\\' , '' , $ this -> getAppNamespace ( ) ) ; $ appConfig = file_get_contents ( config_path ( 'app.php' ) ) ; if ( Str :: contains ( $ appConfig , $ namespace . '\\Providers\\HorizonServiceProvider::class' ) ) { return ; } file_p... | Register the Horizon service provider in the application configuration file . |
41,445 | protected function restart ( ) { if ( $ this -> process -> isStarted ( ) ) { event ( new WorkerProcessRestarting ( $ this ) ) ; } $ this -> start ( $ this -> output ) ; } | Restart the process . |
41,446 | protected function sendSignal ( $ signal ) { try { $ this -> process -> signal ( $ signal ) ; } catch ( ExceptionInterface $ e ) { if ( $ this -> process -> isRunning ( ) ) { throw $ e ; } } } | Send a POSIX signal to the process . |
41,447 | protected function cooldown ( ) { if ( $ this -> coolingDown ( ) ) { return ; } if ( $ this -> restartAgainAt ) { $ this -> restartAgainAt = ! $ this -> process -> isRunning ( ) ? Chronos :: now ( ) -> addMinute ( ) : null ; if ( ! $ this -> process -> isRunning ( ) ) { event ( new UnableToLaunchProcess ( $ this ) ) ; ... | Begin the cool - down period for the process . |
41,448 | protected function scaleUp ( $ processes ) { $ difference = $ processes - count ( $ this -> processes ) ; for ( $ i = 0 ; $ i < $ difference ; $ i ++ ) { $ this -> start ( ) ; } } | Scale up to the given number of processes . |
41,449 | protected function scaleDown ( $ processes ) { $ difference = count ( $ this -> processes ) - $ processes ; $ terminatingProcesses = array_slice ( $ this -> processes , 0 , $ difference ) ; collect ( $ terminatingProcesses ) -> each ( function ( $ process ) { $ this -> markForTermination ( $ process ) ; } ) -> all ( ) ... | Scale down to the given number of processes . |
41,450 | protected function removeProcesses ( $ count ) { array_splice ( $ this -> processes , 0 , $ count ) ; $ this -> processes = array_values ( $ this -> processes ) ; } | Remove the given number of processes from the process array . |
41,451 | protected function start ( ) { $ this -> processes [ ] = $ this -> createProcess ( ) -> handleOutputUsing ( function ( $ type , $ line ) { call_user_func ( $ this -> output , $ type , $ line ) ; } ) ; return $ this ; } | Add a new worker process to the pool . |
41,452 | protected function createProcess ( ) { $ class = config ( 'horizon.fast_termination' ) ? BackgroundProcess :: class : Process :: class ; return new WorkerProcess ( $ class :: fromShellCommandline ( $ this -> options -> toWorkerCommand ( ) , $ this -> options -> directory ) -> setTimeout ( null ) -> disableOutput ( ) ) ... | Create a new process instance . |
41,453 | public function restart ( ) { $ count = count ( $ this -> processes ) ; $ this -> scale ( 0 ) ; $ this -> scale ( $ count ) ; } | Terminate all current workers and start fresh ones . |
41,454 | public function pruneTerminatingProcesses ( ) { $ this -> stopTerminatingProcessesThatAreHanging ( ) ; $ this -> terminatingProcesses = collect ( $ this -> terminatingProcesses ) -> filter ( function ( $ process ) { return $ process [ 'process' ] -> isRunning ( ) ; } ) -> all ( ) ; } | Remove any non - running processes from the terminating process list . |
41,455 | protected function stopTerminatingProcessesThatAreHanging ( ) { foreach ( $ this -> terminatingProcesses as $ process ) { $ timeout = $ this -> options -> timeout ; if ( $ process [ 'terminatedAt' ] -> addSeconds ( $ timeout ) -> lte ( Chronos :: now ( ) ) ) { $ process [ 'process' ] -> stop ( ) ; } } } | Stop any terminating processes that are hanging too long . |
41,456 | public function push ( $ name , $ command , array $ options = [ ] ) { $ this -> connection ( ) -> rpush ( 'commands:' . $ name , json_encode ( [ 'command' => $ command , 'options' => $ options , ] ) ) ; } | Push a command onto a given queue . |
41,457 | public function pending ( $ name ) { $ length = $ this -> connection ( ) -> llen ( 'commands:' . $ name ) ; if ( $ length < 1 ) { return [ ] ; } $ results = $ this -> connection ( ) -> pipeline ( function ( $ pipe ) use ( $ name , $ length ) { $ pipe -> lrange ( 'commands:' . $ name , 0 , $ length - 1 ) ; $ pipe -> ltr... | Get the pending commands for a given queue name . |
41,458 | public function via ( $ notifiable ) { return array_filter ( [ Horizon :: $ slackWebhookUrl ? 'slack' : null , Horizon :: $ smsNumber ? 'nexmo' : null , Horizon :: $ email ? 'mail' : null , ] ) ; } | Get the notification s delivery channels . |
41,459 | public function after ( TestEvent $ e ) { $ seconds_input = $ e -> getTime ( ) ; $ seconds = ( int ) ( $ milliseconds = ( int ) ( $ seconds_input * 1000 ) ) / 1000 ; $ time = ( $ seconds % 60 ) . ( ( $ milliseconds === 0 ) ? '' : '.' . $ milliseconds ) ; $ this -> write ( Descriptor :: getTestSignature ( $ e -> getTest... | we are printing test status and time taken |
41,460 | public function seeEventTriggered ( $ events ) { $ events = is_array ( $ events ) ? $ events : func_get_args ( ) ; foreach ( $ events as $ event ) { if ( ! $ this -> client -> eventTriggered ( $ event ) ) { if ( is_object ( $ event ) ) { $ event = get_class ( $ event ) ; } $ this -> fail ( "The '$event' event did not t... | Make sure events fired during the test . |
41,461 | public function callArtisan ( $ command , $ parameters = [ ] , OutputInterface $ output = null ) { $ console = $ this -> app -> make ( 'Illuminate\Contracts\Console\Kernel' ) ; if ( ! $ output ) { $ console -> call ( $ command , $ parameters ) ; $ output = trim ( $ console -> output ( ) ) ; $ this -> debug ( $ output )... | Call an Artisan command . |
41,462 | public function amOnAction ( $ action , $ params = [ ] ) { $ route = $ this -> getRouteByAction ( $ action ) ; $ absolute = ! is_null ( $ route -> domain ( ) ) ; $ url = $ this -> app [ 'url' ] -> action ( $ action , $ params , $ absolute ) ; $ this -> amOnPage ( $ url ) ; } | Opens web page by action name |
41,463 | public function seeCurrentActionIs ( $ action ) { $ this -> getRouteByAction ( $ action ) ; $ currentRoute = $ this -> app -> request -> route ( ) ; $ currentAction = $ currentRoute ? $ currentRoute -> getActionName ( ) : '' ; $ currentAction = ltrim ( str_replace ( $ this -> getRootControllerNamespace ( ) , "" , $ cur... | Checks that current url matches action |
41,464 | protected function getRootControllerNamespace ( ) { $ urlGenerator = $ this -> app [ 'url' ] ; $ reflection = new \ ReflectionClass ( $ urlGenerator ) ; $ property = $ reflection -> getProperty ( 'rootNamespace' ) ; $ property -> setAccessible ( true ) ; return $ property -> getValue ( $ urlGenerator ) ; } | Get the root controller namespace for the application . |
41,465 | public function seeFormHasErrors ( ) { $ viewErrorBag = $ this -> app -> make ( 'view' ) -> shared ( 'errors' ) ; $ this -> assertGreaterThan ( 0 , count ( $ viewErrorBag ) , 'Expecting that the form has errors, but there were none!' ) ; } | Assert that form errors are bound to the View . |
41,466 | public function dontSeeFormErrors ( ) { $ viewErrorBag = $ this -> app -> make ( 'view' ) -> shared ( 'errors' ) ; $ this -> assertEquals ( 0 , count ( $ viewErrorBag ) , 'Expecting that the form does not have errors, but there were!' ) ; } | Assert that there are no form errors bound to the View . |
41,467 | public function seeFormErrorMessages ( array $ bindings ) { foreach ( $ bindings as $ key => $ value ) { $ this -> seeFormErrorMessage ( $ key , $ value ) ; } } | Assert that specific form error messages are set in the view . |
41,468 | public function seeFormErrorMessage ( $ key , $ expectedErrorMessage = null ) { $ viewErrorBag = $ this -> app [ 'view' ] -> shared ( 'errors' ) ; if ( ! ( $ viewErrorBag -> has ( $ key ) ) ) { $ this -> fail ( "No form error message for key '$key'\n" ) ; } if ( ! is_null ( $ expectedErrorMessage ) ) { $ this -> assert... | Assert that a specific form error message is set in the view . |
41,469 | public function amLoggedAs ( $ user , $ driver = null ) { $ guard = $ auth = $ this -> app [ 'auth' ] ; if ( method_exists ( $ auth , 'driver' ) ) { $ guard = $ auth -> driver ( $ driver ) ; } if ( method_exists ( $ auth , 'guard' ) ) { $ guard = $ auth -> guard ( $ driver ) ; } if ( $ user instanceof Authenticatable )... | Set the currently logged in user for the application . Takes either an object that implements the User interface or an array of credentials . |
41,470 | public function seeAuthentication ( $ guard = null ) { $ auth = $ this -> app [ 'auth' ] ; if ( method_exists ( $ auth , 'guard' ) ) { $ auth = $ auth -> guard ( $ guard ) ; } $ this -> assertTrue ( $ auth -> check ( ) , 'There is no authenticated user' ) ; } | Checks that a user is authenticated . You can specify the guard that should be use for Laravel > = 5 . 2 . |
41,471 | public function dontSeeAuthentication ( $ guard = null ) { $ auth = $ this -> app [ 'auth' ] ; if ( method_exists ( $ auth , 'guard' ) ) { $ auth = $ auth -> guard ( $ guard ) ; } $ this -> assertNotTrue ( $ auth -> check ( ) , 'There is an user authenticated' ) ; } | Check that user is not authenticated . You can specify the guard that should be use for Laravel > = 5 . 2 . |
41,472 | public function haveRecord ( $ table , $ attributes = [ ] ) { if ( class_exists ( $ table ) ) { $ model = new $ table ; if ( ! $ model instanceof EloquentModel ) { throw new \ RuntimeException ( "Class $table is not an Eloquent model" ) ; } $ model -> fill ( $ attributes ) -> save ( ) ; return $ model ; } try { return ... | Inserts record into the database . If you pass the name of a database table as the first argument this method returns an integer ID . You can also pass the class name of an Eloquent model in that case this method returns an Eloquent model . |
41,473 | public function grabRecord ( $ table , $ attributes = [ ] ) { if ( class_exists ( $ table ) ) { if ( ! $ model = $ this -> findModel ( $ table , $ attributes ) ) { $ this -> fail ( "Could not find $table with " . json_encode ( $ attributes ) ) ; } return $ model ; } if ( ! $ record = $ this -> findRecord ( $ table , $ ... | Retrieves record from database If you pass the name of a database table as the first argument this method returns an array . You can also pass the class name of an Eloquent model in that case this method returns an Eloquent model . |
41,474 | public function seeNumRecords ( $ expectedNum , $ table , $ attributes = [ ] ) { if ( class_exists ( $ table ) ) { $ currentNum = $ this -> countModels ( $ table , $ attributes ) ; $ this -> assertEquals ( $ expectedNum , $ currentNum , "The number of found {$table} ({$currentNum}) does not match expected number {$expe... | Checks that number of given records were found in database . You can pass the name of a database table or the class name of an Eloquent model as the first argument . |
41,475 | public function grabNumRecords ( $ table , $ attributes = [ ] ) { return class_exists ( $ table ) ? $ this -> countModels ( $ table , $ attributes ) : $ this -> countRecords ( $ table , $ attributes ) ; } | Retrieves number of records from database You can pass the name of a database table or the class name of an Eloquent model as the first argument . |
41,476 | public function haveMultiple ( $ model , $ times , $ attributes = [ ] , $ name = 'default' ) { try { return $ this -> modelFactory ( $ model , $ name , $ times ) -> create ( $ attributes ) ; } catch ( \ Exception $ e ) { $ this -> fail ( "Could not create model: \n\n" . get_class ( $ e ) . "\n\n" . $ e -> getMessage ( ... | Use Laravel s model factory to create multiple models . Can only be used with Laravel 5 . 1 and later . |
41,477 | protected function getInternalDomains ( ) { $ internalDomains = [ $ this -> getApplicationDomainRegex ( ) ] ; foreach ( $ this -> app [ 'routes' ] as $ route ) { if ( ! is_null ( $ route -> domain ( ) ) ) { $ internalDomains [ ] = $ this -> getDomainRegex ( $ route ) ; } } return array_unique ( $ internalDomains ) ; } | Returns a list of recognized domain names . This elements of this list are regular expressions . |
41,478 | private function getDomainRegex ( $ route ) { ReflectionHelper :: invokePrivateMethod ( $ route , 'compileRoute' ) ; $ compiledRoute = ReflectionHelper :: readPrivateProperty ( $ route , 'compiled' ) ; return $ compiledRoute -> getHostRegex ( ) ; } | Get the regex for matching the domain part of this route . |
41,479 | private function buildQuery ( $ table , $ attributes = [ ] ) { if ( class_exists ( $ table ) ) { $ query = $ this -> getQueryBuilderFromModel ( $ table ) ; } else { $ query = $ this -> getQueryBuilderFromTable ( $ table ) ; } foreach ( $ attributes as $ key => $ value ) { if ( \ is_array ( $ value ) ) { call_user_func_... | Build Eloquent query with attributes |
41,480 | public function fromArray ( array $ actions ) { foreach ( $ actions as $ action => $ arguments ) { $ this -> addAction ( $ action , $ arguments ) ; } return $ this ; } | Creates action sequence from associative array where key is action and value is action arguments |
41,481 | public function run ( $ context ) { foreach ( $ this -> actions as $ step ) { codecept_debug ( "- $step" ) ; try { call_user_func_array ( [ $ context , $ step -> getAction ( ) ] , $ step -> getArguments ( ) ) ; } catch ( \ Exception $ e ) { $ class = get_class ( $ e ) ; throw new $ class ( $ e -> getMessage ( ) . "\nat... | Executes sequence of action as methods of passed object . |
41,482 | protected function runIncludedSuites ( $ suites , $ parent_dir ) { foreach ( $ suites as $ relativePath ) { $ current_dir = rtrim ( $ parent_dir , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . $ relativePath ; $ config = Configuration :: config ( $ current_dir ) ; $ suites = Configuration :: suites ( ) ; $ namespace = ... | Runs included suites recursively |
41,483 | protected function addMetaStep ( $ step , $ stack ) { if ( ( $ this -> isTestFile ( $ this -> file ) ) || ( $ step [ 'class' ] == 'Codeception\Scenario' ) ) { return ; } $ i = count ( $ stack ) - self :: STACK_POSITION - 1 ; while ( isset ( $ stack [ $ i ] ) ) { $ step = $ stack [ $ i ] ; $ i -- ; if ( ! isset ( $ step... | If steps are combined into one method they can be reproduced as meta - step . We are using stack trace to analyze if steps were called from test if not - they were called from meta - step . |
41,484 | public function runShellCommand ( $ command , $ failNonZero = true ) { $ data = [ ] ; exec ( "$command" , $ data , $ resultCode ) ; $ this -> result = $ resultCode ; $ this -> output = implode ( "\n" , $ data ) ; if ( $ this -> output === null ) { \ PHPUnit \ Framework \ Assert :: fail ( "$command can't be executed" ) ... | Executes a shell command . Fails If exit code is > 0 . You can disable this by setting second parameter to false |
41,485 | public function dontSeeInShellOutput ( $ text ) { $ this -> debug ( $ this -> output ) ; \ PHPUnit \ Framework \ Assert :: assertNotContains ( $ text , $ this -> output ) ; } | Checks that output from latest command doesn t contain text |
41,486 | public function seeHttpHeaderOnce ( $ name ) { $ headers = $ this -> getRunningClient ( ) -> getInternalResponse ( ) -> getHeader ( $ name , false ) ; $ this -> assertCount ( 1 , $ headers ) ; } | Checks that http response header is received only once . HTTP RFC2616 allows multiple response headers with the same name . You can check that you didn t accidentally sent the same header twice . |
41,487 | public function grabHttpHeader ( $ name , $ first = true ) { return $ this -> getRunningClient ( ) -> getInternalResponse ( ) -> getHeader ( $ name , $ first ) ; } | Returns the value of the specified header name |
41,488 | public function amAWSAuthenticated ( $ additionalAWSConfig = [ ] ) { if ( method_exists ( $ this -> client , 'setAwsAuth' ) ) { $ config = array_merge ( $ this -> config [ 'aws' ] , $ additionalAWSConfig ) ; if ( ! isset ( $ config [ 'key' ] ) ) { throw new ConfigurationException ( 'AWS Key is not set' ) ; } if ( ! iss... | Allows to send REST request using AWS Authorization |
41,489 | private function setHeaderLink ( array $ linkEntries ) { $ values = [ ] ; foreach ( $ linkEntries as $ linkEntry ) { \ PHPUnit \ Framework \ Assert :: assertArrayHasKey ( 'uri' , $ linkEntry , 'linkEntry should contain property "uri"' ) ; \ PHPUnit \ Framework \ Assert :: assertArrayHasKey ( 'link-param' , $ linkEntry ... | Sets Headers Link as one header Link based on linkEntries |
41,490 | public function seeResponseIsJson ( ) { $ responseContent = $ this -> connectionModule -> _getResponseContent ( ) ; \ PHPUnit \ Framework \ Assert :: assertNotEquals ( '' , $ responseContent , 'response is empty' ) ; json_decode ( $ responseContent ) ; $ errorCode = json_last_error ( ) ; $ errorMessage = json_last_erro... | Checks whether last response was valid JSON . This is done with json_last_error function . |
41,491 | public function dontSeeResponseJsonMatchesXpath ( $ xpath ) { $ response = $ this -> connectionModule -> _getResponseContent ( ) ; $ this -> assertEquals ( 0 , ( new JsonArray ( $ response ) ) -> filterByXPath ( $ xpath ) -> length , "Received JSON matched the XPath `$xpath`.\nJson Response: \n" . $ response ) ; } | Opposite to seeResponseJsonMatchesXpath |
41,492 | public function dontSeeResponseJsonMatchesJsonPath ( $ jsonPath ) { $ response = $ this -> connectionModule -> _getResponseContent ( ) ; $ this -> assertEmpty ( ( new JsonArray ( $ response ) ) -> filterByJsonPath ( $ jsonPath ) , "Received JSON matched the JsonPath `$jsonPath`.\nJson Response: \n" . $ response ) ; } | Opposite to seeResponseJsonMatchesJsonPath |
41,493 | public function dontSeeResponseContainsJson ( $ json = [ ] ) { $ jsonResponseArray = new JsonArray ( $ this -> connectionModule -> _getResponseContent ( ) ) ; $ this -> assertFalse ( $ jsonResponseArray -> containsArray ( $ json ) , "Response JSON contains provided JSON\n" . "- <info>" . var_export ( $ json , true ) . ... | Opposite to seeResponseContainsJson |
41,494 | public function seeResponseMatchesJsonType ( array $ jsonType , $ jsonPath = null ) { $ jsonArray = new JsonArray ( $ this -> connectionModule -> _getResponseContent ( ) ) ; if ( $ jsonPath ) { $ jsonArray = $ jsonArray -> filterByJsonPath ( $ jsonPath ) ; } \ PHPUnit \ Framework \ Assert :: assertThat ( $ jsonArray , ... | Checks that Json matches provided types . In case you don t know the actual values of JSON data returned you can match them by type . Starts check with a root element . If JSON data is array it will check the first element of an array . You can specify the path in the json which should be checked with JsonPath |
41,495 | public function seeResponseIsXml ( ) { libxml_use_internal_errors ( true ) ; $ doc = simplexml_load_string ( $ this -> connectionModule -> _getResponseContent ( ) ) ; $ num = "" ; $ title = "" ; if ( $ doc === false ) { $ error = libxml_get_last_error ( ) ; $ num = $ error -> code ; $ title = trim ( $ error -> message ... | Checks whether last response was valid XML . This is done with libxml_get_last_error function . |
41,496 | public function seeXmlResponseMatchesXpath ( $ xpath ) { $ structure = new XmlStructure ( $ this -> connectionModule -> _getResponseContent ( ) ) ; $ this -> assertTrue ( $ structure -> matchesXpath ( $ xpath ) , 'xpath not matched' ) ; } | Checks whether XML response matches XPath |
41,497 | public function dontSeeXmlResponseMatchesXpath ( $ xpath ) { $ structure = new XmlStructure ( $ this -> connectionModule -> _getResponseContent ( ) ) ; $ this -> assertFalse ( $ structure -> matchesXpath ( $ xpath ) , 'accidentally matched xpath' ) ; } | Checks whether XML response does not match XPath |
41,498 | public function grabTextContentFromXmlElement ( $ cssOrXPath ) { $ el = ( new XmlStructure ( $ this -> connectionModule -> _getResponseContent ( ) ) ) -> matchElement ( $ cssOrXPath ) ; return $ el -> textContent ; } | Finds and returns text contents of element . Element is matched by either CSS or XPath |
41,499 | public function dontSeeXmlResponseEquals ( $ xml ) { \ PHPUnit \ Framework \ Assert :: assertXmlStringNotEqualsXmlString ( $ this -> connectionModule -> _getResponseContent ( ) , $ xml ) ; } | Checks XML response does not equal to provided XML . Comparison is done by canonicalizing both xml s . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.