From af68030fcf0c266300feb2c100149ecadef7d364 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 16 Jul 2006 01:50:23 +0000 Subject: Merge from 3.0 branch till 1264. --- tests/test_tools/simpletest/docs/en/index.html | 48 +++++++++++--------------- 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'tests/test_tools/simpletest/docs/en/index.html') diff --git a/tests/test_tools/simpletest/docs/en/index.html b/tests/test_tools/simpletest/docs/en/index.html index 04797272..c7183c49 100755 --- a/tests/test_tools/simpletest/docs/en/index.html +++ b/tests/test_tools/simpletest/docs/en/index.html @@ -24,9 +24,6 @@ Group tests
  • -Server stubs -
  • -
  • Mock objects
  • @@ -101,26 +98,22 @@ We start by creating a test script which we will call tests/log_test.php and populate it as follows...
    -<?php
    -require_once('simpletest/unit_tester.php');
    -require_once('simpletest/reporter.php');
    -require_once('../classes/log.php');
    -?>
    -
    - Here the simpletest folder is either local or in the path. - You would have to edit these locations depending on where you - placed the toolset. - Next we create a test case... -
    -<?php
    +<?php
     require_once('simpletest/unit_tester.php');
     require_once('simpletest/reporter.php');
     require_once('../classes/log.php');
    -
    +
     class TestOfLogging extends UnitTestCase {
     }
     ?>
     
    + Here the simpletest folder is either local or in the path. + You would have to edit these locations depending on where you + placed the toolset. + The TestOfLogging is our frst test case and it's + currently empty. +

    +

    Now we have five lines of scaffolding code and still no tests. However from this part on we get return on our investment very quickly. We'll assume that the Log class @@ -376,21 +369,15 @@ Mock::generate('Log'); class TestOfSessionLogging extends UnitTestCase { function testLogInIsLogged() { - $log = &new MockLog($this); + $log = &new MockLog(); $log->expectOnce('message', array('User fred logged in.')); $session_pool = &new SessionPool($log); - $session_pool->logIn('fred'); - $log->tally(); + $session_pool->logIn('fred'); } } ?> - The tally() call is needed to - tell the mock object that time is up for the expected call - count. - Without it the mock would wait forever for the method - call to come in without ever actually notifying the test case. - The other test will be triggered when the call to + The test will be triggered when the call to message() is invoked on the MockLog object. The mock call will trigger a parameter comparison and then send the @@ -398,6 +385,13 @@ class TestOfSessionLogging extends UnitTestCase { Wildcards can be included here too so as to prevent tests becoming too specific.

    +

    + If the mock reaches the end of the test case without the + method being called, the expectOnce() + expectation will trigger a test failure. + In other words the mocks can detect the absence of + behaviour as well as the presence. +

    The mock objects in the SimpleTest suite can have arbitrary return values set, sequences of returns, return values @@ -439,12 +433,12 @@ class TestOfAbout extends WebTestCase { function setUp() { $this->get('http://test-server/index.php'); - $this->clickLink('About'); + $this->click('About'); } function testSearchEngineOptimisations() { $this->assertTitle('A long title about us for search engines'); - $this->assertWantedPattern('/a popular keyphrase/i'); + $this->assertPattern('/a popular keyphrase/i'); } } $test = &new TestOfAbout(); -- cgit v1.2.3