Online PHP editor is going to be changed...

We are going to:

  1. Redesign the site
  2. Work with SSH instead of FTP
  3. Switch to HTTPS
  4. Work without "session" to improve security
  5. And, of course, remain open source

Please consider...

  1. Checking our new PHP blog
  2. Visit the new Facebook page


I'm using SSH and I will continue using online-php.com

<? Online-PHP::Tutorials ?>

« Back

  • UnitTesting with phpRack

     

    Hello all,

    phpUnit

    The first framework I saw after a little googling, was the phpUnit (PEAR) framework - it was positioned as the one and the best framework for performing tests in PHP (according to google results). The installation instructions were relatively complicated, involving some PEAR command line installations, and some configuration modifications. That seemed too complicated for just runnung a few tests for my applications. Ofcourse I've installed in and run some tests, (by the way, the code was relatively clear and simple) but I did not like running the tests from the command line. Once you are on a shared hosting or some server with no access to the command line, you have a problem.

    phpRack

    After seeking for a convenient unit testing method and its simplest implementations in PHP, I've noticed phpRack testing framework. The first thing I saw was the simplicity in installing and using (ofcourse after browsing their website). Some very simple tutorials and examples convinced me to try it.

    The step-by-step instructions were perfect. lead me to run my tests in a few minutes. So here they are with a little explanation:

    • To create phprack.php file in your public_html directory - it's important to create the file in the public_html root directory (I has some problems with it). The library itself was in the public_html folder hierarchy.
    • To create PHP integration tests in your rack-tests directory - I've put the directory in public_html/rack-tests directory
    • The code in my phpRack.php was pretty same as their tutorial file:
      <?php
      // this param is mandatory, others are optional
      $phpRackConfig = array(
          'dir' => 'rack-tests',
      );
      // absolute path to the bootstrap script on your server
      include '../phpRack/bootstrap.php';
      
    • The first test looked like:
      <?php
      // the name of the file should be also mytest.php
      class MyTest extends phpRack_Test
      {
          public function testPhpVersionIsCorrect()
          {
              $this->assert->success('this is the success mess;
          }
      }

     

    For conclusion, there are much more available assert functions except fail and success, you can see it the full assertions list on their site.

    I liked the library, and hope to use it in the future.

    Enjoy you too,
    Greg.