note 118330 added to function.get-class-methods
| From: | polarglow06 at gmail dot com | Date: | Wed, 18 Nov 2015 18:09:52 +0000 |
| Subject: | note 118330 added to function.get-class-methods | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204176@lists.php.net to get a copy of this message | ||
I have created a very simple test runner using this function
function get_bar($text) {
$bar = "";
for($i=1; $i<=strlen($text); $i++) {
$bar .= "=";
}
return $bar;
}
class Tester {
function __construct() {
$this->run_tests();
}
// run the tests
function run_tests() {
print("Tester by Minhajul Anwar \n");
$class = get_class($this);
$test_methods = preg_grep('/^test/', get_class_methods($this));
foreach($test_methods as $method) {
$start_rep = "test: $class::$method";
$bar = get_bar($start_rep);
print("\n$start_rep\n$bar\n");
$this->$method();
print("\n");
}
}
}
now you just need to write your test class with tegst methods prefixed by 'test', and then
just instantiate object of that test class of your, all those tests methods will get run
automatically
The drawback is: your test methods must not accept any arguments
an example:
require '../autoload.php';
register_autoload_paths(realpath('./'));
class Test_Test extends Tester {
function test_something() {
print("method got executed");
}
function testAnotherThing() {
print("another test method");
}
}
$Test = new Test_Test();
----
Server IP: 72.52.91.14
Probable Submitter: 103.231.162.62
----
Manual Page -- http://php.net/manual/en/function.get-class-methods.php
Edit -- https://master.php.net/note/edit/118330
Del: integrated -- https://master.php.net/note/delete/118330/integrated
Del: useless -- https://master.php.net/note/delete/118330/useless
Del: bad code -- https://master.php.net/note/delete/118330/bad+code
Del: spam -- https://master.php.net/note/delete/118330/spam
Del: non-english -- https://master.php.net/note/delete/118330/non-english
Del: in docs -- https://master.php.net/note/delete/118330/in+docs
Del: other reasons-- https://master.php.net/note/delete/118330
Reject -- https://master.php.net/note/reject/118330
Search -- https://master.php.net/manage/user-notes.php