PHP-Tester
A PHP testing lib that works through both web & cli
Features
- Output tests to HTML:
- Wrapped in
<details>
tag for vanilla-html expand/collapse - Pass/Fail/Success (colorized)
- Any echo/printed content from each test is shown
- Exceptions in tests are caught & printed
- Source is well-formatted so you can view-source OR view it in a browser
- Wrapped in
- 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.
- Pick any
TODO
item (or issue if there are any) & submit a pull request that solves just that single item. - Submit issues for feature requests or bug reports!
- See something else? Submit an issue & then submit a pull request that resolves it.