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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:53:33+00:00 2026-06-06T14:53:33+00:00

I have a PHPUnit Test which validates the output of a logfile with a

  • 0

I have a PHPUnit Test which validates the output of a logfile with a regexp. The logfile looks like this(First line is empty, but I don’t know how to display that here):

<empty line>
lfworker01:
-----------------------------------------------------------
Last update:               2012-06-14 11:43:17
Last Segment Sent:         2009-12-02 23:25:00 (1259792700)
Current Segement:          2009-12-03 00:25:00 (1259796300)
Clicks processed Segment:  3
Open sessions Segment:     1
Duration Segment:          0,06 sec
Speed Segment:             47,67 clicks/sec
Uptime:                    0 days 00:00:00
Clicks processed overall:  3
Avg Speed overall:         81,70 clicks/sec
Current memory used:       16,75 MB
Max memory used:           16,75 MB

I am validating the content with a regex:

    $strExpectedMeasurementLog = "#
lfworker01:
-----------------------------------------------------------
Last update:               \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}
Last Segment Sent:         2009-12-02 23:25:00 \(1259792700\)
Current Segement:          2009-12-03 00:25:00 \(1259796300\)
Clicks processed Segment:  3
Open sessions Segment:     1
Duration Segment:          \d*,\d{2} sec
Speed Segment:             \d*,\d{2} clicks/sec
Uptime:                    0 days 00:00:00
Clicks processed overall:  3
Avg Speed overall:         \d*,\d{2} clicks/sec
Current memory used:       \d*,\d{2} MB
Max memory used:           \d*,\d{2} MB#";

$strActualMeasurementLog = file_get_contents( dirname( __FILE__)."/applogs/measurement.log");
self::assertRegExp( $strExpectedMeasurementLog, $strActualMeasurementLog);

The PHPUnit test was created in a unix environment. This test passes in a unix test environment, but fails in a windows test environment. I have replaced windows line breaks with unix line breaks by appyling this function to the measurement.log file:

public function unixtodos( $strPathFile )
{
  $strCurrent = file_get_contents( $strPathFile );

  $strPattern = "|\r\n|";
  $strReplace = "\n";
  $strNew = preg_replace( $strPattern, $strReplace, $strCurrent );

  file_put_contents( $strPathFile, $strNew );
}

It still doesn’t match and I am out of ideas 🙁

  • 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-06T14:53:35+00:00Added an answer on June 6, 2026 at 2:53 pm

    The solution is to always check the line breaks. My logfile created on a windows machine with php has unix line breaks:

    Logfile created with php on windows

    The PHPUnit source file checked out of CVS in unix has unix line breaks:

    PHPUnit Source File in unix

    The PHPUnit source file checkout out of CVS in windows has windows line breaks:

    PHPUnit Source File in windows

    These line breaks broke my regex validation. So now I’m always replacing line breaks to unix line breaks.

    // replace possible windows line breaks with unix line breaks
    $strExpectedMeasurementLog = preg_replace( "|\r\n|", "\n", $strExpectedMeasurementLog);
    $strActualMeasurementLog = preg_replace( "|\r\n|", "\n", $strActualMeasurementLog);    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this simple rule: .PHONY: test test: src/*Test.php $(PHPUNIT) $?;\ it will look
I have a big phpunit test suite (in fact it's four testsuites for this
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 have been using PHPUnit for a while now, but suddenly hit a big
I have some needs, for a specific test type: I would like to check
I'm starting work with PHPUnit with Kohana. My application have many controllers which simply
So I have this builder that runs a buildClass method which should be public,
I have code like this: class ToBeTested { function simpleMethod($param) { if(0 === $param)
I have a testclass in which one test runs multiple times via a @dataProvider

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.