Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 164365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:43:53+00:00 2026-05-11T11:43:53+00:00

Has anyone had any success setting up Zend_Test? What was your method/approach and how

  • 0

Has anyone had any success setting up Zend_Test? What was your method/approach and how do you run your tests/test suites?

I already have PHPUnit installed and working. Now I’m trying to write some simple controller tests. The Zend Framework documentation assumes that autoloading is setup, which I haven’t done. What method do you use to autoload the appropriate files? I do so in my normal bootstrap file, but I don’t want to clutter up my Test with a bunch of includes and setting up paths. Would an abstract controller test case class be the way to go?

What about the bootstrap plugin like the documentation uses…is that how you bootstrap your tests, or do you like to do it a different way? I would like to re-use as much of the regular bootstrap file as I can. How should I DRY up my bootstrap for testing and normal use?

Here’s my test so far:

<?php  class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {     public function setUp()     {         $this->bootstrap = array($this, 'appBootstrap');         parent::setUp();     }      public function appBootstrap()     {         $this->frontController->registerPlugin(new Bootstrapper('testing'));     }      public function testIndexAction()     {         $this->dispatch('/index');             $this->assertController('index');             $this->assertAction('index');     }  }  //straight from the documentation class Bootstrapper extends Zend_Controller_Plugin_Abstract {     /**      * @var Zend_Config      */     protected static $_config;      /**      * @var string Current environment      */     protected $_env;      /**      * @var Zend_Controller_Front      */     protected $_front;      /**      * @var string Path to application root      */     protected $_root;      /**      * Constructor      *      * Initialize environment, root path, and configuration.      *      * @param  string $env      * @param  string|null $root      * @return void      */     public function __construct($env, $root = null)     {         $this->_setEnv($env);         if (null === $root) {             $root = realpath(dirname(__FILE__) . '/../../../');         }         $this->_root = $root;          $this->initPhpConfig();          $this->_front = Zend_Controller_Front::getInstance();     }      /**      * Route startup      *      * @return void      */     public function routeStartup(Zend_Controller_Request_Abstract $request)     {         $this->initDb();         $this->initHelpers();         $this->initView();         $this->initPlugins();         $this->initRoutes();         $this->initControllers();     }      // definition of methods would follow... } 

What should I do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:43:53+00:00Added an answer on May 11, 2026 at 11:43 am

    Here’s what I did to get it to work:

    First, we need to resolve the autoloading issue. We’ll do this by creating a file that all the tests will include, and put it in the tests directory. Note: I pretty much copied all of this from my /public/index.php.

    # /tests/loader.php  <?php  define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application/'));  set_include_path( APPLICATION_PATH . '/../library' . PATH_SEPARATOR .                   APPLICATION_PATH . '/models' . PATH_SEPARATOR .                   APPLICATION_PATH . '/forms' . PATH_SEPARATOR .                   get_include_path() );  require_once 'Zend/Loader.php'; Zend_Loader::registerAutoload(); 

    Second, we need to include this file in our test. Our test file is in /tests/application/controllers/ . I’m not going to use my bootstrap as a plugin since my bootstrap file works the same way as the QuickStart tutorial. I’ll just link to it by setting the location as the public $bootstrap. When Zend_Test_PHPUnit_ControllerTestCase constructs, it will look for the bootstrap file that we set here.

    <?php  require_once '../../loader.php';  class IndexControllerTest extends Zend_Test_PHPUnit_ControllerTestCase {     public $bootstrap = '../../../application/bootstrap.php';      public function testIndexAction()     {         $this->dispatch('/index');         $this->assertController('index');         $this->assertAction('index');     }  } 

    And that’s it! If my bootstrap file was already a plugin, this might be a little more complicated, but since it’s not, it’s super easy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone had any success using a GPX route or track to test location
Has anyone had any success in getting Webistrano running on Windows. Everywhere I have
Has anyone had any success creating an info button (italic 'i' in a circle)
Has anyone had any success with libcurl and POP3 with APOP authentication? I had
Has anyone had any success in finding a reliable, generalised solution for managing dependencies
Has anyone had any success running two different web servers -- such as Apache
Has anyone had any success with adding additional information to a PDF file? We
Has anyone had any success using Hudson (or another similar build system) with Perl?
Has anyone had any success converting a VS 2008 C++/CLI (vcproj) project to a
I am sick of using a keyboard. Has anyone had any success with voice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.