SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy php unit test examples for server stubs and mock objects

    I'm trying to learn how to unit test, but I'm having a hell of a time doing so. Can someone post some (useful and simple) tutorials, or recommend books that contain examples of unit testing using server stubs and mock objects? I'm currently using simpletest for unit testing and I have gone over their api tutorials for both those section numerous times and it's not clicking.

    The examples shown in the simpletest tutorials / documentation don't really show the significance of using those test patterns which makes them harder to grasp. I've also tried going through the php architects book, but I had more luck with the simpletest documentation..., so yeah... Thanks in advance.
    My First Website YouCritiqueIT.com
    - A unique approach to rating products

  2. #2
    SitePoint Enthusiast dakine's Avatar
    Join Date
    Dec 2006
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check out http://phpunit.de, its a really good PHP unit testing framework with lots of information and tutorials with a few screencasts too!

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I took a look at the mock and server stub section and it didn't really help much. I also couldn't find the screencasts (are those video tutorials)? Anyways it's more the concept of using them. I understand that server stubs replace some external component of the system (a class). It's just the way the testing is done that seems pointless. For example this is right off the simpletest api tutorial site

    Code:
       1. require_once('simpletest/mock_objects.php');
       2. require_once('database_connection.php');
       3. Stub::generate('DatabaseConnection');
    
    This generates a clone class called StubDatabaseConnection. We can now create instances of the new class within our prototype script...
    
       1. require_once('simpletest/mock_objects.php');
       2. require_once('database_connection.php');
       3. Stub::generate('DatabaseConnection');
       4.  
       5. $connection = new StubDatabaseConnection();
    
    The stub version of a class has all the methods of the original so that operations like $connection->query() are still legal. The return value will be null, but we can change that with...
    
       1. $connection->setReturnValue('query', 37)

    I don't get why you set a fixed return value for the query... It's always going to return the same thing, so how are you supposed to produce a meaningful test from that?
    My First Website YouCritiqueIT.com
    - A unique approach to rating products


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •