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

  • Home
  • SEARCH
  • 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 566351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:58:05+00:00 2026-05-13T12:58:05+00:00

I’d like to run unit test for a functions library file… that is, I

  • 0

I’d like to run unit test for a functions library file…

that is, I don’t have a class, it’s just a file with helper functions in it…

for example, I’ve created a php project at ~/www/test

and a file ~/www/test/lib/format.php

<?php

function toUpper( $text ) {
  return strtoupper( $text );
}

function toLower( $text ) {
  return strtolower( $text );
}

function toProper( $text ) {
  return toUpper( substr( $text, 0, 1 ) ) .  toLower( substr( $text, 1) );
}
?>

tools -> create PHPUnit tests gives me the following error:

PHPUnit 3.4.5 by Sebastian Bergmann.

Could not find class “format” in
“/home/sas/www/test/lib/format.php”.

now, if I code (by hand!) the file
~/www/test/tests/lib/FormatTest.php

<?php
require_once 'PHPUnit/Framework.php';
require_once dirname(__FILE__).'/../../lib/format.php';

class FormatTest extends PHPUnit_Framework_TestCase {

  protected function setUp() {}

  protected function tearDown() {}

  public function testToProper() {
    $this->assertEquals(
            'Sebastian',
            toProper( 'sebastian' )
    );
  }
}
?>

it works fine, I can run it…

but if I select test file from format.php i get

Test file for the selected source file
was not found

any idea?

saludos

sas

ps: another question, is there a way to update generated tests without having to manually delete them???

ps2: using netbeans 2.8 dev

  • 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-13T12:58:05+00:00Added an answer on May 13, 2026 at 12:58 pm

    How you’ve written your Unit test case is 100% correct. The problem lies with common convention and how PHPUnit and Netbeans relies on them.

    Best practice these days is to write all your code in an object orientated fashion. So instead of having a PHP file full of utility functions like you have, you wrap these functions into a class and have them as static functions. Here’s an example using your code above,

    <?php
    
    class Format
    {
        public static function toUpper($text)
        {
            return strtoupper($text);
        }
    
        public static function toLower($text)
        {
            return strtolower($text);
        }
    
        public static function toProper($text)
        {
            return self::toUpper(substr($text, 0, 1 )) .  self::toLower(substr($text, 1));
        }
    }
    

    You’d now use your functions like so,

    Format::toProper('something');
    

    PHPUnit, and Netbeans, depend on this object orientated philosophy. When you try to automatically generate a PHPUnit test case, PHPUnit looks in your file for a class. It then creates a test case based on this class and it’s public API, and calls it ClassNameTest, where ClassName is the name of the class being tested.

    Neatbeans also follows this convention and knows that ClassNameTest is a PHPUnit test case for ClassName, so creates a link between the two in the IDE.

    So, my advice is to always use classes where you can. If you have utility functions that don’t depend on anything and are used globally, make them static ones.

    Side note: I’d get rid of your two functions toUpper() and toLower(). There’s no need to wrap built in PHP functions when there’s no need to. There’s also no need to test them as they are thoroughly tested.

    Site note 2: There’s kind of a built in PHP equivalent to your function toProper() called ucfirst().

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

Sidebar

Ask A Question

Stats

  • Questions 271k
  • Answers 271k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's possible that a member of one of your parameters… May 13, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer You should be using the exposed properties instead of putting… May 13, 2026 at 1:49 pm
  • Editorial Team
    Editorial Team added an answer It is. Look at the Twitter API Wiki and watch… May 13, 2026 at 1:49 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.