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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:49:04+00:00 2026-06-12T06:49:04+00:00

It seems that many people think that unit testing setters and getters is just

  • 0

It seems that many people think that unit testing setters and getters is just a waste of time, and the accessors should be tested only when contain some sort of logic. I agree.

But what about properties that require some (small amout of) logic?

class DeliveryReportEvent extends Event
{
    private static $reasonMap = array(
        '401' => "Message expired (device off/not reachable)",
        '201' => "Operator network malfunctioning",
        '203' => "Recipient unreachable (in roaming)",
        '301' => "Invalid recipient (nonexistent/on portability/not enabled)",
        '302' => "Wrong number",
        '303' => "SMS service not enabled",
    );

    private $errorCode;

    public function __construct($errorCode)
    {
        $this->errorCode = $errorCode;

        if(array_key_exists($errorCode, self::$reasonMap)) {
            $this->errorReason = self::$reasonMap;
        }
    }

    public function getErrorCode()
    {
        return $this->errorCode;
    }

    public function getErrorReason()
    {
        return $this->errorReason;
    }
}

While testing getErrorCode() may sound stupid (because the absence of logic and IDE features), do you thing that testing getErrorReason() makes sense?

/**
 * @dataProvider getKnownErrorCodesAndReasons
 */
public function testErrorReasonWithKnownErrorCodes($knownErrorCode,
    $expectedErrorReason)
{
    $event = $this->getMockDeliveryReportEvent($knownErrorCode);

    $actualErrorReason = $event->getErrorReason();

    $this->assertNotNull($errorReason);
    $this->assertContains($expectedErrorReason, $actualErrorReason, '', true);
}

public function getKnownErrorCodesAndReasons()
{
    return array(
        array('401', "expired"),
        array('201', "network malfunctioning"),
        array('203', "unreachable"),
        array('301', "invalid recipient"),
        array('302', "wrong number"),
        array('303', "not enabled"),
    );
}
  • 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-12T06:49:05+00:00Added an answer on June 12, 2026 at 6:49 am

    It is all subjective and depends on many factors such as:

    • what level of code coverage do you want your test cases to have?
      Some release management systems define this coverage and need it to be satisfied along with other criteria before release confirmation.
    • Is the getErrorReason() a critical function (in-spite of how small its internal logic is)? In other words will it break the system if it gets messed up?

    Also depends on other factors like:

    • How much free time do you have?
    • How much of a purist are you?
    • Do you have a mustache?

    etc, etc.. 🙂

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

Sidebar

Related Questions

Seems to be a problem that many people have, but all the answers I
I just don't know what to think anymore. It seems like the people who
It seems that the following is a common method given in many tutorials on
There are many questions like this but I can't find one that seems to
It seems that runClasses() doesn't terminate the code being tested even after the test
It seems that JavaScript's Date() function can only return local date and time. Is
It seems that many of the JavaScript questions are answered by the simple use
It seems to me that many of the questions in the Perl tag could
It seems like many people have some issues once they start adding video into
it seems that most of the time, the speed gained is not worth it

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.