Last active
May 26, 2017 22:46
-
-
Save MarceloBonifazio/733702fc87d9997a443cc11bcaf21693 to your computer and use it in GitHub Desktop.
Teste com limite para que função que faz uma requisição em um serviço terceiro traga um retorno valido
This file contains hidden or 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 | |
$controle = 1; | |
for($i = 1; $i <= 100; $i++){ | |
$retorno = requisicao($i); | |
echo "<div style='background-color:".($retorno == null ? ( $controle == 3 ? "blue; opacity: .6;'>fatal error no retorno $i" : "red; opacity: .6;'>erro no retorno $i" ) : "green; opacity: .6;'>retorno ".$retorno." valido" )."</div><hr/>"; | |
if ($retorno != null || $controle == 3){ | |
$controle = 1; | |
}else{ | |
$i--; | |
$controle++; | |
} | |
} | |
function requisicao($i){ | |
// Retorno randomico | |
return ( rand(0,1) ? $i : null ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment