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

  • Home
  • SEARCH
  • 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 815159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:38:21+00:00 2026-05-15T01:38:21+00:00

I am new into PHPUnit and just digging through the manual I cannot find

  • 0

I am new into PHPUnit and just digging through the manual I cannot find a decent example of how to build a complete test from end-to-end though, and so, I’m left with questions.

One of these is how can I prep my environment to properly test my code?

I am trying to figure out how to properly pass various configuration values needed for both the test setup/teardown methods, and the configs for the class itself.

// How can I set these variables on testing start?
protected $_db = null;
protected $_config = null;

// So that this function runs properly?
public function setUp(){
    $this->_acl = new acl(
        $this->_db,    // The database connection for the class passed 
                       // from whatever test construct

        $this->_config // Config values passed in from construct
    );
}

// Can I just drop in a construct like this, and have it work properly?
// And if so, how can I set the construct call properly?
public function __construct(
    Zend_Db_Adapter_Abstract $db, $config = array(),
    $baselinedatabase = NULL, $databaseteardown = NULL
){
    $this->_db = $db;
    $this->_config = $config;
    $this->_baselinedatabase = $baselinedatabase;
    $this->_databaseteardown = $databaseteardown;
}

// Or is the wrong idea to be pursuing?
  • 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. Editorial Team
    Editorial Team
    2026-05-15T01:38:22+00:00Added an answer on May 15, 2026 at 1:38 am

    Since it seems like you’re working with Zend Framework, I can tell how we did it, but I can’t vouch it’s THE right solution. But it works 🙂

    All tests are in a separate tests folder which has Test Suite defined as an XML(so you run it with phpunit –configuration TestSuite.xml command). At the root level there is the TestHelper file however that every test is invoking and that does bootstraping by calling into application’s bootstrap class. In app. bootstrap there is a method and does much of bootstrapping but without actual request dispatching. So what you have after running such method will be a ready to use environment(where you have all your Zend_Db, log, modules etc. assembled and ready to go) that unit tests can use.
    Call into TestHelper happens at the very beginning of each unit test class. Here is a quick example:

    /**
     * Unit test for GeoAddressTable model
     * (skipped)
     */
    
    // Call GeoAddressTableTest::main() if this source file is executed directly.
    if (!defined('PHPUnit_MAIN_METHOD')) {
            define('PHPUnit_MAIN_METHOD', 'GeoAddressTableTest::main');
    }
    
    require_once 'PHPUnit/Framework.php';
    
    require_once dirname(dirname(__FILE__)).'/GeoTestHelper.php';
    

    Hope this helps

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

Sidebar

Ask A Question

Stats

  • Questions 395k
  • Answers 395k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could store a list of what has already been… May 15, 2026 at 2:47 am
  • Editorial Team
    Editorial Team added an answer If this is your selector, there are a few issues… May 15, 2026 at 2:47 am
  • Editorial Team
    Editorial Team added an answer I think it's just like any other company or person… May 15, 2026 at 2:47 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.