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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:13:08+00:00 2026-05-11T00:13:08+00:00

I am trying to test a class that manages data access in the database

  • 0

I am trying to test a class that manages data access in the database (you know, CRUD, essentially). The DB library we’re using happens to have an API wherein you first get the table object by a static call:

function getFoo($id) {   $MyTableRepresentation = DB_DataObject::factory('mytable');   $MyTableRepresentation->get($id);   ... do some stuff   return $somedata } 

…you get the idea.

We’re trying to test this method, but mocking the DataObject stuff so that (a) we don’t need an actual db connection for the test, and (b) we don’t even need to include the DB_DataObject lib for the test.

However, in PHPUnit I can’t seem to get $this->getMock() to appropriately set up a static call. I have…

        $DB_DataObject = $this->getMock('DB_DataObject', array('factory')); 

…but the test still says unknown method ‘factory’. I know it’s creating the object, because before it said it couldn’t find DB_DataObject. Now it can. But, no method?

What I really want to do is to have two mock objects, one for the table object returned as well. So, not only do I need to specify that factory is a static call, but also that it returns some specified other mock object that I’ve already set up.

I should mention as a caveat that I did this in SimpleTest a while ago (can’t find the code) and it worked fine.

What gives?

[UPDATE]

I am starting to grasp that it has something to do with expects()

  • 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-11T00:13:08+00:00Added an answer on May 11, 2026 at 12:13 am

    I agree with both of you that it would be better not to use a static call. However, I guess I forgot to mention that DB_DataObject is a third party library, and the static call is their best practice for their code usage, not ours. There are other ways to use their objects that involve constructing the returned object directly. It just leaves those darned include/require statements in whatever class file is using that DB_DO class. That sucks because the tests will break (or just not be isolated) if you’re meanwhile trying to mock a class of the same name in your test–at least I think.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Check out this article that explains when this is necessary.… May 11, 2026 at 3:30 pm
  • added an answer swfobject.removeSWF('myVideoPlayer'); -- Edit: this kills off the original <DIV> that… May 11, 2026 at 3:30 pm
  • added an answer As long as your EventArgs inherit from System.EventArgs you will… May 11, 2026 at 3:30 pm

Related Questions

For deployment reasons, I am trying to use IJW to wrap a C# assembly
I am unit testing a class that calls ContextRegistry.GetContext().GetObject(ISomething) and it's ok if an
I have a class that contains a collection of objects. I am trying to
Hey all, I am trying to test if the argument passed into my function

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.