Last active
January 30, 2017 08:17
-
-
Save mustafaileri/a535862c7aca1c761a8b7f8937ed31a0 to your computer and use it in GitHub Desktop.
Spin metodu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Behat\MinkExtension\Context\MinkContext; | |
class BaseContext extends MinkContext | |
{ | |
/** | |
* @param $closure | |
* @param int $tries | |
* @return mixed | |
* @throws Exception | |
*/ | |
public function spins($closure, $tries = 40) | |
{ | |
for ($i = 0; $i <= $tries; $i++) { | |
try { | |
$closureResult = $closure(); | |
return $closureResult; | |
} catch (Exception $e) { | |
if ($i == $tries) { | |
throw $e; | |
} | |
} | |
usleep(250000); | |
} | |
} | |
public function sampleSpinsUsage() | |
{ | |
$this->spins(function () { | |
//do something... | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment