Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you installed phpunit correctly (through PEAR), then there is no need for an include file; you just need to change the way you use it to test php files (e.g. you use it to test if the file worked by going to the browser type localhost). With phpunit you can use the command line; <a href="http://phpunit.de/manual/current/en/textui.html" rel="noreferrer">chapter 5</a> gives the same example using the command line (I would assume it's a standard). So if you got it installed correctly you can do this:</p> <ol> <li><p>File ExampleTest.php, located at the root of localhost (for me this is /var/www):</p> <pre><code>class ExampleTest extends PHPUnit_Framework_TestCase { public function testOne() { $this-&gt;assertTrue(FALSE); } } </code></pre></li> <li><p>Open a console (terminal on Mac or Linux, command prompt on Win), navigate to your localhost document root (where you saved ExampleTest.php) and type the following:</p> <pre><code>phpunit --verbose ExampleTest.php </code></pre></li> <li><p>You should see:</p> <pre><code>PHPUnit 3.4.13 by Sebastian Bergmann. F Time: 1 second, Memory: 6.50Mb There was 1 failure: 1) ExampleTest::testOne Failed asserting that &lt;boolean:false&gt; is true. /var/www/ExampleTest.php:6 FAILURES! Tests: 1, Assertions: 1, Failures: 1. </code></pre></li> </ol> <p>Notes: All the above assumes you installed phpunit correctly (as stated in <a href="http://www.phpunit.de/manual/current/en/installation.html" rel="noreferrer">chapter 3</a>) and you restarted apache after that .</p> <p>if you really want to run tests in your browser use the following code</p> <pre><code># error reporting ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); # include TestRunner require_once 'PHPUnit/TextUI/TestRunner.php'; # our test class class ExampleTest extends PHPUnit_Framework_TestCase { public function testOne() { $this-&gt;assertTrue(FALSE); } } # run the test $suite = new PHPUnit_Framework_TestSuite('ExampleTest'); PHPUnit_TextUI_TestRunner::run($suite); </code></pre> <hr> <p><strong>Edit</strong> </p> <p>Just spotted Ubuntu 10.10 in your question. For Ubuntu install I recommend this: in terminal do:</p> <pre><code>sudo pear uninstall phpunit/PHPUnit sudo apt-get install phpunit sudo /etc/init.d/apache2 restart </code></pre> <p>Note: Don't issue the first line if you didn't install phpunit through pear. The last line seems to be needed (in my case at least).</p> <pre><code>sudo /etc/init.d/apache2 reload # Or sudo service apache2 restart </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload