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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:42:44+00:00 2026-05-27T18:42:44+00:00

Well, I’m new to unit-testing (with phpUnit) and just started to test one class

  • 0

Well, I’m new to unit-testing (with phpUnit) and just started to test one class of mine.

Actual constructor looks like this:

/**
 * Loads configuration.
 */
function __construct() {

    $config =
        Kohana::$config->load('koffee');

    $this->_table_name = $config->table_name;
    $this->_table_columns = $config->table_columns;

}

It basically gets configuration from another file and sets it as protected properties to that object.

Here is how unit-test looks (it’s not finished and that’s where I need help):

/**
 * Tests that config is loaded and correct.
 */
function testConfigIsLoadedAndCorrect() {

    $object = new Model_Article();

    $config = Kohana::$config->load('koffee');

    // Compare object's **protected** properties to local `$config`. How?!

}

The problem is that properties are protected and I cannot access them so easy…

Possible solutions I see at the moment:

  1. Change visibility of properties (I don’t like this),
  2. Add, so called, “getters” to class I test – not unit-test (I don’t like this neither);

Probably this is funny to you, but, as I said, I’m new to unit-tests. Any help much appreciated.

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

    Unit-testing is about unit testing. Protected members are not part of the public interface of a unit, which is all you should need to care about when writing unit tests.

    You don’t test the inner guts of a unit, but that it works as expected.

    If you regardless of that want to do such stuff, you can use Serialization­Docs, casting to array and Reflection­Docs to inspect protected/private properties of an object or to execute protected/private methods of an object.


    See as well: PhpUnit private method testingSO Q&A

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

Sidebar

Related Questions

Well, I just started to work on server side scripting , I chose PHP,
Well, this one is my XML file <?xml version=1.0 encoding=utf-8?> <config> <setup> <Test>10</Test> <Copy>
Well new to the java stuff and having trouble with assigning a class attribute
Well, after a long time writing .net programs in C# I started to feel
Well, what is one?
Well, I am storing variables inside of a class that will be used for
well. For a single module in terms of regression testing In order to improve
Well, sorry for the question, is more like a general culture one (haven't found
Well, i'm learning to work with QML and i have one doubt. In my
Well I run a small video website and on the actual video page there

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.