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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:36:11+00:00 2026-06-15T03:36:11+00:00

So I have a very simple (at least right now it is) model that

  • 0

So I have a very simple (at least right now it is) model that returns a contact via it’s primary key ID:

class Model_Contact extends \Fuel\Core\Model
{
    public function get_by_id($contact_id)
    {
        return Entity_Contact::find_by_pk($contact_id);
    }
}

The Entity_Contact class looks like this (irrelevant array content omitted):

class Entity_Contact extends \Core\Entity_Base
{
    protected static $_table_name = 'contacts';
    protected static $_properties = array(...);
    protected static $_public_settable_properties = array(...);
    protected static $_rules = array(...);
}

Note: \Core\Entity_Base extends \Fuel\Core\Model_Crud

I might use this in a controller like so:

$model = new Model_Contact();
$contact = $model->get_by_id(4);

I know that in order to unit test this, I should mock out the actual database call (Entity_Contact::find_by_pk), but I’m not sure how to do this. Since I’m using Fuel’s Model_crud functionality (where the DB accessors are actually a part of the domain object model), I’m not sure that I can completely mock the database—or maybe I’m missing something.

So the question: how would you write a test for Model_Contact::get_by_id()?

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-06-15T03:36:12+00:00Added an answer on June 15, 2026 at 3:36 am

    Your test may have to create the objects so you can test your methods.

    1. Create the objects that get stored to the database.
    2. Test get_by_id
    3. Delete your created object

    It’s not the most glorious thing in the world, but it would accomplish testing your method… meh?

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

Sidebar

Related Questions

Supose we have a very simple model: Station has at least one Train Train
Here's my issue: I have a very simple html website teaser right now with
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
Here is one very simple question(or at least at first sight).Let's say we have
I have a weird case here.... I'm making a simple magento module right now.
Very simple example: Model: require 'inventory' class CustomerOrder < ActiveRecord::Base validates_presence_of :name validate :must_have_at_least_one_item,
I currently have a very simple model Coupon. I suddenly am interested to add
I have a very simple bit of code that won't work, and have no
I have very simple piece of code. The goal is when i input four-digit
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As

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.