note 93967 added to features.commandline

From: Date: Thu, 08 Oct 2009 23:06:40 +0000
Subject: note 93967 added to features.commandline
Groups: php.notes 
Request: Send a blank email to php-notes+get-161573@lists.php.net to get a copy of this message
I append this to most of my PHP files, to allow command line unit testing of a class. It ensures that the unit test is only run if the script is run directly, and won't be triggered by an include from another CLI script. <?php if (!empty($argc) && strstr($argv[0], basename(__FILE__))) { $test = new TestClass(); $rv = $test->Test(); die("Test returned $rv\n"); } ?> ---- Server IP: 117.55.229.1 Probable Submitter: 124.190.249.143 ---- Manual Page -- http://www.php.net/manual/en/features.commandline.php Edit -- https://master.php.net/note/edit/93967 Del: integrated -- https://master.php.net/note/delete/93967/integrated Del: useless -- https://master.php.net/note/delete/93967/useless Del: bad code -- https://master.php.net/note/delete/93967/bad+code Del: spam -- https://master.php.net/note/delete/93967/spam Del: non-english -- https://master.php.net/note/delete/93967/non-english Del: in docs -- https://master.php.net/note/delete/93967/in+docs Del: other reasons-- https://master.php.net/note/delete/93967 Reject -- https://master.php.net/note/reject/93967 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161573) next »