Skip to content

Instantly share code, notes, and snippets.

@mustafaileri
Last active January 30, 2017 08:17
Show Gist options
  • Save mustafaileri/a535862c7aca1c761a8b7f8937ed31a0 to your computer and use it in GitHub Desktop.
Save mustafaileri/a535862c7aca1c761a8b7f8937ed31a0 to your computer and use it in GitHub Desktop.
Spin metodu
<?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