Last active
September 1, 2015 18:51
-
-
Save jonataa/49b31582ace7cc6655b2 to your computer and use it in GitHub Desktop.
Este script implementa uma função de teste simples e sem utilizar framework
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 | |
| // Executa quando o teste falha | |
| function assertFailure($file, $line, $code, $failMsg) | |
| { | |
| echo $failMsg, PHP_EOL; | |
| } | |
| // Faz a asserção do nosso teste | |
| function test($obtido, $esperado) | |
| { | |
| $failMsg = sprintf('Falhou! Obtido: %s / Esperado: %s', | |
| var_export($obtido, true), var_export($esperado, true) | |
| ); | |
| if (! $resultado = $obtido === $esperado) | |
| return assert($resultado, $failMsg); | |
| echo 'Passou!', PHP_EOL; | |
| } | |
| // Set our assert options | |
| assert_options(ASSERT_ACTIVE, true); | |
| assert_options(ASSERT_WARNING, false); | |
| assert_options(ASSERT_BAIL, false); | |
| assert_options(ASSERT_CALLBACK, 'assertFailure'); | |
| test(true, false); // Falhou! Obtido: true / Esperado: false | |
| test(true, true); // Passou! | |
| test(5 > 4, true); // Passou! | |
| test('abc', 'abd'); // Falhou! Obtido: 'abc' / Esperado: 'abd' | |
| echo PHP_EOL, 'Testes Executados com sucesso! :-)'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment