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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:47:30+00:00 2026-06-15T13:47:30+00:00

I am starting to play with phpunit, and my exposure to OO PHP is

  • 0

I am starting to play with phpunit, and my exposure to OO PHP is limited, so I think I’m missing something fundamental. When setting up a very simple test, I get the error Trying to get property of non-object.

This is what I’m trying to test

class Employee
{
    protected $jobTypeModifier, $manager, $id;
    public $name, $employee, $years, $allowances, $allowances_left, $extra, $carried, $totalTaken, $holidays;

    function Employee($id)
    {
        $this->jobTypeModifier = 1;
        $this->manager = 0;
        $this->totalTaken = 0;
        $this->setEmployeeId($id);
    }

    function myId()
    {
        return $this->id;
    }
}

And this is my test

class EmployeeTest extends PHPUnit_Framework_TestCase
{
    protected $employee;

    protected function setUp(){
        $this->employee = new Employee(1);
    }

    protected function tearDown() {
        unset($this->employee);
    }

    public function testMyId()
    {
        $actual = $this->employee->myId();
        $expected = 1;
        $this->assertEquals($actual, $expected);
    }
}

I assume I’m missing something fundamental / obvious here?

  • 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-15T13:47:31+00:00Added an answer on June 15, 2026 at 1:47 pm

    Ok,

    • first of all as I said in comment:

    First of all from PHP 5.3.3 your “Employee” won’t be treated as
    construct but just regular method. Use __construct as constructor.
    Check which version oh PHP do you have.

    • in your method Employee you call non-existing method setEmployeeId

    • separate your properties line by line

    • use public/protected/private when you define your methods

    • In assertions the expected value should pass as a first argument

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

Sidebar

Related Questions

I am just starting to play with nservice bus and am trying to get
I'm just starting to play with MVC, and something isn't clicking with me. I
I'm just starting to play with asp.net mvc and I've got a very basic
I'm just starting to play with Backbone JS as we are starting a very
I'm starting to play with Heroku to deploy a simple Node.js in their free
I'm starting to play around with Boomerang for measuring performance. It's very promising. While
I'm starting to play with arrays, but i'm stuck with something that seems yet
Just starting to play around with Flask on a local server and I'm noticing
I just starting to play around with iOS and web services. I'm writing a
I'm just starting to play around with GTK+ and I wanted to stop bad

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.