+ Reply to Thread
Results 1 to 4 of 4

Thread: Zend_Test: how to set up?

  1. #1
    ZFerik is offline Junior Member
    Join Date
    Sep 2008
    Posts
    1

    Default Zend_Test: how to set up?

    I've been reading the Zend_Test documentation over and over again, but I can't figure out how to actually call the Test classes. I mean, a normal "page" is just called by example.com/controller/action or example.com/module/controller/action. But how do I run a test? Should I install PHPUnit for that? Or is there some way to call a test from the browser? And where do I put the test-files?

    I understand how to write tests, I just can't figure out how to run them and where to put the files.

    Thx!

  2. #2
    benrice is offline Junior Member
    Join Date
    Nov 2008
    Posts
    1

    Default Zend_test setup

    Quote Originally Posted by ZFerik View Post
    I've been reading the Zend_Test documentation over and over again, but I can't figure out how to actually call the Test classes. I mean, a normal "page" is just called by example.com/controller/action or example.com/module/controller/action. But how do I run a test? Should I install PHPUnit for that? Or is there some way to call a test from the browser? And where do I put the test-files?

    I understand how to write tests, I just can't figure out how to run them and where to put the files.

    Thx!
    Did you ever find an answer to this?

    Thanks!

  3. #3
    phpoet's Avatar
    phpoet is offline Junior Member
    Join Date
    Sep 2008
    Posts
    26

    Default Testing With The Zend Framework

    The way I have been testing my models is through using PHPUnit. I just wrote a tutorial for installing and configuring the Zend Framework and I'll be putting together another lesson about testing in the future.

    After installing PHPUnit, I create a 'tests' folder on the same level as my application and library folders - outside the root directory of the web site. Then I create a bootstrap file just for my tests that looks something like this.

    Code:
    <?php
    //File name: TestConfiguration.php
    
    TestConfiguration::setUp();
    
    class TestConfiguration {
      
      public static function setUp() {
        require_once 'PHPUnit/Framework.php';     
        require_once 'PHPUnit/Framework/TestSuite.php';    
        require_once 'PHPUnit/TextUI/TestRunner.php';
        
        error_reporting( E_ALL | E_STRICT );
        
        $appRoot = realpath(dirname(basename(__FILE__)).'/..');
        
        set_include_path($appRoot . '/application/models/' 
                . PATH_SEPARATOR . $appRoot . '/library/'
                . PATH_SEPARATOR . $appRoot . '/application/config/'
                . PATH_SEPARATOR . get_include_path()); 
    
        require_once 'Zend/Loader.php';
        Zend_Loader::registerAutoload(); 
        
        // Set up the config in the registry path relative to public/index.php
        $cfg = new Zend_Config_Ini('config.ini', 'test'); 
        Zend_Registry::set('config', $cfg);
    
        // Set up the database in the Registry
        $db = Zend_Db::factory($cfg->db);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        
        // Set timezone
        date_default_timezone_set("America/New_York");
      }
      
    }
    ?>
    Than I write tests and put them in my tests/models folder. A test file looks something like this.

    Code:
    <?php
    // File name: Models_AddressTest.php
    
    require_once dirname(__FILE__) . '/../TestConfiguration.php';
    
    class Models_AddressTest extends PHPUnit_Framework_TestCase {
    
      public function testValidObject() {
        /* some code to test stuff */
        $this->assertEquals(0, count($errors));
      }
      
    }
    
    ?>
    Finally, to run the test I will open up a terminal, cd to my tests directory then type: phpunit Models_AddressTest

  4. #4
    mariaschon is offline Junior Member
    Join Date
    Apr 2009
    Posts
    2

    Default

    Thank a lot, nice post! But when I run it, it says
    Could not open input file: .\pear\PHPUnit2\TextUI\TestRunner.php
    Do you have any idea whats wrong?

    I can run test from:
    C:\projects\Prova\php\phpunit2>php stringtest.php


    TestCase ArrTest->testNewArrayIsEmpty() passed
    TestCase ArrTest->testArrayContainsAnElement() passed

    Thanks again!
    Maria

+ Reply to Thread

Similar Threads

  1. Zend_Test - assertQueryContentContains() &nbsp;
    By mark2331 in forum Model-View-Controller (MVC)
    Replies: 0
    Last Post: 07-27-2010, 12:01 AM
  2. How to properly use Zend_Test and Zend_AMF
    By shinank in forum Core Infrastructure
    Replies: 0
    Last Post: 01-29-2010, 12:58 PM
  3. PHPUnit & Zend_Test with ZF 1.8
    By mark2331 in forum Resources for Developers
    Replies: 0
    Last Post: 05-21-2009, 12:38 AM
  4. Zend_Test help
    By toonevdb in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 02-19-2009, 03:54 PM
  5. Zend_Test...::assertRedirectTo
    By storeman in forum Model-View-Controller (MVC)
    Replies: 1
    Last Post: 01-21-2009, 01:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts