How to use updateFromGithub method of stub class

Best Atoum code snippet using stub.updateFromGithub

stub.php

Source:stub.php Github

copy

Full Screen

...122 ->writeInfo($this->locale->_('atoum version %s by %s (%s)', atoum\version, atoum\author, \phar::running()))123 ;124 return $this->stopRun();125 }126 public function updateFromGithub()127 {128 if ($this->adapter->ini_get('phar.readonly') == true)129 {130 throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\'');131 }132 if ($this->adapter->ini_get('allow_url_fopen') == false)133 {134 throw new exceptions\runtime('Unable to update the PHAR, allow_url_fopen is not set, use \'-d allow_url_fopen=1\'');135 }136 if (($versions = $this->getVersions($currentPhar = call_user_func($this->pharFactory, $this->getName()))) === null)137 {138 throw new exceptions\runtime('Unable to update the PHAR, the versions\'s file is invalid');139 }140 $this->writeMessage($this->locale->_('Checking if a new version is available on Github...'), false);141 $httpContext = stream_context_create(array(142 'http' => array(143 'method' => 'GET',144 'protocol_version' => '1.1',145 'header' => "Accept: */*\r\nUser-Agent:atoum\r\nCache-Control: no-cache"146 )147 ));148 $data = json_decode($this->adapter->file_get_contents(self::githubUpdateUrl, false, $httpContext), true);149 $this150 ->clearMessage()151 ->writeMessage($this->locale->_('Checking if a new version is available Github... Done!' . PHP_EOL))152 ;153 if (is_array($data) === false || sizeof($data) === 0)154 {155 $this->writeInfo($this->locale->_('There is no new version available!'));156 }157 else158 {159 $data = array_filter($data, function ($release) { return $release['draft'] === false; });160 $release = array_shift($data);161 if (is_array($release) === false || isset($release['name']) === false || version_compare($versions[$versions['current']], $release['name']) >= 0)162 {163 $this->writeInfo($this->locale->_('There is no new version available!'));164 }165 else166 {167 $assets = array_filter($release['assets'], function ($asset) { return $asset['name'] === 'atoum.phar'; });168 $asset = array_shift($assets);169 $assetData = json_decode($this->adapter->file_get_contents($asset['url'], false, $httpContext), true);170 if (is_array($assetData) === false || isset($assetData['browser_download_url']) === false)171 {172 $this->writeInfo($this->locale->_('There is no new version available!'));173 }174 else175 {176 $this->downloadPhar($release['name'], $currentPhar, $this->adapter->file_get_contents($assetData['browser_download_url'], false, $httpContext));177 }178 }179 }180 return $this->stopRun();181 }182 public function update()183 {184 if ($this->adapter->ini_get('phar.readonly') == true)185 {186 throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\'');187 }188 if ($this->adapter->ini_get('allow_url_fopen') == false)189 {190 throw new exceptions\runtime('Unable to update the PHAR, allow_url_fopen is not set, use \'-d allow_url_fopen=1\'');191 }192 if (($versions = $this->getVersions($currentPhar = call_user_func($this->pharFactory, $this->getName()))) === null)193 {194 throw new exceptions\runtime('Unable to update the PHAR, the versions\'s file is invalid');195 }196 unset($versions['current']);197 $this->writeMessage($this->locale->_('Checking if a new version is available...'), false);198 $data = json_decode($this->adapter->file_get_contents(sprintf(self::updateUrl, json_encode(array_values($versions)))), true);199 $this200 ->clearMessage()201 ->writeMessage($this->locale->_('Checking if a new version is available... Done!' . PHP_EOL))202 ;203 if (is_array($data) === false || isset($data['version']) === false || isset($data['phar']) === false)204 {205 $this->writeInfo($this->locale->_('There is no new version available!'));206 }207 else208 {209 $this->downloadPhar($data['version'], $currentPhar, utf8_decode($data['phar']));210 }211 return $this->stopRun();212 }213 private function downloadPhar($newVersion, $currentPhar, $newPhar)214 {215 $tmpFile = $this->adapter->realpath($this->adapter->sys_get_temp_dir()) . '/' . md5($newVersion) . '.phar';216 if ($this->adapter->file_put_contents($tmpFile, $newPhar) === false)217 {218 throw new exceptions\runtime('Unable to create temporary file to update to version \'' . $newVersion);219 }220 $this->writeMessage($this->locale->_('Update to version \'%s\'...', $newVersion), false);221 $pharPathLength = strlen($pharPath = 'phar://' . $tmpFile . '/1/');222 $newCurrentDirectory = 1;223 while (isset($versions[$newCurrentDirectory]) === true)224 {225 $newCurrentDirectory++;226 }227 $newFiles = new \arrayIterator();228 foreach (new \recursiveIteratorIterator(new \recursiveDirectoryIterator($pharPath)) as $newFile)229 {230 $newFiles[$newCurrentDirectory . '/' . substr($newFile, $pharPathLength)] = ($newFile = (string) $newFile);231 }232 $currentPhar->buildFromIterator($newFiles);233 $this234 ->clearMessage()235 ->writeMessage($this->locale->_('Update to version \'%s\'... Done!' . PHP_EOL, $newVersion))236 ;237 @$this->adapter->unlink($tmpFile);238 $this->writeMessage($this->locale->_('Enable version \'%s\'...', $newVersion), false);239 $versions[$newCurrentDirectory] = $newVersion;240 $versions['current'] = $newCurrentDirectory;241 $currentPhar['versions'] = serialize($versions);242 $this243 ->clearMessage()244 ->writeMessage($this->locale->_('Enable version \'%s\'... Done!' . PHP_EOL, $newVersion))245 ;246 $this->writeInfo($this->locale->_('Atoum has been updated from version \'%s\' to \'%s\' successfully!', atoum\version, $newVersion));247 }248 public function listAvailableVersions()249 {250 $currentPhar = call_user_func($this->pharFactory, $this->getName());251 if (isset($currentPhar['versions']) === false)252 {253 throw new exceptions\runtime('Unable to list available versions in PHAR, the versions\'s file does not exist');254 }255 $versions = unserialize(file_get_contents($currentPhar['versions']));256 if (is_array($versions) === false || sizeof($versions) <= 0 || isset($versions['current']) === false)257 {258 throw new exceptions\runtime('Unable to list available versions in PHAR, the versions\'s file is invalid');259 }260 $currentDirectory = $versions['current'];261 unset($versions['current']);262 asort($versions);263 foreach ($versions as $directory => $version)264 {265 $this->writeMessage(($directory == $currentDirectory ? '*' : ' ') . ' ' . $version . PHP_EOL);266 }267 return $this->stopRun();268 }269 public function enableVersion($versionName, \phar $phar = null)270 {271 if ($this->adapter->ini_get('phar.readonly') == true)272 {273 throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\'');274 }275 if ($phar === null)276 {277 $phar = call_user_func($this->pharFactory, $this->getName());278 }279 if (($versions = $this->getVersions($phar)) === null)280 {281 throw new exceptions\runtime('Unable to enable version \'' . $versionName . '\', the versions\'s file is invalid');282 }283 $versionDirectory = array_search($versionName, $versions);284 if ($versionDirectory === false)285 {286 throw new exceptions\runtime('Unable to enable version \'' . $versionName . '\' because it does not exist');287 }288 $versions['current'] = $versionDirectory;289 $phar['versions'] = serialize($versions);290 return $this->stopRun();291 }292 public function deleteVersion($versionName, \phar $phar = null)293 {294 if ($this->adapter->ini_get('phar.readonly') == true)295 {296 throw new exceptions\runtime('Unable to update the PHAR, phar.readonly is set, use \'-d phar.readonly=0\'');297 }298 if ($phar === null)299 {300 $phar = call_user_func($this->pharFactory, $this->getName());301 }302 if (($versions = $this->getVersions($phar)) === null)303 {304 throw new exceptions\runtime('Unable to delete version \'' . $versionName . '\', the versions\'s file is invalid');305 }306 $versionDirectory = array_search($versionName, $versions);307 if ($versionDirectory === false)308 {309 throw new exceptions\runtime('Unable to delete version \'' . $versionName . '\' because it does not exist');310 }311 if ($versionDirectory == $versions['current'])312 {313 throw new exceptions\runtime('Unable to delete version \'' . $versionName . '\' because it is the current version');314 }315 unset($versions[$versionDirectory]);316 unset($phar[$versionDirectory]);317 $phar['versions'] = serialize($versions);318 return $this->stopRun();319 }320 public function getResourcesDirectory()321 {322 if (($versions = $this->getVersions($phar = call_user_func($this->pharFactory, $this->getName()))) === null)323 {324 throw new exceptions\runtime('Unable to define resources directory, verions\'s file is invalid');325 }326 if (isset($phar[$versions['current'] . '/resources']) === false)327 {328 throw new exceptions\logic('Resources directory does not exist in PHAR \'' . $this->getName() . '\'');329 }330 return 'phar://' . $this->getName() . '/' . $versions['current'] . '/resources';331 }332 protected function setArgumentHandlers()333 {334 return335 parent::setArgumentHandlers()336 ->addArgumentHandler(337 function($script, $argument, $values) {338 if (sizeof($values) !== 0)339 {340 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));341 }342 $script->infos();343 },344 array('-i', '--infos'),345 null,346 $this->locale->_('Display informations, do not run any script')347 )348 ->addArgumentHandler(349 function($script, $argument, $values) {350 if (sizeof($values) !== 0)351 {352 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));353 }354 $script->signature();355 },356 array('-s', '--signature'),357 null,358 $this->locale->_('Display phar signature, do not run any script')359 )360 ->addArgumentHandler(361 function($script, $argument, $values) {362 if (sizeof($values) !== 1)363 {364 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));365 }366 $script->extractTo($values[0]);367 },368 array('-e', '--extract-to'),369 '<directory>',370 $this->locale->_('Extract all file from phar to <directory>, do not run any script')371 )372 ->addArgumentHandler(373 function($script, $argument, $values) {374 if (sizeof($values) !== 1)375 {376 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));377 }378 $script->extractResourcesTo($values[0]);379 },380 array('-er', '--extract-resources-to'),381 '<directory>',382 $this->locale->_('Extract resources from phar to <directory>, do not run any script')383 )384 ->addArgumentHandler(385 function($script, $argument, $values, $position) {386 if ($position !== 1 || sizeof($values) !== 1)387 {388 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));389 }390 unset($_SERVER['argv'][1]);391 unset($_SERVER['argv'][2]);392 $script->useScript($values[0]);393 },394 array('-u', '--use'),395 '<script> <args>',396 $this->locale->_('Run script <script> from PHAR with <args> as arguments (this argument must be the first)'),397 4398 )399 ->addArgumentHandler(400 function($script, $argument, $values) {401 if (sizeof($values) > 0)402 {403 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));404 }405 $script->listScripts();406 },407 array('-ls', '--list-scripts'),408 null,409 $this->locale->_('List available scripts')410 )411 ->addArgumentHandler(412 function($script, $argument, $values) {413 if (sizeof($values) > 0)414 {415 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));416 }417 $script->update();418 },419 array('--update'),420 null,421 $this->locale->_('Update atoum')422 )423 ->addArgumentHandler(424 function($script, $argument, $values) {425 if (sizeof($values) > 0)426 {427 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));428 }429 $script->updateFromGithub();430 },431 array('--github-update'),432 null,433 $this->locale->_('Update atoum from github')434 )435 ->addArgumentHandler(436 function($script, $argument, $values) {437 if (sizeof($values) > 0)438 {439 throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));440 }441 $script->listAvailableVersions();442 },443 array('-lav', '--list-available-versions'),...

Full Screen

Full Screen

updateFromGithub

Using AI Code Generation

copy

Full Screen

1$stub->updateFromGithub();2$stub->updateFromGithub();3$stub->updateFromGithub();4$stub->updateFromGithub();5$stub->updateFromGithub();6$stub->updateFromGithub();7$stub->updateFromGithub();8$stub->updateFromGithub();9$stub->updateFromGithub();10$stub->updateFromGithub();11$stub->updateFromGithub();12$stub->updateFromGithub();13$stub->updateFromGithub();14$stub->updateFromGithub();15$stub->updateFromGithub();16$stub->updateFromGithub();17$stub->updateFromGithub();18$stub->updateFromGithub();19$stub->updateFromGithub();

Full Screen

Full Screen

updateFromGithub

Using AI Code Generation

copy

Full Screen

1$github = new Github();2$github->updateFromGithub();3$github = new Github();4$github->updateFromGithub();5$github = new Github();6$github->updateFromGithub();7$github = new Github();8$github->updateFromGithub();9$github = new Github();10$github->updateFromGithub();11$github = new Github();12$github->updateFromGithub();13$github = new Github();14$github->updateFromGithub();15$github = new Github();16$github->updateFromGithub();17$github = new Github();18$github->updateFromGithub();19$github = new Github();20$github->updateFromGithub();21$github = new Github();22$github->updateFromGithub();23$github = new Github();24$github->updateFromGithub();25$github = new Github();26$github->updateFromGithub();27$github = new Github();28$github->updateFromGithub();29$github = new Github();30$github->updateFromGithub();31$github = new Github();32$github->updateFromGithub();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger updateFromGithub code on LambdaTest Cloud Grid

Execute automation tests with updateFromGithub on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful