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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:05:55+00:00 2026-06-02T05:05:55+00:00

PHPUnit contains an assertEquals() method, but it also has an assertSame() one. At first

  • 0

PHPUnit contains an assertEquals() method, but it also has an assertSame() one. At first glance it looks like they do the same thing.

What is the difference between the two? Why are they both specified?

  • 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-02T05:05:57+00:00Added an answer on June 2, 2026 at 5:05 am

    I use both sporadically, but according to the docs:

    assertSame

    Reports an error identified by $message if the two variables $expected and $actual do not have the same type and value.”

    And as you can see in the example below the above excerpt, they are passing '2204' and 2204, which will fail using assertSame because one is a string and one is an int, basically:

    '2204' !== 2204
    assertSame('2204', 2204) // this test fails
    

    assertEquals

    “Reports an error identified by $message if the two variables $expected and $actual are not equal.”

    assertEquals does not appear to take datatype into consideration so using the above example of 2204:

    '2204' == 2204
    assertEquals('2204', 2204) // this test passes
    

    I just ran some unit tests against the above examples, and indeed they resulted in documented behavior.

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

Sidebar

Related Questions

I installed PHPUnit and my Test class looks like this: require_once 'PHPUnit/Framework/TestCase.php'; class Test
I have been using PHPUnit for a while now, but suddenly hit a big
I using PHPUnit and Selenium Server to testing Yii Application, but whenever i tried
PHPUnit seems to execute properly (appropriate tests are executed & pass), but during code
PHPunit can create a multitude of result reports, but I am having trouble figuring
With PHPUnit it's quite easy to test raw PHP code, but what about code
I have a PHPUnit Test class that I'd like to be ignored from a
PHPUnit 's own manual has some as-yet-unwritten sections entitled Operations and Database Testing Best
I use PHPUnit for unit tests, but when a fatal error is triggered, the
I'm using PHPUnit but find it difficult to make it create good mocks and

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.