Skip to content

Commit a3203ba

Browse files
committed
Add tests section with enough docs to get started and some @todo for future possible sections
1 parent 0de7082 commit a3203ba

File tree

7 files changed

+496
-0
lines changed

7 files changed

+496
-0
lines changed

Book/index.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ This part concerns only the PHP 7 branch. It is under development.
5454
php7/zend_engine.rst
5555
php7/final.rst
5656
57+
Testing PHP Source
58+
------------------
59+
60+
Writing tests applies to both PHP 5 & PHP 7.
61+
62+
.. toctree::
63+
:maxdepth: 3
64+
65+
tests/introduction.rst
66+
tests/overview.rst
67+
tests/running_the_test_suite.rst
68+
tests/phpt_file_structure.rst
69+
tests/examining_failed_test_output.rst
70+
5771
Index and search
5872
================
5973

Book/tests/echo_basic.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
echo - basic test for echo language construct
3+
--FILE--
4+
<?php
5+
echo 'This works ', 'and takes args!';
6+
?>
7+
--EXPECT--
8+
This works and takes args!
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _examining_failed_test_output:
2+
3+
Examining failed test output
4+
============================
5+
6+
We've learned how to create and run tests and have had great success with passing tests, but what happens when things go
7+
wrong? We'll examine how to help ourselves debug failed tests using the failed-test output files.
8+
9+
Failed test output files
10+
------------------------
11+
12+
@TODO Add all the rest here. :)

Book/tests/introduction.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Testing with ``.phpt`` files
2+
============================
3+
4+
Tests are a great way to get your foot in the door of PHP internals. You don't even need to know C in order to get
5+
started because all the tests are written in PHP.
6+
7+
In this chapter we'll explore the test suite that covers the internal functionality of PHP. We'll cover everything from
8+
running the test suite with PHP's custom black-box testing tool called ``run-tests.php`` to creating new tests.
9+
10+
@TODO
11+
-----
12+
13+
The following sections still need to be written:
14+
15+
* Examining failed test output (examining_failed_test_output)
16+
* Finding untested code (finding_untested_code)
17+
* Environment variables (advanced/environment_variables)
18+
* Redirect Tests (advanced/redirect_tests)
19+
* Step debugging with GDB (advanced/step_debugging_with_gdb)

Book/tests/overview.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. _overview:
2+
3+
Testing overview
4+
================
5+
6+
PHP has an extensive test suite with over 15,000 individual test files. The test files are run with PHP's black-box
7+
testing tool called `run-tests.php`_ which can be found in the root directory of the php source code.
8+
9+
"But wait!" you say, "I heard that PHP source doesn't have any unit tests." You are correct. The PHP source code has
10+
zero unit tests. But it does have `functional tests`_ and lucky for us, these particular functional tests are written in
11+
PHP. The test files have a ``.phpt`` file extension and can be run just like any normal PHP file.
12+
13+
The official documentation for writing phpt tests lives at `qa.php.net`_.
14+
15+
.. _run-tests.php: https://github.com/php/php-src/blob/master/run-tests.php
16+
.. _`functional tests`: https://en.wikipedia.org/wiki/Functional_testing
17+
.. _`qa.php.net`: http://qa.php.net/write-test.php
18+
19+
Black-box testing
20+
-----------------
21+
22+
In a nutshell, `black-box testing`_ sends input to some function and examines the output after the function has finished
23+
execution. If the output matches what we were expecting, then the test has passed. Black-box testing doesn't care *how*
24+
something is done, it only cares about the end result. This is exactly how ``run-tests.php`` works; it takes a set of
25+
inputs, runs some PHP code and then examines the output. If the output matches what is expected, then the test passes.
26+
27+
.. _black-box testing: https://en.wikipedia.org/wiki/Black-box_testing
28+
29+
Where the test files live
30+
-------------------------
31+
32+
The test files live in several different places throughout the codebase in folders named ``tests``. Each test folder
33+
contains ``.phpt`` files pertaining to its containing folder's code.
34+
35+
* ``ext/{extension-name}/tests/`` Extension tests
36+
* ``sapi/{sapi-name}/tests/`` SAPI tests
37+
* ``Zend/tests/`` Zend engine tests
38+
* ``tests/`` More Zend engine tests

0 commit comments

Comments
 (0)