1<?php
2abstract class gtTestSubject {
3
4  protected $optionalArgumentNames;
5  protected $mandatoryArgumentNames;
6
7  protected $extraArgumentList = '';
8  protected $shortArgumentList = '';
9
10  protected $allowedArgumentLists;
11
12  protected $maximumArgumentList;
13
14  protected $initialisationStatements;
15
16
17  /** Return the list of all mandatory argument names
18   *
19   * @return array
20   */
21  public function getMandatoryArgumentNames() {
22    return $this->mandatoryArgumentNames;
23  }
24
25
26  /**
27   * Return the list of all optional argument names
28   *
29   * @return array
30   */
31  public function getOptionalArgumentNames() {
32    return $this->optionalArgumentNames;
33  }
34
35  public function setArgumentLists() {
36    $this->setValidArgumentLists();
37    $this->setExtraArgumentList();
38    $this->setShortArgumentList();
39  }
40
41  /**
42   * Set the argument list to call the subject with. Adds one extra argument.
43   *
44   */
45  public function setExtraArgumentList() {
46    if(count ($this->mandatoryArgumentNames) > 0) {
47      for( $i = 0; $i < count( $this->mandatoryArgumentNames ); $i++) {
48        $this->extraArgumentList .= "\$".$this->mandatoryArgumentNames[$i].", ";
49      }
50    }
51
52    if(count ($this->optionalArgumentNames) > 0) {
53      for( $i = 0; $i < count( $this->optionalArgumentNames ); $i++) {
54        $this->extraArgumentList .=  "\$".$this->optionalArgumentNames[$i].", ";
55      }
56    }
57
58    $this->extraArgumentList= $this->extraArgumentList. "\$extra_arg";
59  }
60
61
62  /**
63   * Return the list of arguments as it appears in the function call
64   *
65   * @return string - list of arguments
66   */
67  public function getExtraArgumentList() {
68    return $this->extraArgumentList;
69  }
70
71
72  /**
73   * Set the list of function arguments to be one less that the number of mandatory arguments
74   *
75   */
76  public function setShortArgumentList() {
77
78    if(count ($this->mandatoryArgumentNames) > 0) {
79      for( $i = 0; $i < count( $this->mandatoryArgumentNames ) - 1; $i++) {
80        $this->shortArgumentList .= "\$".$this->mandatoryArgumentNames[$i].", ";
81      }
82      $this->shortArgumentList = substr($this->shortArgumentList, 0, -2);
83    }
84  }
85
86
87  /**
88   * Return the short list of arguments
89   *
90   * @return string - list of arguments
91   */
92  public function getShortArgumentList() {
93    return $this->shortArgumentList;
94  }
95
96
97  /**
98   * Construct the list of all possible ways to call the subject (function or method)
99   *
100   */
101  public function setValidArgumentLists() {
102    $this->allowedArgumentLists[0] = '';
103    if(count ($this->mandatoryArgumentNames) > 0) {
104      for( $i = 0; $i < count( $this->mandatoryArgumentNames ); $i++) {
105        $this->allowedArgumentLists[0] .= "\$".$this->mandatoryArgumentNames[$i].", ";
106      }
107    }
108
109    if(count ($this->optionalArgumentNames) > 0) {
110      for( $i = 0; $i < count( $this->optionalArgumentNames ); $i++) {
111        $this->allowedArgumentLists[] = $this->allowedArgumentLists[$i]."\$".$this->optionalArgumentNames[$i].", ";
112        $this->allowedArgumentLists[$i] = substr ($this->allowedArgumentLists[$i], 0, -2);
113      }
114    }
115
116    $this->allowedArgumentLists[count($this->allowedArgumentLists) -1 ] = substr($this->allowedArgumentLists[count($this->allowedArgumentLists) -1 ], 0, -2);
117  }
118
119
120  /**
121   * Return the array of all possible sets of method/function arguments
122   *
123   * @return unknown
124   */
125  public function getValidArgumentLists() {
126    return $this->allowedArgumentLists;
127  }
128
129
130  /**
131   * Returns the argument list with the greatest possible number of arguments.
132   *
133   * @return string
134   */
135  public function getMaximumArgumentList() {
136    return end($this->allowedArgumentLists);
137  }
138
139
140  /**
141   * Write initialisation statemenst for all the variables that might be used
142   *
143   */
144  public function setInitialisationStatements() {
145    if(count ($this->mandatoryArgumentNames) > 0) {
146      foreach( $this->mandatoryArgumentNames as $name) {
147        $this->initialisationStatements[] = "\$".$name." = ";
148      }
149    }
150    if(count ($this->optionalArgumentNames) > 0) {
151      foreach( $this->optionalArgumentNames as $name) {
152        $this->initialisationStatements[] = "\$".$name." = ";
153      }
154    }
155  }
156
157  /**
158   * Return the initialisation statements
159   *
160   * @return unknown
161   */
162  public function getInitialisationStatements() {
163    return $this->initialisationStatements;
164  }
165}
166?>
167