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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:09:39+00:00 2026-05-29T09:09:39+00:00

Situation I’m implementing a Listener for PHPUnit that will record test results to a

  • 0

Situation

I’m implementing a Listener for PHPUnit that will record test results to a DB for later review. I like the default information phpunit outputs to console when a failure, error, skipped, or incomplete test is encountered.

Example:

1) sandbox_ExtensionSampleTest::testError
printf(): Too few arguments

E:\ecom_testing\tests_v2\TestSuites\sandbox\Base.php:28
E:\ecom_testing\tests_v2\TestSuites\sandbox\ExtensionSampleTest.php:37
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:939
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:801
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestResult.php:649
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestCase.php:748
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestSuite.php:772
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\Framework\TestSuite.php:745
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\TestRunner.php:325
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\Command.php:187
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\pear\PHPUnit\TextUI\Command.php:125
C:\Program Files (x86)\EasyPHP-5.3.8.1\php\pear\phpunit:44

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

Note: I did find listing all the PHPUnit dependencies in the output is a bug, but the example above still shows two related test files.

Question

One of the parameters for an implemented listener method is Exception $e. I can get the message as well as the first line using $e, but I can’t seem to get the rest of the lines.

After reading Exceptions in the PHP manual, I thought using $e->getPrevious() would work… attempted to do the following:

// Storing in a array to put into a DB later
// First line with the message
$trace[] = sprintf(
    "%s\n\n%s:%s\n", 
    $e->getMessage(), 
    $e->getFile(), 
    $e->getLine()
);

// Go through the rest of the exceptions of files and lines
while ($e = $e->getPrevious()){
    $trace[] = sprintf(
        "%s:%s\n", 
        $e->getFile(), 
        $e->getLine()
    );
}

That didn’t work. It seems like $e->getPrevious() is empty and I did confirmed it when I dumped the object. I thought something like $e->getTraceAsString() would yield the same results, but it’s not what I expected (I haven’t used exceptions much)

  • 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-29T09:09:40+00:00Added an answer on May 29, 2026 at 9:09 am

    The list of file and line number combinations is called the stack trace. You can grab it as an array using Exception::getTrace() and walk it yourself, or you can let PHPUnit filter out its classes for you by calling PHPUnit_Util_Filter::getFilteredStacktrace(). Pass the exception $e and true to receive a formatted string, or pass false to get the filtered array back instead.

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

Sidebar

Related Questions

Situation: I have a simple XML document that contains image information. I need to
Situation There is a high chance that users will not interact directly with the
Situation: text: a string R: a regex that matches part of the string. This
Situation with Thai text on a client site is that we can't control where
Situation: I am trying to write a efficient query using "LIKE" statement to look
Situation: I am writing a program in C that maintains a number of threads.
Situation: I send an ajax request that returns HTML containing elements needing event handlers
Situation: I have an Xcode project based on the Navigation-Based-Application template. So that means
Situation I've got a worker thread that's being triggered by a condition_variable to do
Situation: I have many gzipped input files that I want to process in a

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.