Slide 1

Slide 1 text

joind.in/talk/6c2ad @SammyK #phptek For PHP Source Writing Tests Sammy Kaye Powers 2017-05-25 PHP[TEK] 2017

Slide 2

Slide 2 text

joind.in/talk/6c2ad @SammyK #phptek Slides Get the joind.in/talk/6c2ad

Slide 3

Slide 3 text

Thanks to our Sponsors!

Slide 4

Slide 4 text

joind.in/talk/6c2ad @SammyK #phptek PHP Internals This is a talk

Slide 5

Slide 5 text

Write more TESTS!

Slide 6

Slide 6 text

joind.in/talk/6c2ad @SammyK #phptek Unit tests?

Slide 7

Slide 7 text

joind.in/talk/6c2ad @SammyK #phptek @dhh “TDD is dead.” http://david.heinemeierhansson.com/2014/tdd-is-dead-long-live-testing.html

Slide 8

Slide 8 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 9

Slide 9 text

joind.in/talk/6c2ad @SammyK #phptek Integration tests? *Sort of

Slide 10

Slide 10 text

joind.in/talk/6c2ad @SammyK #phptek Acceptance tests?

Slide 11

Slide 11 text

joind.in/talk/6c2ad @SammyK #phptek Black-box Testing

Slide 12

Slide 12 text

joind.in/talk/6c2ad @SammyK #phptek Testing …you could probably argue that it is Integration

Slide 13

Slide 13 text

joind.in/talk/6c2ad @SammyK #phptek Testing …but it’s more like System

Slide 14

Slide 14 text

joind.in/talk/6c2ad @SammyK #phptek Black-box Testing? What is this

Slide 15

Slide 15 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 16

Slide 16 text

joind.in/talk/6c2ad @SammyK #phptek What is in there?

Slide 17

Slide 17 text

joind.in/talk/6c2ad @SammyK #phptek Input Expected Output ✓

Slide 18

Slide 18 text

joind.in/talk/6c2ad @SammyK #phptek run-tests.php

Slide 19

Slide 19 text

joind.in/talk/6c2ad @SammyK #phptek .phpt Expected Hello World Output Hello World

Slide 20

Slide 20 text

joind.in/talk/6c2ad @SammyK #phptek run-tests.php Development

Slide 21

Slide 21 text

joind.in/talk/6c2ad @SammyK #phptek run-tests.php

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 26

Slide 26 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 27

Slide 27 text

joind.in/talk/6c2ad @SammyK #phptek run-tests.php Development

Slide 28

Slide 28 text

Legacy Code

Slide 29

Slide 29 text

joind.in/talk/6c2ad @SammyK #phptek Files

Slide 30

Slide 30 text

joind.in/talk/6c2ad @SammyK #phptek /ext/{name}/tests /Zend/tests /sapi/{name}/tests Extensions SAPI’s Zend Engine

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

joind.in/talk/6c2ad @SammyK #phptek Input Output

Slide 33

Slide 33 text

joind.in/talk/6c2ad @SammyK #phptek Running run-tests with

Slide 34

Slide 34 text

joind.in/talk/6c2ad @SammyK #phptek 1 source code Clone the

Slide 35

Slide 35 text

joind.in/talk/6c2ad @SammyK #phptek $ git clone \ [email protected]:php/php-src.git

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

joind.in/talk/6c2ad @SammyK #phptek 2source Compile from

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

joind.in/talk/6c2ad @SammyK #phptek $ ./buildconf

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

joind.in/talk/6c2ad @SammyK #phptek $ ./configure

Slide 42

Slide 42 text

joind.in/talk/6c2ad @SammyK #phptek $ ./configure \ --disable-all

Slide 43

Slide 43 text

joind.in/talk/6c2ad @SammyK #phptek $ ./configure \ --enable-debug \ --enable-phpdbg \ --enable-cli \ --enable-cgi \ --with-zlib

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

joind.in/talk/6c2ad @SammyK #phptek $ make

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 48

Slide 48 text

$ sapi/cli/php --version

Slide 49

Slide 49 text

joind.in/talk/6c2ad @SammyK #phptek 3tests Run the

Slide 50

Slide 50 text

joind.in/talk/6c2ad @SammyK #phptek Two Ways to run tests

Slide 51

Slide 51 text

joind.in/talk/6c2ad @SammyK #phptek run-tests.php Run the with… directly

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

joind.in/talk/6c2ad @SammyK #phptek Run the with… the Makefile Recommended!

Slide 54

Slide 54 text

Recommended!

Slide 55

Slide 55 text

Recommended!

Slide 56

Slide 56 text

joind.in/talk/6c2ad @SammyK #phptek Let’s Make a test!

Slide 57

Slide 57 text

joind.in/talk/6c2ad @SammyK #phptek test-echo.phpt Save as… php Run from

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

joind.in/talk/6c2ad @SammyK #phptek Test it! $ make test TESTS=test-echo.phpt

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

joind.in/talk/6c2ad @SammyK #phptek Fail When tests

Slide 62

Slide 62 text

joind.in/talk/6c2ad @SammyK #phptek Input Output Expected

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

joind.in/talk/6c2ad @SammyK #phptek Output Examining the !==

Slide 66

Slide 66 text

Files test-echo.out test-echo.exp test-echo.diff test-echo.log Output

Slide 67

Slide 67 text

joind.in/talk/6c2ad @SammyK #phptek $ less test-echo.out Hello world Script output

Slide 68

Slide 68 text

joind.in/talk/6c2ad @SammyK #phptek $ less test-echo.exp Hello Jane! --EXPECT--

Slide 69

Slide 69 text

joind.in/talk/6c2ad @SammyK #phptek $ less test-echo.diff 001+ Hello world 001- Hello Jane!

Slide 70

Slide 70 text

joind.in/talk/6c2ad @SammyK #phptek $ less test-echo.log ---- EXPECTED OUTPUT Hello Jane! ---- ACTUAL OUTPUT Hello world ---- FAILED

Slide 71

Slide 71 text

Files test-echo.php test-echo.sh Executable

Slide 72

Slide 72 text

joind.in/talk/6c2ad @SammyK #phptek test-echo.php --FILE--

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

test-echo.sh

Slide 75

Slide 75 text

joind.in/talk/6c2ad @SammyK #phptek Example A more complex

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

joind.in/talk/6c2ad @SammyK #phptek Fails So say it

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

$ less test-dt.diff 001+ Boy you know I'm from Europe/Oslo 001- Boy you know I'm from America/Chicago

Slide 83

Slide 83 text

test-dt.php Executable!

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

test-dt.sh

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

joind.in/talk/6c2ad @SammyK #phptek Debugging $ gdb … failed tests with

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

#ShamelessPlug Tomorrow @ 9:30 am in Main Ballroom Dance The An Intro To Step Debugging in

Slide 92

Slide 92 text

joind.in/talk/6c2ad @SammyK #phptek Conventions Naming

Slide 93

Slide 93 text

joind.in/talk/6c2ad @SammyK #phptek {function-name}_basic.phpt {function-name}_error.phpt {function-name}_variation.phpt {ext-name}{number}.phpt bug{bug-id}.phpt http://qa.php.net/write-test.php#naming-conventions

Slide 94

Slide 94 text

joind.in/talk/6c2ad @SammyK #phptek Contribute How-to

Slide 95

Slide 95 text

joind.in/talk/6c2ad @SammyK #phptek Tests! Add some

Slide 96

Slide 96 text

gcov.php.net

Slide 97

Slide 97 text

PHP_FUNCTION

Slide 98

Slide 98 text

readline.c

Slide 99

Slide 99 text

joind.in/talk/6c2ad @SammyK #phptek ? readline()

Slide 100

Slide 100 text

joind.in/talk/6c2ad @SammyK #phptek php.net/readline

Slide 101

Slide 101 text

No content

Slide 102

Slide 102 text

joind.in/talk/6c2ad @SammyK #phptek Let’s Make a test!

Slide 103

Slide 103 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 104

Slide 104 text

joind.in/talk/6c2ad @SammyK #phptek for ext/readline Find the ext/readline/tests

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

joind.in/talk/6c2ad @SammyK #phptek Save as… ext/readline/tests/readline_basic.phpt

Slide 107

Slide 107 text

No content

Slide 108

Slide 108 text

joind.in/talk/6c2ad @SammyK #phptek $ less ext/readline/tests/readline_basic.out Fatal error: Uncaught Error: Call to undefined function readline() in /Users/SammyK/Developer/php-src/ ext/readline/tests/ readline_basic.php:2

Slide 109

Slide 109 text

joind.in/talk/6c2ad @SammyK #phptek php.net/readline

Slide 110

Slide 110 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 111

Slide 111 text

No content

Slide 112

Slide 112 text

joind.in/talk/6c2ad @SammyK #phptek $ ./configure \ --enable-debug \ --enable-phpdbg \ --enable-cli \ --enable-cgi \ --with-zlib

Slide 113

Slide 113 text

joind.in/talk/6c2ad @SammyK #phptek $ ./configure \ --enable-debug \ --enable-phpdbg \ --enable-cli \ --enable-cgi \ --with-zlib \ --with-readline

Slide 114

Slide 114 text

joind.in/talk/6c2ad @SammyK #phptek OR

Slide 115

Slide 115 text

joind.in/talk/6c2ad @SammyK #phptek $ ./configure \ --enable-debug \ --enable-phpdbg \ --enable-cli \ --enable-cgi \ --with-zlib \ --with-libedit

Slide 116

Slide 116 text

No content

Slide 117

Slide 117 text

joind.in/talk/6c2ad @SammyK #phptek $ less ext/readline/tests/readline_basic.out You said:

Slide 118

Slide 118 text

joind.in/talk/6c2ad @SammyK #phptek readline_basic.sh Let’s try

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

joind.in/talk/6c2ad @SammyK #phptek

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

Now send a pull request

Slide 123

Slide 123 text

joind.in/talk/6c2ad @SammyK #phptek internals contributor You’re an

Slide 124

Slide 124 text

joind.in/talk/6c2ad @SammyK #phptek Shhh…. It’s a secret

Slide 125

Slide 125 text

Legacy Code

Slide 126

Slide 126 text

refactor github.com/SammyK/run-tests run-tests

Slide 127

Slide 127 text

refactor run-tests

Slide 128

Slide 128 text

wishlist * Concurrency * Unit tests * Colored output run-tests

Slide 129

Slide 129 text

joind.in/talk/6c2ad @SammyK #phptek Code with me tonight! Main Ballroom during community night after +

Slide 130

Slide 130 text

joind.in/talk/6c2ad @SammyK #phptek Pull Request to php-src yield by midnight ;

Slide 131

Slide 131 text

THANKS! SAMMY KAYE POWERS @SammyK SammyK.me Host of @PHPRoundtable @ChiPHPUG West Coast Swing Hire me! :) /talk/6c2ad