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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:54:40+00:00 2026-05-11T18:54:40+00:00

At the risk of being flamed… what advantage does enforcing calls to methods rather

  • 0

At the risk of being flamed… what advantage does enforcing calls to methods rather than functions have in a context where the context is implicit.

Considering that PHP’s syntax is so ugly for calling methods why would PHPUnit’s creators have enforced its usage?

If the framework had set a global “currentTestCase” object and then transparently associated failed asserts with that object we could be writing:

assertEquals("blah", $text);

as opposed to the equivalent, but verbose:

$this->assertEquals("blah", $text);

What exactly do we get by using OO in this context.

Please enlighten me.

  • 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-11T18:54:40+00:00Added an answer on May 11, 2026 at 6:54 pm

    Because PHPUnit is derived from xUnit and that’s how xUnit does it.

    Why does xUnit do it that way? I’m glad you asked. The original reason, as Robert points out, is that xUnit comes from Smalltalk and was popularized by JUnit in Java. Both are OO-or-nothing languages so they had no choice.

    This is not to say there are not other advantages. OO tests can be inherited. This means if you want to test a subclass you can run all the parent’s tests and just override the handful of test methods for the behaviors you’ve changed. This gives you excellent coverage of subclasses without having to duplicate test code.

    Its easy to add and override assert methods in PHPUnit. Just subclass PHPUnit_Framework_TestCase, write your own assert methods and have your test classes inherit from your new subclass. You can also write default setup and teardown methods.

    Finally, it guarantees that the test framework’s methods aren’t going to clash with the thing that they’re testing. If the test framework just dumped its functions into the test and you wanted to test something that had a setup method… well you’re in trouble.

    That said, I hear your pain. A big test framework can be annoying and cumbersome and brittle. Perl doesn’t use an xUnit style, it uses a procedural style with short test function names. See Test::More for an example. Behind the scenes it does just what you suggested, there’s a singleton test instance object which all the functions use. There’s also a hybrid procedural assert functions with OO test methods module called Test::Class which does the best of both worlds.

    Considering that PHP’s syntax is so ugly for calling methods

    I guess you don’t like the ->. I suggest you learn to live with it. OO PHP is so much nicer than the alternative.

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

Sidebar

Related Questions

I have Common.dll that's shared/used by (far more than) two SharePoint packages being deployed
I realize this comes at an enormous risk of being branded subjective and discussion-based,
i have 3 Array X,Y,Risk. i added a list generic (listtraining). if i click
I am trying to assess our security risk if we allow to have a
With the risk of being redirected to a dublicate question, what is the difference
Assuming that the variable isn't in any risk of being modified during the reads,
Currently I have few methods that accept GridView object as parameter and the value
I have implemented an ajax-polling script that calls an action in the server Controller
At risk of being told this is a duplicate question, I am trying to
At the risk of being downmodded, I want to ask what the best mechanism

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.