Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Automatizando testes com PHPUnit

Automatizando testes com PHPUnit

Uma breve descrição do que são testes automatizados e como o PHPUnit pode ser utilizado no seu dia a dia.

Augusto Pascutti

September 01, 2017
Tweet

More Decks by Augusto Pascutti

Other Decks in Technology

Transcript

  1. 1 $ php hello.php 2 Hello World! 3 $ echo

    $? 4 0 “EXIT CODE” DO COMANDO ANTERIOR
  2. 1 $ php hello.php 2 Hello World! 3 $ echo

    $? 4 0 QUALQUER OUTRA COISA É UMA FALHA
  3. 1 <?php 2 3 $programs = [ 4 __DIR__ .

    '/hello.php' 5 ]; 6 7 foreach ($programs as $program) { 8 $output = ''; 9 $exitCode = 255; 10 $test = 'php ' . $program; 11 $lastLine = exec($test, $output, $exitCode); 12 echo ($exitCode === 0) ? '.' : 'E' ; 13 } 14 15 echo PHP_EOL ;
  4. 1 <?php 2 3 $programs = [ 4 __DIR__ .

    '/hello.php' 5 ]; 6 7 foreach ($programs as $program) { 8 $output = ''; 9 $exitCode = 255; 10 $test = 'php ' . $program; 11 $lastLine = exec($test, $output, $exitCode); 12 echo ($exitCode === 0) ? '.' : 'E' ; 13 } 14 15 echo PHP_EOL ; LISTA DE PROGRAMAS QUE QUEREMOS TESTAR
  5. 1 <?php 2 3 $programs = [ 4 __DIR__ .

    '/hello.php' 5 ]; 6 7 foreach ($programs as $program) { 8 $output = ''; 9 $exitCode = 255; 10 $test = 'php ' . $program; 11 $lastLine = exec($test, $output, $exitCode); 12 echo ($exitCode === 0) ? '.' : 'E' ; 13 } 14 15 echo PHP_EOL ; PARA CADA PROGRAMA
  6. 1 <?php 2 3 $programs = [ 4 __DIR__ .

    '/hello.php' 5 ]; 6 7 foreach ($programs as $program) { 8 $output = ''; 9 $exitCode = 255; 10 $test = 'php ' . $program; 11 $lastLine = exec($test, $output, $exitCode); 12 echo ($exitCode === 0) ? '.' : 'E' ; 13 } 14 15 echo PHP_EOL ; COMANDO A SER EXECUTADO
  7. 1 <?php 2 3 $programs = [ 4 __DIR__ .

    '/hello.php' 5 ]; 6 7 foreach ($programs as $program) { 8 $output = ''; 9 $exitCode = 255; 10 $test = 'php ' . $program; 11 $lastLine = exec($test, $output, $exitCode); 12 echo ($exitCode === 0) ? '.' : 'E' ; 13 } 14 15 echo PHP_EOL ; EXECUTA A BOMBA
  8. 1 <?php 2 3 $programs = [ 4 __DIR__ .

    '/hello.php' 5 ]; 6 7 foreach ($programs as $program) { 8 $output = ''; 9 $exitCode = 255; 10 $test = 'php ' . $program; 11 $lastLine = exec($test, $output, $exitCode); 12 echo ($exitCode === 0) ? '.' : 'E' ; 13 } 14 15 echo PHP_EOL ; IMPRIME UM RESULTADO PRA CADA PROGRAMA TESTADO.
  9. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449
  10. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 LISTA ARTIGOS E FILTRA
  11. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 O PIPE PASSA OS RESULTADOS DO COMANDO ANTERIOR PRO SEGUINTE
  12. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 IMPRIME ARTIGOS COM MENOS DE 1.350 PALAVRAS
  13. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449
  14. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 RECEITA PARA UMA CAGADA LITERÁRIA
  15. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 USA O ID DO ARTIGO PARA DEFINIR A TAG NO POCKET
  16. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 USA O ID DO ARTIGO PARA DEFINIR A TAG NO POCKET
  17. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 10 $ echo $? 11 0
  18. 1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

    3 $ php reading-dump.php pocket-retrieve | \ 4 php reading-dump.php filter-reading-time 5 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 10 $ echo $? 11 0
  19. GREP -B 2 EXIT SRC/*.PHP E ALÉM DA LINHA COM

    MATCH, TRAZ DUAS LINHAS ANTERIORES
  20. 1 src/filter-reading-time.php- } catch (PocketException $e) { 2 src/filter-reading-time.php- echo

    $e->getMessage() . PHP_EOL; 3 src/filter-reading-time.php- } 4 src/filter-reading-time.php: exit(2); 5 -- 6 src/help.php:exit(1); 7 -- 8 src/pocket-retrieve.php- echo 'Not available'; 9 src/pocket-retrieve.php: exit(2); 10 -- 11 src/pocket-retrieve.php- } catch (PocketException $e) { 12 src/pocket-retrieve.php- echo $e->getMessage() . PHP_EOL; 13 src/pocket-retrieve.php- } 14 src/pocket-retrieve.php: exit(2);
  21. 1 src/filter-reading-time.php- } catch (PocketException $e) { 2 src/filter-reading-time.php- echo

    $e->getMessage() . PHP_EOL; 3 src/filter-reading-time.php- } 4 src/filter-reading-time.php: exit(2); 5 -- 6 src/help.php:exit(1); 7 -- 8 src/pocket-retrieve.php- echo 'Not available'; 9 src/pocket-retrieve.php: exit(2); 10 -- 11 src/pocket-retrieve.php- } catch (PocketException $e) { 12 src/pocket-retrieve.php- echo $e->getMessage() . PHP_EOL; 13 src/pocket-retrieve.php- } 14 src/pocket-retrieve.php: exit(2);
  22. 16 src/pocket-retrieve.php- if (isset($items['error']) && count($items['error'])) { 17 src/pocket-retrieve.php- echo

    "Unknown error retrieving articles." . PHP_EOL; 18 src/pocket-retrieve.php: exit(2); 19 -- 20 src/pocket-save.php- } catch (PocketException $e) { 21 src/pocket-save.php- echo $e->getMessage() . PHP_EOL; 22 src/pocket-save.php- } 23 src/pocket-save.php: exit(2); 24 -- 25 src/pocket-tag.php- if (count($lineColumns) < 3) { 26 src/pocket-tag.php- echo 'Error: Needed 3 columns on line.’ . PHP_EOL . $line; 27 src/pocket-tag.php: exit(2); 28 -- 29 src/pocket-tag.php- echo 'Not available'; 30 src/pocket-tag.php: exit(2);
  23. 16 src/pocket-retrieve.php- if (isset($items['error']) && count($items['error'])) { 17 src/pocket-retrieve.php- echo

    "Unknown error retrieving articles." . PHP_EOL; 18 src/pocket-retrieve.php: exit(2); 19 -- 20 src/pocket-save.php- } catch (PocketException $e) { 21 src/pocket-save.php- echo $e->getMessage() . PHP_EOL; 22 src/pocket-save.php- } 23 src/pocket-save.php: exit(2); 24 -- 25 src/pocket-tag.php- if (count($lineColumns) < 3) { 26 src/pocket-tag.php- echo 'Error: Needed 3 columns on line.’ . PHP_EOL . $line; 27 src/pocket-tag.php: exit(2); 28 -- 29 src/pocket-tag.php- echo 'Not available'; 30 src/pocket-tag.php: exit(2);
  24. 1 Reading Dump Test Suite 2 3 [x] 'test/pocket-tag-using-pipes.php' 4

    [x] 'test/readme-example.php' 5 [x] 'test/retrieve-without-arguments.php' 6 [x] 'test/save-article-without-url.php' 7 [x] 'test/save-article.php' 8 9 10 Executed in 3.703507 seconds. 11 5 total tests, with 5 successes and 0 failures.
  25. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0;
  26. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0; DRAGÕES
  27. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0; VALORES PADRÃO QUE GARANTEM QUE O TESTE FALHE SE NADA DER CERTO
  28. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0; O COMANDO QUE VAMOS TESTAR
  29. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0; EXECUTA A BOMBA
  30. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0; RETORNA “TRUE” SE O “EXIT-CODE” FOR ZERO
  31. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL,
  32. 1 Reading Dump Test Suite 2 3 [x] 'test/pocket-tag-using-pipes.php' 4

    [x] 'test/readme-example.php' 5 [x] 'test/retrieve-without-arguments.php' 6 [x] 'test/save-article-without-url.php' 7 [x] 'test/save-article.php' 8 9 10 Executed in 3.703507 seconds. 11 5 total tests, with 5 successes and 0 failures.
  33. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL,
  34. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL, LISTA TODOS NOSSOS TESTES
  35. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL, IGNORA O QUE NÃO FOR UM TESTE
  36. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL, EXECUTA O TESTE
  37. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL, FUNÇÃO QUE TESTA
  38. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL, UM ARQUIVO
  39. 3 $total = $success = $failure = 0; 4 $executeTest

    = function($file) use (&$total, &$success, &$failure) 5 { 21 }; 22 23 echo 'Reading Dump Test Suite' . PHP_EOL . PHP_EOL ; 24 25 $starTime = microtime(true); 27 foreach (glob('test/*.php') as $file) { 28 if ($file == 'test/bootstrap.php') { 29 continue; 30 } 31 32 $executeTest($file); 33 } 35 $endTime = microtime(true); 36 $totalTime = $endTime - $starTime ; 37 echo PHP_EOL . PHP_EOL ; 38 echo 'Executed in ' . number_format($totalTime, 6) . ' seconds.' . PHP_EOL; 39 echo sprintf( 40 '%s total tests, with %s successes and %s failures.' . PHP_EOL, E ALIMENTA O STATUS DA NOSSA SUITE
  40. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 };
  41. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; IMPEDE QUE O OUTPUT DO TESTE SEJA EXIBIDO
  42. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; INTERPRETA O ARQUIVO DE TESTE
  43. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $command = "php reading-dump.php pocket-retrieve"; 9 10 exec($command, $output, $exitCode); 11 var_dump($exitCode, $output); 12 13 return $exitCode === 0; LEMBRA DESSE CARA?
  44. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; OLHA ELE AQUI!
  45. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; GUARDA O OUTPUT DO TESTE, SE HOUVER
  46. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; TESTE++
  47. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; DEU BOM
  48. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; SE DEU RUIM, EXIBE O OUTPUT DO TESTE PARA DEBUG
  49. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; BOM
  50. 4 $executeTest = function($file) use (&$total, &$success, &$failure) 5 {

    6 ob_start(); 7 $isSuccess = require $file; 8 $testOutput = ob_get_clean(); 9 10 $total++; 11 if ($isSuccess) { 12 echo "[x] '$file'" . PHP_EOL; 13 $success++; 14 } else { 15 echo PHP_EOL . '[ ] ' . $file . PHP_EOL; 16 echo str_repeat('-', 80) . PHP_EOL; 17 echo $testOutput . PHP_EOL; 18 echo str_repeat('-', 80) . PHP_EOL; 19 $failure++; 20 } 21 }; RUIM
  51. Reading Dump Test Suite [x] 'test/pocket-tag-using-pipes.php' [x] 'test/readme-example.php' [x] 'test/retrieve-without-arguments.php'

    [x] 'test/save-article-without-url.php' [ ] test/save-article.php -------------------------------------------------------------------------------- int(255) Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Option 'url' must have a value' in /p/vendor/augustohp/getopt-php/src/CommandLineParser.php:16 ———————————————————————————————————————— Executed in 2.907382 seconds. 5 total tests, with 4 successes and 1 failures.
  52. Reading Dump Test Suite [x] 'test/pocket-tag-using-pipes.php' [x] 'test/readme-example.php' [x] 'test/retrieve-without-arguments.php'

    [x] 'test/save-article-without-url.php' [ ] test/save-article.php -------------------------------------------------------------------------------- int(255) Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Option 'url' must have a value' in /p/vendor/augustohp/getopt-php/src/CommandLineParser.php:16 ———————————————————————————————————————— Executed in 2.907382 seconds. 5 total tests, with 4 successes and 1 failures. TESTE ZUADO
  53. Reading Dump Test Suite [x] 'test/pocket-tag-using-pipes.php' [x] 'test/readme-example.php' [x] 'test/retrieve-without-arguments.php'

    [x] 'test/save-article-without-url.php' [ ] test/save-article.php -------------------------------------------------------------------------------- int(255) Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Option 'url' must have a value' in /p/vendor/augustohp/getopt-php/src/CommandLineParser.php:16 ———————————————————————————————————————— Executed in 2.907382 seconds. 5 total tests, with 4 successes and 1 failures. EXIT CODE DO COMANDO
  54. Reading Dump Test Suite [x] 'test/pocket-tag-using-pipes.php' [x] 'test/readme-example.php' [x] 'test/retrieve-without-arguments.php'

    [x] 'test/save-article-without-url.php' [ ] test/save-article.php -------------------------------------------------------------------------------- int(255) Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Option 'url' must have a value' in /p/vendor/augustohp/getopt-php/src/CommandLineParser.php:16 ———————————————————————————————————————— Executed in 2.907382 seconds. 5 total tests, with 4 successes and 1 failures. TIPO DE ERRO
  55. Reading Dump Test Suite [x] 'test/pocket-tag-using-pipes.php' [x] 'test/readme-example.php' [x] 'test/retrieve-without-arguments.php'

    [x] 'test/save-article-without-url.php' [ ] test/save-article.php -------------------------------------------------------------------------------- int(255) Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Option 'url' must have a value' in /p/vendor/augustohp/getopt-php/src/CommandLineParser.php:16 ———————————————————————————————————————— Executed in 2.907382 seconds. 5 total tests, with 4 successes and 1 failures. OLHA MÃE! 
 NÓIS DEBUGANDO
  56. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $articleUrl = "https://medium.com/computeiros/shell-sorteando- coisas-como-um-dev-d63bb6e85f3f"; 9 $command = "php reading-dump.php pocket-save --url '$articleUrl'"; 10 11 exec($command, $output, $exitCode); 12 var_dump($exitCode, $output); 13 14 return $exitCode === 0;
  57. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $articleUrl = "https://medium.com/computeiros/shell-sorteando- coisas-como-um-dev-d63bb6e85f3f"; 9 $command = "php reading-dump.php pocket-save --url '$articleUrl'"; 10 11 exec($command, $output, $exitCode); 12 var_dump($exitCode, $output); 13 14 return $exitCode === 0; SALVANDO UM ARTIGO
  58. 1 <?php 2 3 require __DIR__ . '/bootstrap.php'; 4 5

    $exitCode = 255; 6 $output = null; 7 8 $articleUrl = "https://medium.com/computeiros/shell-sorteando- coisas-como-um-dev-d63bb6e85f3f"; 9 $command = "php reading-dump.php pocket-save --url '$articleUrl'"; 10 11 exec($command, $output, $exitCode); 12 var_dump($exitCode, $output); 13 14 return $exitCode === 0; JÁ TA LIGADO NÉ?
  59. 6 $ php reading-dump.php pocket-retrieve | \ 7 php reading-dump.php

    filter-reading-time | \ 8 php reading-dump.php pocket-tag 9 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 10 $ echo $? 11 0
  60. 3 require __DIR__ . '/bootstrap.php'; 4 5 $exitCode = 255;

    6 $output = null; 7 8 $articleUrl = “https://bit.ly/eh-nois“; 9 $command = "php reading-dump.php pocket-save --url '${articleUrl}'"; 10 11 exec($command, $output, $exitCode); 12 if ($exitCode !== 0) { 13 echo 'Problem saving article to tag.'; 14 var_dump($exitCode, $output); 15 return false; // fails test 16 } 17 18 $command = "php reading-dump.php pocket-retrieve | ' . 19 'php reading-dump.php filter-reading-time --less-than-minutes 5 | ' . 20 'php reading-dump.php pocket-tag"; 21 exec($command, $output, $exitCode); 22 var_dump($command, $exitCode, $output); 23 24 return $exitCode === 0;
  61. 3 require __DIR__ . '/bootstrap.php'; 4 5 $exitCode = 255;

    6 $output = null; 7 8 $articleUrl = “https://bit.ly/eh-nois“; 9 $command = "php reading-dump.php pocket-save --url '${articleUrl}'"; 10 11 exec($command, $output, $exitCode); 12 if ($exitCode !== 0) { 13 echo 'Problem saving article to tag.'; 14 var_dump($exitCode, $output); 15 return false; // fails test 16 } 17 18 $command = "php reading-dump.php pocket-retrieve | ' . 19 'php reading-dump.php filter-reading-time --less-than-minutes 5 | ' . 20 'php reading-dump.php pocket-tag"; 21 exec($command, $output, $exitCode); 22 var_dump($command, $exitCode, $output); 23 24 return $exitCode === 0; ADICIONA UM ARTIGO PRA TESTE
  62. 3 require __DIR__ . '/bootstrap.php'; 4 5 $exitCode = 255;

    6 $output = null; 7 8 $articleUrl = “https://bit.ly/eh-nois“; 9 $command = "php reading-dump.php pocket-save --url '${articleUrl}'"; 10 11 exec($command, $output, $exitCode); 12 if ($exitCode !== 0) { 13 echo 'Problem saving article to tag.'; 14 var_dump($exitCode, $output); 15 return false; // fails test 16 } 17 18 $command = "php reading-dump.php pocket-retrieve | ' . 19 'php reading-dump.php filter-reading-time --less-than-minutes 5 | ' . 20 'php reading-dump.php pocket-tag"; 21 exec($command, $output, $exitCode); 22 var_dump($command, $exitCode, $output); 23 24 return $exitCode === 0; SE NÃO ROLAR, PÁRA O TESTE
  63. 3 require __DIR__ . '/bootstrap.php'; 4 5 $exitCode = 255;

    6 $output = null; 7 8 $articleUrl = “https://bit.ly/eh-nois“; 9 $command = "php reading-dump.php pocket-save --url '${articleUrl}'"; 10 11 exec($command, $output, $exitCode); 12 if ($exitCode !== 0) { 13 echo 'Problem saving article to tag.'; 14 var_dump($exitCode, $output); 15 return false; // fails test 16 } 17 18 $command = "php reading-dump.php pocket-retrieve | ' . 19 'php reading-dump.php filter-reading-time | ' . 20 'php reading-dump.php pocket-tag"; 21 exec($command, $output, $exitCode); 22 var_dump($command, $exitCode, $output); 23 24 return $exitCode === 0; TESTA A JAMAICA TODA
  64. 1 Reading Dump Test Suite 2 3 [x] 'test/pocket-tag-using-pipes.php' 4

    [x] 'test/readme-example.php' 5 [x] 'test/retrieve-without-arguments.php' 6 [x] 'test/save-article-without-url.php' 7 [x] 'test/save-article.php' 8 9 10 Executed in 3.703507 seconds. 11 5 total tests, with 5 successes and 0 failures.
  65. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 }
  66. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } PHPUNIT
  67. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } UM GRUPO DE TESTES
  68. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } NOME DO GRUPO
  69. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } UM TESTE
  70. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } AVISA ISSO PRO PHPUNIT
  71. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } NOME DO TESTE
  72. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } SEJA EXPLÍCITO
  73. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 } PROCRASTINA
  74. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 }
  75. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } PHPUNIT
  76. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } NOSSA CLASSE DE TESTES
  77. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } EXECUTADO ANTES DE TODO TESTE
  78. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } IMPEDE QUE O MÉTODO SEJA SOBRESCRITO
  79. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } O QUE PRECISAMOS CONFIGURADO
  80. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } UMA VERIFICAÇÃO
  81. 13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16

    ); O QUE O PHPUNIT EXIBE QUANDO A VERIFICAÇÃO FALHA
  82. 13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16

    ); AJUDA OUTROS DEVS A ENTENDER O QUE DEVERIA TER ACONTECIDO
  83. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } OUTRA VERIFICAÇÃO
  84. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } SALVA O CAMINHO PRO PROGRAMA PRINCIPAL
  85. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } GARANTE QUE QUE EXISTE
  86. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 11 $key = getenv("POCKET_APP_CONSUMER_KEY"); 12 $token = getenv("POCKET_APP_ACCESS_TOKEN"); 13 $this->assertNotEmpty( 14 $key, 15 "Declare POCKET_APP_CONSUMER_KEY environment variable." 16 ); 17 $this->assertNotEmpty( 18 $token, 19 "Declare POCKET_APP_ACCESS_TOKEN environment variable." 20 ); 21 22 $this->programPath = realpath(__DIR__ . '/../../reading-dump.php'); 23 $this->assertFileExists($this->programPath); 24 25 $this->init(); 26 } 40 } LIBERA OUTRO MÉTODO PARA SER USADO COMO SETUP
  87. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 26 } 27 28 protected function renderCommand($command) 29 { 30 return 'php ' . $this->programPath . ' ' . $command; 31 } 32 37 public function init() 38 { 39 } 40 }
  88. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 26 } 27 28 protected function renderCommand($command) 29 { 30 return 'php ' . $this->programPath . ' ' . $command; 31 } 32 37 public function init() 38 { 39 } 40 } DECLARAÇÃO DO NOVO “SETUP”
  89. 5 class IntegrationTest extends \PHPUnit_Framework_TestCase 6 { 7 private $programPath

    = ''; 8 9 final public function setUp() 10 { 26 } 27 28 protected function renderCommand($command) 29 { 30 return 'php ' . $this->programPath . ' ' . $command; 31 } 32 37 public function init() 38 { 39 } 40 } RETORNA O COMANDO A SER EXECUTADO COM O PATH CERTO
  90. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 }
  91. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $this->markTestIncomplete('TODO'); 13 } 14 }
  92. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 }
  93. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 } URL DO ARTIGO
  94. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 } RETORNA O COMANDO COMPLETO
  95. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 } EXECUTA
  96. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 } VERIFICA O EXIT CODE
  97. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 }
  98. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } TESTA UMA FALHA
  99. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } DATA PROVIDER
  100. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } CONECTA O TESTE AO DATA PROVIDER
  101. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } LISTA DE CENÁRIOS
  102. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } NOME DO CENÁRIO
  103. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } UM CENÁRIO = UMA EXECUÇÃO DO TESTE
  104. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } RECEBE UM DADO
  105. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } DAQUI
  106. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 }
  107. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 } COMANDO A SER EXECUTADO
  108. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 } EXECUTA A BOMBA
  109. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 } TRANSFORMA UM ARRAY EM UMA STRING
  110. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 } VERIFICA O EXIT CODE
  111. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 } AGORA TEM QUE DAR RUIM
  112. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 52 $command = $this->renderCommand("pocket-save --url '${url}'"); 53 54 exec($command, $output, $exitCode); 55 $output = implode(PHP_EOL, $output); 56 57 $this->assertEquals( 58 2, 59 $exitCode, 60 "Bad exit code: " . PHP_EOL . $output 61 ); 62 $this->assertContains( 63 'must be an URL', 64 $output, 65 "Command output: " . PHP_EOL . $output 66 ); 67 } VERIFICA O OUTPUT PRO USUÁRIO.
  113. public function provideInvalidUrl() { return [ "only having protocol" =>

    [ "URL" => "http://", "Expected output" => "must be an URL" ], "not having protocol" => [ "URL" => 'xxx.com', "Expected output" => "must be an URL" ], 'being empty' => [ "URL" => '', "Expected output" => "Option 'url' must have a value" ] ]; }
  114. public function provideInvalidUrl() { return [ "only having protocol" =>

    [ "URL" => "http://", "Expected output" => "must be an URL" ], "not having protocol" => [ "URL" => 'xxx.com', "Expected output" => "must be an URL" ], 'being empty' => [ "URL" => '', "Expected output" => "Option 'url' must have a value" ] ]; } TESTES
  115. public function provideInvalidUrl() { return [ "only having protocol" =>

    [ "URL" => "http://", "Expected output" => "must be an URL" ], "not having protocol" => [ "URL" => 'xxx.com', "Expected output" => "must be an URL" ], 'being empty' => [ "URL" => '', "Expected output" => "Option 'url' must have a value" ] ]; } NOME
  116. public function provideInvalidUrl() { return [ "only having protocol" =>

    [ "URL" => "http://", "Expected output" => "must be an URL" ], "not having protocol" => [ "URL" => 'xxx.com', "Expected output" => "must be an URL" ], 'being empty' => [ "URL" => '', "Expected output" => "Option 'url' must have a value" ] ]; } ARGUMENTOS
  117. 1 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3

    4 Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 ........ 8 / 8 (100%) 8 9 Time: 4.54 seconds, Memory: 3.75MB 10 11 OK (8 tests, 41 assertions)
  118. 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3 4

    Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 Pascutti\ReadingDump\Example 8 [x] Successfull readme example execution 9 10 Pascutti\ReadingDump\RetrieveArticles 11 [x] Without arguments execute successfully 12 13 Pascutti\ReadingDump\SaveArticle 14 [x] Successfull article adition 15 [x] Save article without url argument fails 16 [x] Save article with invalid url fails because of only having protocol 17 [x] Save article with invalid url fails because of not having protocol 18 [x] Save article with invalid url fails because of being empty 19 20 Pascutti\ReadingDump\TagArticle 21 [x] Successfull article tag
  119. 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3 4

    Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 Pascutti\ReadingDump\Example 8 [x] Successfull readme example execution 9 10 Pascutti\ReadingDump\RetrieveArticles 11 [x] Without arguments execute successfully 12 13 Pascutti\ReadingDump\SaveArticle 14 [x] Successfull article adition 15 [x] Save article without url argument fails 16 [x] Save article with invalid url fails because of only having protocol 17 [x] Save article with invalid url fails because of not having protocol 18 [x] Save article with invalid url fails because of being empty 19 20 Pascutti\ReadingDump\TagArticle 21 [x] Successfull article tag CLASSE
  120. 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3 4

    Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 Pascutti\ReadingDump\Example 8 [x] Successfull readme example execution 9 10 Pascutti\ReadingDump\RetrieveArticles 11 [x] Without arguments execute successfully 12 13 Pascutti\ReadingDump\SaveArticle 14 [x] Successfull article adition 15 [x] Save article without url argument fails 16 [x] Save article with invalid url fails because of only having protocol 17 [x] Save article with invalid url fails because of not having protocol 18 [x] Save article with invalid url fails because of being empty 19 20 Pascutti\ReadingDump\TagArticle 21 [x] Successfull article tag NOME DO TESTE
  121. 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3 4

    Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 Pascutti\ReadingDump\Example 8 [x] Successfull readme example execution 9 10 Pascutti\ReadingDump\RetrieveArticles 11 [x] Without arguments execute successfully 12 13 Pascutti\ReadingDump\SaveArticle 14 [x] Successfull article adition 15 [x] Save article without url argument fails 16 [x] Save article with invalid url fails because of only having protocol 17 [x] Save article with invalid url fails because of not having protocol 18 [x] Save article with invalid url fails because of being empty 19 20 Pascutti\ReadingDump\TagArticle 21 [x] Successfull article tag STATUS
  122. 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3 4

    Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 Pascutti\ReadingDump\Example 8 [x] Successfull readme example execution 9 10 Pascutti\ReadingDump\RetrieveArticles 11 [x] Without arguments execute successfully 12 13 Pascutti\ReadingDump\SaveArticle 14 [x] Successfull article adition 15 [x] Save article without url argument fails 16 [x] Save article with invalid url fails because of only having protocol 17 [x] Save article with invalid url fails because of not having protocol 18 [x] Save article with invalid url fails because of being empty 19 20 Pascutti\ReadingDump\TagArticle 21 [x] Successfull article tag NOME DO TESTE
  123. 2 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 3 4

    Runtime: PHP 5.6.26 5 Configuration: /p/phpunit.xml.dist 6 7 Pascutti\ReadingDump\Example 8 [x] Successfull readme example execution 9 10 Pascutti\ReadingDump\RetrieveArticles 11 [x] Without arguments execute successfully 12 13 Pascutti\ReadingDump\SaveArticle 14 [x] Successfull article adition 15 [x] Save article without url argument fails 16 [x] Save article with invalid url fails because of only having protocol 17 [x] Save article with invalid url fails because of not having protocol 18 [x] Save article with invalid url fails because of being empty 19 20 Pascutti\ReadingDump\TagArticle 21 [x] Successfull article tag DATA PROVIDER
  124. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class PocketArticleTest

    extends \PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10 */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $this->markTestIncomplete(); 14 } 26 27 /** 28 * @test 29 * @dataProvider provideBadConstructorArguments 30 */ 31 public function failedInstantiationWith($id, $createdAt, $wordCount, $expectedExceptionMessage) 32 { 33 $this->markTestIncomplete(); 34 } 47 48 /** 49 * @test 50 */ 51 public function successfullPocketArticleUrlGuessingThroughArticleId() 52 { 53 $this->markTestIncomplete(); 54 } 55 56 /** 57 * @test 58 */ 59 public function successfullSerializationToCliLine() 60 { 61 $this->markTestIncomplete(); 62 } 63 }
  125. 11 public function successfullInstantiationWith() 31 public function failedInstantiationWith() 51 public

    function pocketArticleUrl() 59 public function serializationToCliLine()
  126. 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10

    */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 } 24 25 public function provideValidConstructorArguments() 26 { 27 return [ 28 "every information possible" => [ 29 "id" => "123456", 30 "createdAt" => "1503855225", 31 "wordCount" => 650 32 ] 33 ]; 34 } 72 }
  127. 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10

    */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 } 24 25 public function provideValidConstructorArguments() 26 { 27 return [ 28 "every information possible" => [ 29 "id" => "123456", 30 "createdAt" => "1503855225", 31 "wordCount" => 650 32 ] 33 ]; 34 } 72 } DATA PROVIDER
  128. 25 public function provideValidConstructorArguments() 26 { 27 return [ 28

    "every information possible" => [ 29 "id" => "123456", 30 "createdAt" => "1503855225", 31 "wordCount" => 650 32 ] 33 ]; 34 } 72 }
  129. 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10

    */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 } 72 }
  130. 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10

    */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 } 72 } CRIA UMA INSTÂNCIA
  131. 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10

    */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 } 72 } VERIFICA ELA
  132. 7 /** 8 * @test 9 * @dataProvider provideValidConstructorArguments 10

    */ 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 } 72 } DESNECESSÁRIO
  133. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class PocketArticle

    6 { 7 private $id = ""; 8 private $createdAt = null; 9 private $wordCount = 0; 10 11 public function __construct($id, $createdAt, $wordCount) 12 { 13 // ... nothing here 14 } 15 }
  134. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class PocketArticle

    6 { 7 private $id = ""; 8 private $createdAt = null; 9 private $wordCount = 0; 10 11 public function __construct($id, $createdAt, $wordCount) 12 { 13 // ... nothing here 14 } 15 } NÃO FAZ NADA
  135. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 .III 4 / 4 (100%) 7 8 Time: 23 ms, Memory: 3.25MB 24 OK, but incomplete, skipped, or risky tests! 25 Tests: 4, Assertions: 1, Incomplete: 3.
  136. 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article

    = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 $this->assertEquals( 24 $id, 25 $article->id(), 26 "The ID of the article should be the same one given upon instantiation." 27 ); 28 $this->assertEquals( 29 $createdAt, 30 $article->createdAt()->format('U'), 31 "When the article was saved must be always presented through a DateTime instance." 32 ); 33 $this->assertEquals( 34 (int) $wordCount, 35 $article->wordCount(), 36 "The 'word count' of the article should be the same one given upon instantiation." 37 ); 38 } 39 ISSO É O QUE TÍNHAMOS
  137. 11 public function successfullInstantiationWith($id, $createdAt, $wordCount) 12 { 13 $article

    = new PocketArticle( 14 $id, 15 $createdAt, 16 $wordCount 17 ); 18 19 $this->assertInstanceOf( 20 PocketArticle::class, 21 $article 22 ); 23 $this->assertEquals( 24 $id, 25 $article->id(), 26 "The ID of the article should be the same one given upon instantiation." 27 ); 28 $this->assertEquals( 29 $createdAt, 30 $article->createdAt()->format('U'), 31 "When the article was saved must be always presented through a DateTime instance." 32 ); 33 $this->assertEquals( 34 (int) $wordCount, 35 $article->wordCount(), 36 "The 'word count' of the article should be the same one given upon instantiation." 37 ); 38 } 39 NOVAS VERIFICAÇÕES
  138. 11 23 $this->assertEquals( 24 $id, 25 $article->id(), 26 "The ID

    of the article should be the same one given upon instantiation." 27 ); 28 $this->assertEquals( 29 $createdAt, 30 $article->createdAt()->format('U'), 31 "When the article was saved must be always presented through a DateTime instance." 32 ); 33 $this->assertEquals( 34 (int) $wordCount, 35 $article->wordCount(), 36 "The 'word count' of the article should be the same one given upon instantiation." 37 ); 38 } 39
  139. 11 23 $this->assertEquals( 24 $id, 25 $article->id(), 26 "The ID

    of the article should be the same one given upon instantiation." 27 ); 28 $this->assertEquals( 29 $createdAt, 30 $article->createdAt()->format('U'), 31 "When the article was saved must be always presented through a DateTime instance." 32 ); 33 $this->assertEquals( 34 (int) $wordCount, 35 $article->wordCount(), 36 "The 'word count' of the article should be the same one given upon instantiation." 37 ); 38 } 39
  140. 11 23 $this->assertEquals( 24 $id, 25 $article->id(), 26 "The ID

    of the article should be the same one given upon instantiation." 27 ); 28 $this->assertEquals( 29 $createdAt, 30 $article->createdAt()->format('U'), 31 "When the article was saved must be always presented through a DateTime instance." 32 ); 33 $this->assertEquals( 34 (int) $wordCount, 35 $article->wordCount(), 36 "The 'word count' of the article should be the same one given upon instantiation." 37 ); 38 } 39
  141. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 FIII 4 / 4 (100%) 7 8 Time: 26 ms, Memory: 3.50MB 9 10 There was 1 failure: 11 12 1) Pascutti\ReadingDump\PocketArticleTest::successfullInstantiationWith with data set "every information possible" ('123456', '1503855225', 650) 13 The ID of the article should be the same one given upon instantiation. 14 Failed asserting that two strings are equal. 15 --- Expected 16 +++ Actual 17 @@ @@ 18 -'123456' 19 +'' 20 21 /p/test/unit/PocketArticleTest.php:27 39 FAILURES! 40 Tests: 4, Assertions: 2, Failures: 1, Incomplete: 3.
  142. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 FIII 4 / 4 (100%) 7 8 Time: 26 ms, Memory: 3.50MB 9 10 There was 1 failure: 11 12 1) Pascutti\ReadingDump\PocketArticleTest::successfullInstantiationWith with data set "every information possible" ('123456', '1503855225', 650) 13 The ID of the article should be the same one given upon instantiation. 14 Failed asserting that two strings are equal. 15 --- Expected 16 +++ Actual 17 @@ @@ 18 -'123456' 19 +'' 20 21 /p/test/unit/PocketArticleTest.php:27 39 FAILURES! 40 Tests: 4, Assertions: 2, Failures: 1, Incomplete: 3.
  143. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 .III 4 / 4 (100%) 7 8 Time: 24 ms, Memory: 3.25MB 24 OK, but incomplete, skipped, or risky tests! 25 Tests: 4, Assertions: 4, Incomplete: 3.
  144. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 Pascutti\ReadingDump\PocketArticle 7 [x] Successfull instantiation with every information possible 8 [x] Successfull instantiation with maximum integer value for word count 9 [x] Successfull instantiation with with one tag 10 [x] Failed instantiation with invalid creation date 11 [x] Successfull pocket article url guessing through article id 12 [x] Successfull serialization to cli line 13 [x] Successfully assert tag is present and is the only one on article 14 [x] Successfully assert tag is present and is the among many on article 15 [x] Successfully assert tag is not present on article without tags
  145. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 ......... 9 / 9 (100%) 7 8 Time: 23 ms, Memory: 3.25MB 9 10 OK (9 tests, 22 assertions)
  146. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 ......... 9 / 9 (100%) 7 8 Time: 23 ms, Memory: 3.25MB 9 10 OK (9 tests, 22 assertions)
  147. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 ................. 17 / 17 (100%) 7 8 Time: 6.99 seconds, Memory: 4.00MB 9 10 OK (17 tests, 63 assertions)
  148. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 ................. 17 / 17 (100%) 7 8 Time: 6.99 seconds, Memory: 4.00MB 9 10 OK (17 tests, 63 assertions)
  149. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 } LEMBRA DESSE MANO?
  150. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } E DESSA MINA?
  151. 1 <?php 2 3 namespace Pascutti\ReadingDump; 4 5 class SaveArticleTest

    extends IntegrationTest 6 { 7 /** 8 * @test 9 */ 10 public function successfullArticleAdition() 11 { 12 $articleUrl = “https://bit.ly/lalala“; 13 $command = $this->renderCommand("pocket-save --url '$articleUrl'"); 14 15 exec($command, $output, $exitCode); 16 17 $this->assertEquals( 18 0, 19 $exitCode, 20 “Bad exit code: " . PHP_EOL . implode(PHP_EOL, $output) 21 ); 22 } 23 } NÃO CRIAR ESSE CARA
  152. 46 /** 47 * @test 48 * @dataProvider provideInvalidUrl 49

    */ 50 public function saveArticleWithInvalidUrl($url) 51 { 67 } 68 69 public function provideInvalidUrl() 70 { 71 return [ 72 "Only protocol" => ["http://"], 73 ]; 74 } RECEBÊ-LO
  153. 1 <?php 2 3 namespace Pacutti\ReadingDump; 4 5 class PocketServiceTest

    extends\PHPUnit_Framework_TestCase 6 { 7 /** 8 * @test 9 */ 10 public function successfullySavingArticle() 11 { 12 $this->markTestIncomplete(); 13 } 14 15 /** 16 * @test 17 */ 18 public function failToSaveArticleWithoutUrl() 19 { 20 $this->markTestIncomplete(); 21 } 22 23 /** 24 * @test 25 */ 26 public function failToSaveArticleForServerError() 27 { 28 $this->markTestIncomplete(); 29 } 30 }
  154. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20
  155. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 AQUI NÓS VOA BRUXÃO
  156. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 LEMBRA DESSE CARA?
  157. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 ESSE É NOVO!
  158. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 A DEPENDÊNCIA
  159. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 MOCKS DO PHPUNIT
  160. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 CRIA UM CÓDIGO COM COMPORTAMENTO QUE QUEREMOS
  161. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 OU MODIFICA UM EXISTENTE
  162. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 VAMOS INJETAR NOVO COMPORTAMENTO
  163. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 NO NOSSO CÓDIGO
  164. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 10 private $mockApi =

    null; 11 private $pocket = null; 12 13 public function setUp() 14 { 15 $this->mockApi = $this->getMockBuilder(Pocket::class) 16 ->disableOriginalConstructor() 17 ->getMock(); 18 $this->pocket = new PocketService($this->mockApi); 19 } 20 EM TODO TESTE
  165. 1 <?php 2 3 namespace Pascutti\ReadingDump; 7 8 class PocketService

    9 { 10 private $api = null; 11 12 public function __construct(\Pocket $api) 13 { 14 $this->api = $api; 15 } 16 }
  166. 1 <?php 2 3 namespace Pascutti\ReadingDump; 7 8 class PocketService

    9 { 10 private $api = null; 11 12 public function __construct(\Pocket $api) 13 { 14 $this->api = $api; 15 } 16 } INJEÇÃO DE DEPENDÊNCIA
  167. 1 <?php 2 3 namespace Pascutti\ReadingDump; 7 8 class PocketService

    9 { 10 private $api = null; 11 12 public function __construct(\Pocket $api) 13 { 14 $this->api = $api; 15 } 16 } DEPENDÊNCIA
  168. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 }
  169. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } COMEÇAR PELAS FALHAS, COSTUMA SER MAIS FÁCIL
  170. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } A API DE TERCEIRO
  171. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } O COMPORTAMENTO QUE QUEREMOS MUDAR
  172. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } O QUE ELE VAI FAZER
  173. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } VERIFICAÇÃO
  174. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } O NOVO MEMBRO DA FAMÍLIA
  175. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } QUE RECEBE E CONSOME A DEPENDÊNCIA
  176. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } QUANDO EXECUTAMOS ISSO
  177. 8 class PocketServiceTest extends\PHPUnit_Framework_TestCase 9 { 37 /** 38 *

    @test 39 */ 40 public function failToSaveArticleForServerError() 41 { 42 $this->mockApi->method('add') 43 ->will($this->throwException(new PocketException)); 44 45 $this->expectException(PocketException::class); 46 47 $this->pocket->saveArticle('aaa', 'bbbb'); 48 } 49 } ELE EXECUTA ISSO
  178. 8 class PocketService 9 { 17 function saveArticle($url, $title, array

    $tags = []) 18 { 19 return $this->api->add([ 20 "url" => $url, 21 "title" => $title, 22 "tags" => implode(',', $tags) 23 ]); 24 } 25 }
  179. 8 class PocketService 9 { 17 function saveArticle($url, $title, array

    $tags = []) 18 { 19 return $this->api->add([ 20 "url" => $url, 21 "title" => $title, 22 "tags" => implode(',', $tags) 23 ]); 24 } 25 } O QUE EXECUTAMOS
  180. 8 class PocketService 9 { 17 function saveArticle($url, $title, array

    $tags = []) 18 { 19 return $this->api->add([ 20 "url" => $url, 21 "title" => $title, 22 "tags" => implode(',', $tags) 23 ]); 24 } 25 } A DEPENDÊNCIA
  181. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 .................... 20 / 20 (100%) 7 8 Time: 6.46 seconds, Memory: 4.50MB 9 10 OK (20 tests, 67 assertions)
  182. 1 PHPUnit 5.7.21 by Sebastian Bergmann and contributors. 2 3

    Runtime: PHP 5.6.26 4 Configuration: /p/phpunit.xml.dist 5 6 Pascutti\ReadingDump\Example 7 [x] Successfull readme example execution 8 9 Pascutti\ReadingDump\RetrieveArticles 10 [x] Without arguments execute successfully 11 12 Pascutti\ReadingDump\SaveArticle 13 [x] Successfull article adition 14 [x] Save article without url argument fails 15 [x] Save article with invalid url fails because of only having protocol 16 [x] Save article with invalid url fails because of not having protocol 17 [x] Save article with invalid url fails because of being empty 18 19 Pascutti\ReadingDump\TagArticle 20 [x] Successfull article tag 21 22 Pascutti\ReadingDump\PocketArticle 23 [x] Successfull instantiation with every information possible 24 [x] Successfull instantiation with maximum integer value for word count 25 [x] Successfull instantiation with with one tag 26 [x] Failed instantiation with invalid creation date 27 [x] Successfull pocket article url guessing through article id 28 [x] Successfull serialization to cli line 29 [x] Successfully assert tag is present and is the only one on article 30 [x] Successfully assert tag is present and is the among many on article 31 [x] Successfully assert tag is not present on article without tags 32 33 Pascutti\ReadingDump\PocketService 34 [x] Successfully saving article 35 [x] Fail to save article without url 36 [x] Fail to save article for server error