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 614133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:04:45+00:00 2026-05-13T18:04:45+00:00

followed by my previous website development,we have built several controller classs corresponding to entities

  • 0

followed by my previous website development,we have built several controller classs corresponding to entities that will appear in our website development.and our website is very simple:just a shopping website for customers to book bus for travel.

Now I am assigned a challenging task that need to be done,that is ,for a single controller class,I need to write a test case to test whether it is working properly.

For example,we have a controller class called “JobsController”,like:

models = array( ‘jobs’ => new Jobs() );
}

function __destruct()
{
parent::__destruct();
}

function addJob( $name , $desc )
{
if( $name == ” )
{
return false;
};

$params = array( ‘name’ => $name ,
‘description’ => $desc );

return $this->models[‘jobs’]->add( $params );
}

function modifyJob( $jid , $name , $desc )
{
if( $jid == ” || $name == ” )
{
return false;
};

$params = array( ‘name’ => $name ,
‘description’ => $desc );

return $this->models[‘jobs’]->modify( $jid , $params );
}

function removeJob( $jid )
{
if( $jid == ” )
{
return false;
};

return $this->models[‘jobs’]->remove( $jid );
}

function getJob( $jid )
{
return $this->models[‘jobs’]->getInfo( $jid );
}

function getAllJobs()
{
return $this->models[‘jobs’]->getAll();
}

}

?>

and all other Controller class are almost the same,just with name changes.

Now I really need you guys help me a bit how on to write a simple php file to test whether this Controller Class is working properly.After studying your code,I could get my hands on it to work with the rest controllers myself.

Many thank!

  • 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-13T18:04:45+00:00Added an answer on May 13, 2026 at 6:04 pm

    When writing test cases you are basically testing a before and after scenario. Before the test is run you want to initialize a clean environment (every time) to ensure you know what to expect. Next you’ll run your methods and test what the environment is like afterward, confirming whether or not the action you took had the desired affect.

    For example to test your modifyJob method you want to create an environment with a job, call the modifyJob method with test values, and then call getJob on the same job and ensure that the return value has values matching what you passed in to modifyJob:

    function testModifyJob() {
      // create clean, known environment
      $controller = new JobsController();
      $job_id = $controller->addJob('name', 'description');
    
      // run the action
      $controller->modifyJob($job_id, 'new name', 'new description');
    
      //test the results
      $job = $controller->getJob($job_id);
      $result = $job['name'] == 'new name' && $job['description'] == 'new description';
    
      return $result;
    }
    

    For testing your controller you’re going to want to write test cases like the one above for each of the methods the class provides to ensure that the object can be trusted within your system.

    When writing your test cases you’ll most likely have a need to create new methods on your controller just for your tests, go ahead and create these (if your assignment permits). It’s very common for test cases to bring this up and usually helps round out the available functionality of your classes by bringing these nuances to light (one of the reasons test-driven development has such a strong following). An example of this would be creating a hasJob($job_id) method that would test if your jobs collection contains a specific job, allowing you to test functions such as deleteJob().

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

Sidebar

Ask A Question

Stats

  • Questions 307k
  • Answers 307k
  • 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 have to select the method and Alt+Enter will give… May 13, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer That is done by the browsers, if you are under… May 13, 2026 at 9:27 pm
  • Editorial Team
    Editorial Team added an answer Do you need exactly a cmdlet? I wonder why you… May 13, 2026 at 9:27 pm

Related Questions

This is related to my previous question More than 1 Left joins in MSAccess
I have a page where i have multiple textboxes followed by a browse link,
my understanding of the entropy formula is that it's used to compute the minimum
I have uncovered another problem in the effort that we are making to port
I am attempting to build a .PLY parser to load 3d models stored as

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.