Slide 1

Slide 1 text

Augusto Pascutti
 @augustohp AUTOMATIZANDO TESTES COM PHPUNIT

Slide 2

Slide 2 text

AGENDA - Apresentação - Q&A

Slide 3

Slide 3 text

O QUE VOCÊ PRECISA PRA COMEÇAR?

Slide 4

Slide 4 text

ERRE

Slide 5

Slide 5 text

ERRAR É DAHORA !!!

Slide 6

Slide 6 text

O QUE É UM TESTE?

Slide 7

Slide 7 text

1

Slide 8

Slide 8 text

NOSSO PRIMEIRO TESTE

Slide 9

Slide 9 text

1 $ php hello.php 2 Hello World!

Slide 10

Slide 10 text

1 $ php hello.php 2 Hello World!

Slide 11

Slide 11 text

A VERIFICAÇÃO DE UM COMPORTAMENTO É UM TESTE

Slide 12

Slide 12 text

AUTOMATIZAR ESSAS VERIFICAÇÕES É ONDE DÁ RUIM

Slide 13

Slide 13 text

MAS NÃO CRIEMOS PÂNICO

Slide 14

Slide 14 text

VOCÊ JÁ SABE COMO TESTAR LIÇÃO

Slide 15

Slide 15 text

EXISTEM VÁRIAS FORMAS DE TESTAR A MESMA COISA

Slide 16

Slide 16 text

COMO TESTAR TODOS COMANDOS NO TERMINAL?

Slide 17

Slide 17 text

COMO SABER QUE UM COMANDO NO TERMINAL DEU BOM?

Slide 18

Slide 18 text

1 $ php hello.php 2 Hello World! 3 $ echo $? 4 0

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

1 $ php hello.php 2 Hello World! 3 $ echo $? 4 0 ZERO É SUCESSO !

Slide 21

Slide 21 text

1 $ php hello.php 2 Hello World! 3 $ echo $? 4 0 QUALQUER OUTRA COISA É UMA FALHA

Slide 22

Slide 22 text

UM TESTE AUTOMÁTICO PRA QUALQUER COMANDO NO TERMINAL

Slide 23

Slide 23 text

1

Slide 24

Slide 24 text

1

Slide 25

Slide 25 text

1

Slide 26

Slide 26 text

1

Slide 27

Slide 27 text

1

Slide 28

Slide 28 text

1

Slide 29

Slide 29 text

AUTOMATIZAMOS NOSSO PRIMEIRO TESTE

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

O JENKINS TESTA USANDO “EXIT CODE”

Slide 33

Slide 33 text

É ISSO AÍ MESMO!

Slide 34

Slide 34 text

FIZEMOS O JENKINS MAIS DO UNIVERSO

Slide 35

Slide 35 text

AUTOMATIZANDO TESTES EM UM CENÁRIO REAL

Slide 36

Slide 36 text

READING-DUMP

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

EXECUTANDO A APLICAÇÃO MANUALMENTE

Slide 39

Slide 39 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449

Slide 40

Slide 40 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 PROGRAMA PRINCIPAL

Slide 41

Slide 41 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 NOME DO
 SCRIPT

Slide 42

Slide 42 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 UM ARTIGO NO “POCKET”

Slide 43

Slide 43 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 ID DO ARTIGO

Slide 44

Slide 44 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 UNIX TIMESTAMP DE QUANDO ELE FOI ADICIONADO

Slide 45

Slide 45 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 NÚMERO DE PALAVRAS NO ARTIGO

Slide 46

Slide 46 text

1 $ php reading-dump.php pocket-retrieve 2 1498569449 1503883482 358 https://getpocket.com/a/read/1498569449 URL DO ARTIGO NO POCKET

Slide 47

Slide 47 text

UMA PESSOA LÊ EM MÉDIA 270 PALAVRAS POR MINUTO

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

SÓ FALTA ADICIONAR A TAG

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

E TESTAR SE O COMANDO DEU CERTO

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

OS SCRIPTS RETORNAM EXIT CODES DE ERRO

Slide 62

Slide 62 text

GREP -B 2 EXIT SRC/*.PHP

Slide 63

Slide 63 text

GREP -B 2 EXIT SRC/*.PHP BUSCA

Slide 64

Slide 64 text

GREP -B 2 EXIT SRC/*.PHP PELA FUNÇÃO “EXIT” DO PHP

Slide 65

Slide 65 text

GREP -B 2 EXIT SRC/*.PHP EM TODOS OS SCRIPTS

Slide 66

Slide 66 text

GREP -B 2 EXIT SRC/*.PHP E ALÉM DA LINHA COM MATCH, TRAZ DUAS LINHAS ANTERIORES

Slide 67

Slide 67 text

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);

Slide 68

Slide 68 text

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);

Slide 69

Slide 69 text

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);

Slide 70

Slide 70 text

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);

Slide 71

Slide 71 text

MELHORANDO NOSSO JENKINS

Slide 72

Slide 72 text

O QUE QUEREMOS EXIBIR?

Slide 73

Slide 73 text

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.

Slide 74

Slide 74 text

UM TESTE AUTOMATIZADO NESSA SUITE

Slide 75

Slide 75 text

1

Slide 76

Slide 76 text

1

Slide 77

Slide 77 text

1

Slide 78

Slide 78 text

1

Slide 79

Slide 79 text

1

Slide 80

Slide 80 text

1

Slide 81

Slide 81 text

O SCRIPT QUE RODA ESSE TESTE

Slide 82

Slide 82 text

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,

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

CALMA. ESSA PARTE É TODA PARA IMPRESSÃO

Slide 85

Slide 85 text

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.

Slide 86

Slide 86 text

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,

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

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

Slide 93

Slide 93 text

A FUNÇÃO QUE TESTA UM ARQUIVO

Slide 94

Slide 94 text

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 };

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

1

Slide 98

Slide 98 text

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!

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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++

Slide 101

Slide 101 text

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

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

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

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

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.

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

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

Slide 108

Slide 108 text

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

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

COM NOSSO JENKINS

Slide 111

Slide 111 text

AUTOMATICAMENTE

Slide 112

Slide 112 text

No content

Slide 113

Slide 113 text

ACABAMOS DE CRIAR UMA SUITE DE TESTES DE ACEITAÇÃO

Slide 114

Slide 114 text

ACABAMOS DE CRIAR UMA SUITE DE TESTES FUNCIONAL

Slide 115

Slide 115 text

ELA TESTA AUTOMATICAMENTE DO PONTO DE VISTA DO USUÁRIO

Slide 116

Slide 116 text

MAS ELA DÁ RUIM …

Slide 117

Slide 117 text

E SE … ACABAREM OS ARTIGOS?

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

TEMOS SEMPRE QUE ADICIONAR UM ARTIGO NOVO

Slide 120

Slide 120 text

1

Slide 121

Slide 121 text

1

Slide 122

Slide 122 text

1

Slide 123

Slide 123 text

TESTANDO O EXEMPLO MANUAL LÁ DO INÍCIO

Slide 124

Slide 124 text

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

Slide 125

Slide 125 text

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;

Slide 126

Slide 126 text

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

Slide 127

Slide 127 text

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

Slide 128

Slide 128 text

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

Slide 129

Slide 129 text

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.

Slide 130

Slide 130 text

A MESMA ESTRATÉGIA DE TESTE AUTOMATIZADO PODE TE LEVAR LONGE LIÇÃO

Slide 131

Slide 131 text

VOCÊ SÓ ENCONTRA ELA DEPOIS DE ERRAR O SUFICIENTE

Slide 132

Slide 132 text

PHPUNIT COMO FAZ?

Slide 133

Slide 133 text

VAMOS MIGRAR NOSSA SUITE PARA O PHPUNIT

Slide 134

Slide 134 text

1 markTestIncomplete('TODO'); 13 } 14 }

Slide 135

Slide 135 text

1 markTestIncomplete('TODO'); 13 } 14 } PHPUNIT

Slide 136

Slide 136 text

1 markTestIncomplete('TODO'); 13 } 14 } UM GRUPO DE TESTES

Slide 137

Slide 137 text

1 markTestIncomplete('TODO'); 13 } 14 } NOME DO GRUPO

Slide 138

Slide 138 text

1 markTestIncomplete('TODO'); 13 } 14 } UM TESTE

Slide 139

Slide 139 text

1 markTestIncomplete('TODO'); 13 } 14 } AVISA ISSO PRO PHPUNIT

Slide 140

Slide 140 text

1 markTestIncomplete('TODO'); 13 } 14 } NOME DO TESTE

Slide 141

Slide 141 text

1 markTestIncomplete('TODO'); 13 } 14 } SEJA EXPLÍCITO

Slide 142

Slide 142 text

1 markTestIncomplete('TODO'); 13 } 14 } PROCRASTINA

Slide 143

Slide 143 text

O DRAGÃO DA SUITE

Slide 144

Slide 144 text

PRECISAMOS CONFIGURAR O AMBIENTE PRA USAR A API DO POCKET

Slide 145

Slide 145 text

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 }

Slide 146

Slide 146 text

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

Slide 147

Slide 147 text

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

Slide 148

Slide 148 text

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

Slide 149

Slide 149 text

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

Slide 150

Slide 150 text

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

Slide 151

Slide 151 text

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

Slide 152

Slide 152 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 );

Slide 153

Slide 153 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); A VALIDAÇÃO QUE SERÁ FEITA

Slide 154

Slide 154 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); O QUE VAI SER VERIFICADO

Slide 155

Slide 155 text

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

Slide 156

Slide 156 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); AJUDA OUTROS DEVS A ENTENDER O QUE DEVERIA TER ACONTECIDO

Slide 157

Slide 157 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); É O DEBUG

Slide 158

Slide 158 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); O VAR_DUMP

Slide 159

Slide 159 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); O FEIJÃO DO NOSSO ARROZ

Slide 160

Slide 160 text

13 $this->assertNotEmpty( 14 $key, 15 “Mensagem quando dá ruim” 16 ); CUIDADO COM PLEONASMOS

Slide 161

Slide 161 text

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

Slide 162

Slide 162 text

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

Slide 163

Slide 163 text

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

Slide 164

Slide 164 text

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

Slide 165

Slide 165 text

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 }

Slide 166

Slide 166 text

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”

Slide 167

Slide 167 text

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

Slide 168

Slide 168 text

1 markTestIncomplete('TODO'); 13 } 14 }

Slide 169

Slide 169 text

1 markTestIncomplete('TODO'); 13 } 14 }

Slide 170

Slide 170 text

1 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 }

Slide 171

Slide 171 text

1 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

Slide 172

Slide 172 text

1 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

Slide 173

Slide 173 text

1 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

Slide 174

Slide 174 text

1 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

Slide 175

Slide 175 text

O PHPUNIT NÃO TE AJUDA A TESTAR LIÇÃO

Slide 176

Slide 176 text

SÓ AUTOMATIZAR O QUE VOCÊ JÁ SABE LIÇÃO

Slide 177

Slide 177 text

CENÁRIOS DE FALHA

Slide 178

Slide 178 text

REAPROVEITANDO TESTES COM DATA PROVIDERS

Slide 179

Slide 179 text

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 }

Slide 180

Slide 180 text

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

Slide 181

Slide 181 text

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

Slide 182

Slide 182 text

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

Slide 183

Slide 183 text

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

Slide 184

Slide 184 text

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

Slide 185

Slide 185 text

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

Slide 186

Slide 186 text

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

Slide 187

Slide 187 text

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

Slide 188

Slide 188 text

O TESTE VOCÊ JÁ SABE

Slide 189

Slide 189 text

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 }

Slide 190

Slide 190 text

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

Slide 191

Slide 191 text

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

Slide 192

Slide 192 text

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

Slide 193

Slide 193 text

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

Slide 194

Slide 194 text

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

Slide 195

Slide 195 text

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.

Slide 196

Slide 196 text

MAIS CENÁRIOS DE TESTE COM DATA PROVIDERS

Slide 197

Slide 197 text

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" ] ]; }

Slide 198

Slide 198 text

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

Slide 199

Slide 199 text

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

Slide 200

Slide 200 text

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

Slide 201

Slide 201 text

EXECUTANDO A SUITE

Slide 202

Slide 202 text

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)

Slide 203

Slide 203 text

UM OUTPUT QUE ESTAMOS ACOSTUMADOS

Slide 204

Slide 204 text

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

Slide 205

Slide 205 text

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

Slide 206

Slide 206 text

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

Slide 207

Slide 207 text

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

Slide 208

Slide 208 text

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

Slide 209

Slide 209 text

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

Slide 210

Slide 210 text

UM POUCO DE CONCEITO

Slide 211

Slide 211 text

HTTPS://MARTINFOWLER.COM/BLIKI/TESTPYRAMID.HTML

Slide 212

Slide 212 text

HTTPS://MARTINFOWLER.COM/BLIKI/TESTPYRAMID.HTML BALANÇO IDEAL

Slide 213

Slide 213 text

HTTPS://MARTINFOWLER.COM/BLIKI/TESTPYRAMID.HTML MENOS

Slide 214

Slide 214 text

HTTPS://MARTINFOWLER.COM/BLIKI/TESTPYRAMID.HTML MAIS

Slide 215

Slide 215 text

HTTPS://MARTINFOWLER.COM/BLIKI/TESTPYRAMID.HTML O QUE FIZEMOS

Slide 216

Slide 216 text

HTTPS://MARTINFOWLER.COM/BLIKI/TESTPYRAMID.HTML O QUE VAMOS FAZER

Slide 217

Slide 217 text

TESTES FUNCIONAIS SÃO FÁCEIS DE ENCONTRAR LIÇÃO

Slide 218

Slide 218 text

NÃO RECOMENDADOS LIÇÃO

Slide 219

Slide 219 text

MAS NECESSÁRIOS LIÇÃO

Slide 220

Slide 220 text

SÓ NÃO DEPENDA EXCLUSIVAMENTE DELES LIÇÃO

Slide 221

Slide 221 text

No content

Slide 222

Slide 222 text

COMO VIMOS AS COISAS ATÉ AGORA?

Slide 223

Slide 223 text

No content

Slide 224

Slide 224 text

COMO DEVEMOS VER?

Slide 225

Slide 225 text

No content

Slide 226

Slide 226 text

COMO DEVERIA SER?

Slide 227

Slide 227 text

No content

Slide 228

Slide 228 text

REALIDADE

Slide 229

Slide 229 text

MUITOS PONTOS DE FALHA

Slide 230

Slide 230 text

No content

Slide 231

Slide 231 text

FALHA DE CONEXÃO

Slide 232

Slide 232 text

RESPOSTA INEXPERADA

Slide 233

Slide 233 text

INPUT INEXPERADO

Slide 234

Slide 234 text

MUDANÇA DE API

Slide 235

Slide 235 text

REQUER QUE UM ARTIGO EXISTA

Slide 236

Slide 236 text

REQUER QUE UMA CONTA EXISTA

Slide 237

Slide 237 text

UM APP REGISTRADO

Slide 238

Slide 238 text

AMBIENTE CONFIGURADO

Slide 239

Slide 239 text

TESTES DE INTEGRAÇÃO SÃO UM CA%#780 DE SE MANTER LIÇÃO

Slide 240

Slide 240 text

ISOLANDO UM PROBLEMA

Slide 241

Slide 241 text

No content

Slide 242

Slide 242 text

UM ARTIGO NO POCKET

Slide 243

Slide 243 text

COMEÇANDO PELO TESTE

Slide 244

Slide 244 text

1 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 }

Slide 245

Slide 245 text

NADA DA NOSSA CLASSE DE INTEGRAÇÃO

Slide 246

Slide 246 text

1

Slide 247

Slide 247 text

1

Slide 248

Slide 248 text

LISTANDO CENÁRIOS POSSÍVEIS

Slide 249

Slide 249 text

11 public function successfullInstantiationWith() 31 public function failedInstantiationWith() 51 public function pocketArticleUrl() 59 public function serializationToCliLine()

Slide 250

Slide 250 text

TESTE DE INSTANCIAÇÃO BEM SUCEDIDA

Slide 251

Slide 251 text

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 }

Slide 252

Slide 252 text

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

Slide 253

Slide 253 text

25 public function provideValidConstructorArguments() 26 { 27 return [ 28 "every information possible" => [ 29 "id" => "123456", 30 "createdAt" => "1503855225", 31 "wordCount" => 650 32 ] 33 ]; 34 } 72 }

Slide 254

Slide 254 text

O TESTE

Slide 255

Slide 255 text

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 }

Slide 256

Slide 256 text

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

Slide 257

Slide 257 text

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

Slide 258

Slide 258 text

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

Slide 259

Slide 259 text

NOSSA CLASSE CONCRETA OU SUT

Slide 260

Slide 260 text

1

Slide 261

Slide 261 text

1

Slide 262

Slide 262 text

MAS O TESTE PASSA

Slide 263

Slide 263 text

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.

Slide 264

Slide 264 text

MELHORANDO O TESTE

Slide 265

Slide 265 text

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

Slide 266

Slide 266 text

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

Slide 267

Slide 267 text

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

Slide 268

Slide 268 text

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

Slide 269

Slide 269 text

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

Slide 270

Slide 270 text

EXECUTANDO O TESTE

Slide 271

Slide 271 text

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.

Slide 272

Slide 272 text

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.

Slide 273

Slide 273 text

DEPOIS DE IMPLEMENTAR O CÓDIGO

Slide 274

Slide 274 text

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.

Slide 275

Slide 275 text

FIZEMOS O TESTE ANTES DA IMPLEMENTAÇÃO

Slide 276

Slide 276 text

No content

Slide 277

Slide 277 text

TESTES UNITÁRIOS SÃO RÁPIDOS

Slide 278

Slide 278 text

E ISOLADOS

Slide 279

Slide 279 text

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

Slide 280

Slide 280 text

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)

Slide 281

Slide 281 text

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)

Slide 282

Slide 282 text

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)

Slide 283

Slide 283 text

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)

Slide 284

Slide 284 text

LIDANDO COM DEPENDÊNCIAS

Slide 285

Slide 285 text

SERVIÇOS

Slide 286

Slide 286 text

BANCO DE DADOS

Slide 287

Slide 287 text

SISTEMA DE ARQUIVOS

Slide 288

Slide 288 text

GALERA DA API QUE NÃO ENTREGA OS BANG

Slide 289

Slide 289 text

INJEÇÃO DE DEPENDÊNCIAS

Slide 290

Slide 290 text

1 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?

Slide 291

Slide 291 text

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?

Slide 292

Slide 292 text

1 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

Slide 293

Slide 293 text

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

Slide 294

Slide 294 text

INJEÇÃO DE DEPENDÊNCIAS

Slide 295

Slide 295 text

No content

Slide 296

Slide 296 text

#FODEU

Slide 297

Slide 297 text

No content

Slide 298

Slide 298 text

No content

Slide 299

Slide 299 text

1 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 }

Slide 300

Slide 300 text

10 public function successfullySavingArticle() 11 18 public function failToSaveArticleWithoutUrl() 19 26 public function failToSaveArticleForServerError()

Slide 301

Slide 301 text

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

Slide 302

Slide 302 text

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

Slide 303

Slide 303 text

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?

Slide 304

Slide 304 text

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!

Slide 305

Slide 305 text

No content

Slide 306

Slide 306 text

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

Slide 307

Slide 307 text

No content

Slide 308

Slide 308 text

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

Slide 309

Slide 309 text

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

Slide 310

Slide 310 text

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

Slide 311

Slide 311 text

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

Slide 312

Slide 312 text

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

Slide 313

Slide 313 text

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

Slide 314

Slide 314 text

No content

Slide 315

Slide 315 text

1 api = $api; 15 } 16 }

Slide 316

Slide 316 text

1 api = $api; 15 } 16 } INJEÇÃO DE DEPENDÊNCIA

Slide 317

Slide 317 text

1 api = $api; 15 } 16 } DEPENDÊNCIA

Slide 318

Slide 318 text

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 }

Slide 319

Slide 319 text

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

Slide 320

Slide 320 text

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

Slide 321

Slide 321 text

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

Slide 322

Slide 322 text

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

Slide 323

Slide 323 text

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

Slide 324

Slide 324 text

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

Slide 325

Slide 325 text

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

Slide 326

Slide 326 text

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

Slide 327

Slide 327 text

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

Slide 328

Slide 328 text

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 }

Slide 329

Slide 329 text

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

Slide 330

Slide 330 text

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

Slide 331

Slide 331 text

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)

Slide 332

Slide 332 text

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

Slide 333

Slide 333 text

No content

Slide 334

Slide 334 text

HTTP://NATPRYCE.COM/ARTICLES.HTML

Slide 335

Slide 335 text

VOCÊ VAI PRECISAR MUDAR SEU CÓDIGO ATUAL PARA AUTOMATIZAR LIÇÃO

Slide 336

Slide 336 text

CONCLUSÕES - Erre. - Todo resto, você sabe.

Slide 337

Slide 337 text

SEJA MAIS PREGUIÇOSO LIÇÃO

Slide 338

Slide 338 text

O QUE EU ERREI NESSA PALESTRA?

Slide 339

Slide 339 text

PERGUNTAS?