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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:24:13+00:00 2026-05-15T06:24:13+00:00

With PHPUnit it’s quite easy to test raw PHP code, but what about code

  • 0

With PHPUnit it’s quite easy to test raw PHP code, but what about code that heavily relies on cookies? Sessions could be a good example.

Is there a method that doesn’t require me to setup $_COOKIE with data during my test? It feels like a hacky way of doing things.

  • 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-15T06:24:14+00:00Added an answer on May 15, 2026 at 6:24 am

    This is a common problem with code, especially lagacy PHP code. The common technique used is to further abstract the COOKIE/SESSION variables in related objects and using inversion of control technique(s) to pull those dependencies into scope.

    http://martinfowler.com/articles/injection.html

    Now before you execute a test you would instantiate a mock version of a Cookie/Session object and provide default data.

    I imagine, the same effect can be achieved with legacy code by simply overriding the super global value before executing the test.

    Cheers,
    Alex

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

Sidebar

Related Questions

I am using PHPUnit to test my PHP source code, but I need a
I have a PHPUnit test that's using a Doctrine2 custom repository and Doctrine Fixtures.
I have a PHPUnit test suite that is currently causing a fatal error due
I am running PHP unit as follows: phpunit --debug --verbose --coverage-clover=/tmp/test.xml and get the
I have a test suite for phpunit for my symfony application. In that test
PHPUnit seems to execute properly (appropriate tests are executed & pass), but during code
I'm using PHPUnit (3.6.7) to test and provide code coverage reports on my application,
So I have a PHPUnit test, and found this code within a function. global
I have a PHPUnit Test class that I'd like to be ignored from a
The current version of PHPUnit is 3.6, but until I update my code I

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.