Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (67 sloc) 2.84 kB
b672584 Updates to QA pages
Zoe Slattery authored
1 <?php
2 include("include/functions.php");
3
4 $TITLE = "Generating tests [PHP-QAT: Quality Assurance Team]";
5 $SITE_UPDATE = date("D M d H:i:s Y T", filectime(__FILE__));
6 /* $Id$ */
7
8 common_header();
9 ?>
10 <h2>Auto-generating test cases</h2>
11 <p>
12 Although it's not possible to generate a complete PHPT test, it's quite easy to generate the
13 standard sections and some simple functions automatically, creating a test case "frame".
14 To do this, you need: <ul>
7612539 Changed documenation for new version
Zoe Slattery authored
15 <li> A build pf PHP53
36005be ooops
Zoe Slattery authored
16 </li> <li> The file generate-phpt.phar, located in the PHP53 source under scripts/dev
b672584 Updates to QA pages
Zoe Slattery authored
17
18 </li></ul>
19 <p />
20 <p />
21 <p />
22 <h3>Example output - a generated test case frame for the cos() function: </h3>
23 <p />
24 <div class="fragment"><pre>
25 --TEST--
7612539 Changed documenation for new version
Zoe Slattery authored
26 Test function cos() by calling it with its expected arguments
b672584 Updates to QA pages
Zoe Slattery authored
27 --FILE--
28 &lt;?php
29
30
7612539 Changed documenation for new version
Zoe Slattery authored
31 echo "*** Test by calling method or function with its expected arguments ***\n"
b672584 Updates to QA pages
Zoe Slattery authored
32
7612539 Changed documenation for new version
Zoe Slattery authored
33 $number =
b672584 Updates to QA pages
Zoe Slattery authored
34
35
7612539 Changed documenation for new version
Zoe Slattery authored
36
37 var_dump(cos( $number ) );
b672584 Updates to QA pages
Zoe Slattery authored
38
39
40 ?&gt;
41 --EXPECTF--
7612539 Changed documenation for new version
Zoe Slattery authored
42
43 </pre></pre></div>
b672584 Updates to QA pages
Zoe Slattery authored
44 <p />
45 <p />
46 <p />
47 <h3>Completing the .phpt test file: </h3>
48 <p />
7612539 Changed documenation for new version
Zoe Slattery authored
49 To turn this into a complete test case, all the developer has to do is to initialise $number to something reasonable
b672584 Updates to QA pages
Zoe Slattery authored
50 and to add a section for the expected output.
51 <p />
52
53
54 <p />
55 <h3> Command syntax </h3>
56 <div class="fragment"><pre>
7612539 Changed documenation for new version
Zoe Slattery authored
57 php generate-phpt.php -f &lt;function_name&gt; |-c &lt;class_name&gt; -m &lt;method_name&gt; -b|e|v [-s skipif:ini:clean:done] [-k win|notwin|64b|not64b] [-x ext]
58 </pre></div>
b672584 Updates to QA pages
Zoe Slattery authored
59 <h3> Options </h3>
60 Use -h to list them, this is the output:
61 <p />
62 <div class="fragment"><pre>
63 -f function_name ................. Name of PHP function, eg cos
7612539 Changed documenation for new version
Zoe Slattery authored
64 -c class name .....................Name of class, eg DOMDocument
65 -m method name ....................Name of method, eg createAttribute
66 -b ............................... Generate basic tests
67 -e ............................... Generate error tests
68 -v ............................... Generate variation tests
69 -s sections....................... Create optional sections, colon separated list
70 -k skipif key..................... Skipif option, only used if -s skipif is used.
71 -x extension.......................Skipif option, specify extension to check for
72 -h ............................... Print this message
73 </pre></div>
74 <h3>Implementation notes</h3>
75 <p>The source code is under scripts/dev/generate-phpt/src. The phar file is generated using the script gtPackage.php.
76 The script works by using Reflection to work out what arguments a function or method expects and then setting up a function/method
77 invocation.
78 The catch with generating tests this way is that the script has to be run *using the level of PHP that you want to test*,
79 so if your were trying to write tests before doing development this script will not help. However, for filling in test gaps
80 in existing extensions it works fine.
b672584 Updates to QA pages
Zoe Slattery authored
81 <p>Return to <a href="write-test.php">write tests.</a></p>
Something went wrong with that request. Please try again.