PHP-Tester

A PHP testing lib that works through both web & cli

Features

  • Output tests to HTML:
    1. Wrapped in <details> tag for vanilla-html expand/collapse
    2. Pass/Fail/Success (colorized)
    3. Any echo/printed content from each test is shown
    4. Exceptions in tests are caught & printed
    5. Source is well-formatted so you can view-source OR view it in a browser
  • Extend the tester class & every method starting with test will be run as a test

TODO

Priority TODO
  • Add functional testing option
    • $t = new \Taeluf\Tester(); $t->startTest(); doSomeCode(); $t->endTest('name');
  • Add basic test benchmarking
  • Add equality testing function
    • $succeeded = $this->test('expectedOutput', $actualOutput);
    • print "target: ..." & "actual: ..."
    • Handle printing of strings & arrays, maybe other stuff. Maybe just var_dump?? (ugly)
Maybe Eventually TODO
  • Pick a better name
  • Self-promo, maybe? Document it on my website & direct folks there, share my twitter handle, patreon, etc
  • Add sub-tests (not sure what I mean here?? But it's in my notes!)
  • Store test code in arrays & output it in the HTML for each test
    • Use debug_backtrace() or tokenizing or something to get the line of each testFunction & just copy the code from the function & include it in the HTML output
    • This should DEFINITELY be optional

Example (OOP Style)

We'll create a simple "translator" function & test it with the OOP approach.

"translation" function:

@import(Example.Translator)

"Tester" class:

@import(Example.TranslatorTester)

Output:

You can copy the path to the html file & paste it in your browser bar to view your test result

HTML Code

@import(Example.TranslatorOutput)

Visual

Markdown strips the inline styles, so it lacks the colors & white-space:pre @import(Example.TranslatorOutput)

Contribution

PHP code is in 5-src dir. Put tests in 8-build/test/. Probably use a sub-directory. Look at my Translator test and see Docu Bear to learn how to document. Orr... just write some code & I'll probably document it up.

  1. Pick any TODO item (or issue if there are any) & submit a pull request that solves just that single item.
  2. Submit issues for feature requests or bug reports!
  3. See something else? Submit an issue & then submit a pull request that resolves it.