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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:53:03+00:00 2026-05-12T19:53:03+00:00

I was trying to learn unit test with PHP. I know it’s a bit

  • 0

I was trying to learn unit test with PHP. I know it’s a bit too far for someone who just jump into unit test in PHP. Anyway, here’s the case:

function doresize(&$mp3file)
{
    global $tmpdir, $mp3info, $ffmpeg;

    if(dirname($mp3file) != $tmpdir )
    {
        copy($mp3file , $tmpdir . '/' . $mp3file);
        $mp3file = $tmpdir . '/' . $mp3file;
    }
    $mp3filenew = basename($file, '.swf') . "_new.mp3";

    $command2 = "$mp3info -x \"$mp3file\" 2> /dev/null";

    exec($command2, $buffer);

    $mp3length = getLengthFromBuffer($buffer);

    debug("  \$mp3length: $mp3length");

    $lengthTranslated = roundLengthToSeconds($mp3length);

    $maxlength = floor( $lengthTranslated / 2);

    $halfmaxlength = floor( $maxlength / 2);

    $start = rand($halfmaxlength, $maxlength);

    $command3 = "$ffmpeg -y -acodec copy -ss $start -t $maxlength -i \"$mp3file\" $mp3filenew 2> /dev/null";


    exec($command3);

    @unlink($mp3file);
    rename($mp3filenew, $mp3file);
}

From the code above, what aspect of that code should I add in test case?

FYI: The code above is used to cut mp3 file in half.

  • 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-12T19:53:03+00:00Added an answer on May 12, 2026 at 7:53 pm

    As I can see, you are using external program ffmpeg to do the work. So my suggestions are that:

    1) Test the command: You extract this function into two functions. One for generating the command (in this case is $command3). Create a unit test to check that the command is valid. Another function execute the command.

    2) Test the final result. You manually, create a result file. Do what ever it take (by hand) to ensure that the result file is what you want. Write a unit test to create the command, execute it and then compare the new output file and the file you have generate earlier. The comparison can be done by tools such as bsdiff or using php to read byte-by-byte (fread comes to mind) to compare them.

    You may create multiple files to do this test (like for each bandwidth, sample rate or codec).

    NOTE I that the second test might not work if the convert process always produce exactly the same binary.

    NOTE II If the conversion does not always produce exact same binary or it is not possible to have one test file to represent all other files. You have to do a more transparent test by knowing the format of the output file and analyze it. For example, read the original and ouptut file audio-length, sampling rates and compare it.

    Hope this helps.

    EDIT I forgot to say something. If you trust ffmpeg. You can simply skip Test 2 (binary comparison) entirely and only check the command.

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

Sidebar

Related Questions

I am trying to learn unit testing. I am trying to unit test some
Trying to learn a bit of CSS and I want a horizontal navbar and
Trying to learn a bit about PDO and is going through this tutorial .
Trying to learn about php's arrays today. I have a set of arrays like
Trying to learn MVP pattern with C#... Does anyone know of any particularly good
I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to
I'm looking at modifying a toy OS system and I'm just trying to learn
I am trying to learn about unit testing in Zend Framework. I have installed
Trying to learn some F# and I've run into a couple of hangups. Here's
I'm trying to learn dependency injection and have come across a problem, when unit

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.