Slide 1

Slide 1 text

joind.in/talk/c6253 @SammyK #ZendCon2017 For PHP Source Writing Tests Sammy Kaye Powers 2017-10-26

Slide 2

Slide 2 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Slides Get the joind.in/talk/c6253

Slide 3

Slide 3 text

joind.in/talk/c6253 @SammyK #ZendCon2017 PHP Internals This is a talk

Slide 4

Slide 4 text

Write more TESTS!

Slide 5

Slide 5 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Unit tests?

Slide 6

Slide 6 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Acceptance tests?

Slide 9

Slide 9 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Integration tests? *Sort of

Slide 10

Slide 10 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Black-box Testing

Slide 11

Slide 11 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Testing …you could probably argue that it is Integration

Slide 12

Slide 12 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Testing …but it’s more like System

Slide 13

Slide 13 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Black-box Testing? What is this

Slide 14

Slide 14 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 15

Slide 15 text

joind.in/talk/c6253 @SammyK #ZendCon2017 What is in there?

Slide 16

Slide 16 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Input Expected Output ✓

Slide 17

Slide 17 text

joind.in/talk/c6253 @SammyK #ZendCon2017 run-tests.php

Slide 18

Slide 18 text

joind.in/talk/c6253 @SammyK #ZendCon2017 .phpt Expected Hello World Output Hello World

Slide 19

Slide 19 text

joind.in/talk/c6253 @SammyK #ZendCon2017 run-tests.php Development

Slide 20

Slide 20 text

joind.in/talk/c6253 @SammyK #ZendCon2017 run-tests.php

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

STFU Operator

Slide 24

Slide 24 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 25

Slide 25 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 26

Slide 26 text

joind.in/talk/c6253 @SammyK #ZendCon2017 run-tests.php Development

Slide 27

Slide 27 text

Legacy Code

Slide 28

Slide 28 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Files

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Input Output

Slide 32

Slide 32 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Running run-tests with

Slide 33

Slide 33 text

joind.in/talk/c6253 @SammyK #ZendCon2017 1 source code Clone the

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

joind.in/talk/c6253 @SammyK #ZendCon2017 2source Compile from

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./buildconf

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./configure

Slide 41

Slide 41 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./configure \ --disable-all

Slide 42

Slide 42 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./configure \ --enable-maintainer-zts \ --enable-debug \ --enable-cli

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ make

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 47

Slide 47 text

$ sapi/cli/php --version

Slide 48

Slide 48 text

joind.in/talk/c6253 @SammyK #ZendCon2017 3tests Run the

Slide 49

Slide 49 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Two Ways to run tests

Slide 50

Slide 50 text

joind.in/talk/c6253 @SammyK #ZendCon2017 run-tests.php Run the with… directly

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Run the with… the Makefile Recommended!

Slide 53

Slide 53 text

Recommended!

Slide 54

Slide 54 text

Recommended!

Slide 55

Slide 55 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Let’s Make a test!

Slide 56

Slide 56 text

joind.in/talk/c6253 @SammyK #ZendCon2017 test-echo.phpt Save as… php Run from

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Test it! $ make test TESTS=test-echo.phpt

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Fail When tests

Slide 61

Slide 61 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Input Output Expected

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Output Examining the !==

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ less test-echo.out Hello world Script output

Slide 67

Slide 67 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ less test-echo.exp Hello Jane! --EXPECT--

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

joind.in/talk/c6253 @SammyK #ZendCon2017 test-echo.php --FILE--

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

test-echo.sh

Slide 74

Slide 74 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Example A more complex

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Fails So say it

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

test-dt.php Executable!

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

test-dt.sh

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Debugging $ gdb … failed tests with

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Conventions Naming

Slide 91

Slide 91 text

joind.in/talk/c6253 @SammyK #ZendCon2017 {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 92

Slide 92 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Contribute How-to

Slide 93

Slide 93 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Tests! Add some

Slide 94

Slide 94 text

gcov.php.net

Slide 95

Slide 95 text

PHP_FUNCTION

Slide 96

Slide 96 text

readline.c

Slide 97

Slide 97 text

joind.in/talk/c6253 @SammyK #ZendCon2017 ? readline()

Slide 98

Slide 98 text

joind.in/talk/c6253 @SammyK #ZendCon2017 php.net/readline

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Let’s Make a test!

Slide 101

Slide 101 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 102

Slide 102 text

joind.in/talk/c6253 @SammyK #ZendCon2017 for ext/readline Find the ext/readline/tests

Slide 103

Slide 103 text

No content

Slide 104

Slide 104 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Save as… ext/readline/tests/readline_basic.phpt

Slide 105

Slide 105 text

No content

Slide 106

Slide 106 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ 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 107

Slide 107 text

joind.in/talk/c6253 @SammyK #ZendCon2017 php.net/readline

Slide 108

Slide 108 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 109

Slide 109 text

No content

Slide 110

Slide 110 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./configure \ --enable-maintainer-zts \ --enable-debug \ --enable-cli

Slide 111

Slide 111 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./configure \ --enable-maintainer-zts \ --enable-debug \ --enable-cli \ --with-readline

Slide 112

Slide 112 text

joind.in/talk/c6253 @SammyK #ZendCon2017 OR

Slide 113

Slide 113 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ ./configure \ --enable-maintainer-zts \ --enable-debug \ --enable-cli \ --with-libedit

Slide 114

Slide 114 text

No content

Slide 115

Slide 115 text

joind.in/talk/c6253 @SammyK #ZendCon2017 $ less ext/readline/tests/readline_basic.out You said:

Slide 116

Slide 116 text

joind.in/talk/c6253 @SammyK #ZendCon2017 readline_basic.sh Let’s try

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

joind.in/talk/c6253 @SammyK #ZendCon2017

Slide 119

Slide 119 text

No content

Slide 120

Slide 120 text

Now send a pull request

Slide 121

Slide 121 text

joind.in/talk/c6253 @SammyK #ZendCon2017 internals contributor You’re an

Slide 122

Slide 122 text

joind.in/talk/c6253 @SammyK #ZendCon2017 phptestfest.org

Slide 123

Slide 123 text

joind.in/talk/c6253 @SammyK #ZendCon2017 sammyk.me Six-part screencast series

Slide 124

Slide 124 text

Legacy Code

Slide 125

Slide 125 text

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

Slide 126

Slide 126 text

refactor run-tests

Slide 127

Slide 127 text

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

Slide 128

Slide 128 text

joind.in/talk/c6253 @SammyK #ZendCon2017 Code with me today! Uncon Room @ 9:15am (by Paradise tower)

Slide 129

Slide 129 text

Sammy Kaye Powers Thanks! /talk/c6253 @SammyK SammyK.me Host of @PHPRoundtable Co-admin of @ChiPHPUG I ❤ West Coast Swing