summaryrefslogtreecommitdiff
path: root/modules/simpletest/invoker.php
blob: 7944c1b4f98302c0cbaf52ecf40bb409e8fcd6bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
// $Id$

/**
 *    This is called by the class runner to run a
 *    single test method. Will also run the setUp()
 *    and tearDown() methods.
 *    @package SimpleTest
 *    @subpackage UnitTester
 */
class SimpleInvoker {
  var $_test_case;

  /**
   *    Stashes the test case for later.
   *    @param SimpleTestCase $test_case  Test case to run.
   */
  function SimpleInvoker(&$test_case) {
    $this->_test_case = &$test_case;
  }

  /**
   *    Accessor for test case being run.
   *    @return SimpleTestCase    Test case.
   *    @access public
   */
  function &getTestCase() {
    return $this->_test_case;
  }

  /**
   *    Runs test level set up. Used for changing
   *    the mechanics of base test cases.
   *    @param string $method    Test method to call.
   *    @access public
   */
  function before($method) {
    $this->_test_case->before($method);
  }

  /**
   *    Invokes a test method and buffered with setUp()
   *    and tearDown() calls.
   *    @param string $method    Test method to call.
   *    @access public
   */
  function invoke($method) {
    $this->_test_case->setUp();
    $this->_test_case->$method();
    $this->_test_case->tearDown();
  }

  /**
   *    Runs test level clean up. Used for changing
   *    the mechanics of base test cases.
   *    @param string $method    Test method to call.
   *    @access public
   */
  function after($method) {
    $this->_test_case->after($method);
  }
}

/**
 *    Do nothing decorator. Just passes the invocation
 *    straight through.
 *    @package SimpleTest
 *    @subpackage UnitTester
 */
class SimpleInvokerDecorator {
  var $_invoker;

  /**
   *    Stores the invoker to wrap.
   *    @param SimpleInvoker $invoker  Test method runner.
   */
  function SimpleInvokerDecorator(&$invoker) {
    $this->_invoker = &$invoker;
  }

  /**
   *    Accessor for test case being run.
   *    @return SimpleTestCase    Test case.
   *    @access public
   */
  function &getTestCase() {
    return $this->_invoker->getTestCase();
  }

  /**
   *    Runs test level set up. Used for changing
   *    the mechanics of base test cases.
   *    @param string $method    Test method to call.
   *    @access public
   */
  function before($method) {
    $this->_invoker->before($method);
  }

  /**
   *    Invokes a test method and buffered with setUp()
   *    and tearDown() calls.
   *    @param string $method    Test method to call.
   *    @access public
   */
  function invoke($method) {
    $this->_invoker->invoke($method);
  }

  /**
   *    Runs test level clean up. Used for changing
   *    the mechanics of base test cases.
   *    @param string $method    Test method to call.
   *    @access public
   */
  function after($method) {
    $this->_invoker->after($method);
  }
}