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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:04:04+00:00 2026-06-02T15:04:04+00:00

I am beginning to get into more OO PHP and also writing tests for

  • 0

I am beginning to get into more OO PHP and also writing tests for that objects. My main question is: if I have a Blog_Post object, and I call $post->setCategory( 'Foo' ), should doing that save to the database directly?

The reason I ask is for unit testing, I often don’t want to use the DB for these kind of things because that’s not what I am testing.

I have seen people suggest doing something like

function __construct( PDO $db )

to pass in the database object to be used, then use mock when testing. However, I really don’t like the idea of having instantiate my database objects all the time by whatever is calling the Blog_Post class.

This is in the scope of WordPress, which does not have an OO approach fundamentally – with my current Blog_Post, the setter method would just call the DB (via a global $wpdb!! (i know!)).

Really I wanted to know, what’s the general pattern that is the path of least resistance with something like this. Would Blog_Post just write it’s self, or would one maybe put on a “save()” method to actually push all set properties to the DB? Or perhaps set a flag on teh object “setSaveToDB(false)” before calling the setter.

Thanks, hope this make some sense!

  • 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-06-02T15:04:05+00:00Added an answer on June 2, 2026 at 3:04 pm

    Short answer: No. Delegate loading, saving to another layer.

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

Sidebar

Related Questions

I am just beginning to get into desktop application development, and have chosen C#
Afternoon Developers, I have a problem that's beginning to get on my wick. I
I'm beginning to think that to get a ProgressDialog to work the AsyncTask has
I have 2 queries that get involved in a deadlock situaution displayed in the
I am beginning to delve deeper into Perl, but am having trouble writing Perl-ly
I'm running into this strange issue. Basically I have a loop that loops forever,
I realize that this is a question that will probably not have a single
I have an air application that I'd like to turn into a multi-player game.
I am beginning to work with Express JS and have run into an issue.
Lately, I have been doing some research into cryptography. To get a better understanding

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.