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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:21:01+00:00 2026-05-25T14:21:01+00:00

I have been learning MVC recently and have started creating my own framework (for

  • 0

I have been learning MVC recently and have started creating my own framework (for learning purposes only, of course) from http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

I want to be able to extend these base classes but first I would like to be able to unit test them. Does anyone have an idea how I would go about testing the base Controller, Model and Template classes?

Thanks in advance!

  • 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-25T14:21:01+00:00Added an answer on May 25, 2026 at 2:21 pm

    Just write test classes, preferably mirroring your framework structure (eg ControllerTest, ModelTest, etc), that put the classes through their paces, meaning putting in some data and checking the output. If your code is well-structured, should be quite easy to implement.

    Edit

    Basically, what you test in a unit test is if ( Class::methodToTest( $input ) === $expected_output ). The output must always be identical for the same $input. If this is not the case, or you can’t test write a test case like this, it’s often an indicator that your code is not well structured (object oriented and loosely coupled).

    Your Template::render() method for example, is not testable because it prints the data instead of returning it. Now, you could work around this by using ob_start(), but better anyway would be to chop the function into smaller parts, that return values instead of directly printing them.

    It’s a bit abstract, but I hope you get the point.

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

Sidebar

Related Questions

I have been learning .MVC recently and am having trouble understanding how to process
I have been working on my own library/framework for the learning experience for a
I have been learning C++ with some books from school that are from the
I've been learning the ASP.NET MVC framework using the Apress book Pro ASP.NET MVC
I have been learning ASP.NET MVC in the last few months and I think
I have been learning ASP.NET MVC for a few months. I have learned about
I have been learning to develop websites using ASP.NET MVC 2 for work... and
I have been learning RESTful webservices following this tutorial http://www.vogella.de/articles/REST/article.html . As I understand,
I have been learning java spring hibernate MVC for 3 months and got pretty
In my class we have been learning about different designs such as MVC and

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.