summaryrefslogtreecommitdiff
path: root/scripts/dev/generate-phpt/src/gtTestSubject.php
blob: 76454dc7b85bb8d9f4133c822a4d59cd418355f9 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
abstract class gtTestSubject {

  protected $optionalArgumentNames = [];
  protected $mandatoryArgumentNames = [];

  protected $extraArgumentList = '';
  protected $shortArgumentList = '';

  protected $allowedArgumentLists;

  protected $maximumArgumentList;
  
  protected $initialisationStatements;


  /** Return the list of all mandatory argument names
   *
   * @return array
   */
  public function getMandatoryArgumentNames() {
    return $this->mandatoryArgumentNames;
  }


  /**
   * Return the list of all optional argument names
   *
   * @return array
   */
  public function getOptionalArgumentNames() {
    return $this->optionalArgumentNames;
  }
  
  public function setArgumentLists() {
    $this->setValidArgumentLists();
    $this->setExtraArgumentList();
    $this->setShortArgumentList();
  }

  /**
   * Set the argument list to call the subject with. Adds one extra argument.
   *
   */
  public function setExtraArgumentList() {
    if(count ($this->mandatoryArgumentNames) > 0) {
      for( $i = 0; $i < count( $this->mandatoryArgumentNames ); $i++) {
        $this->extraArgumentList .= "\$".$this->mandatoryArgumentNames[$i].", ";
      }
    }
     
    if(count ($this->optionalArgumentNames) > 0) {
      for( $i = 0; $i < count( $this->optionalArgumentNames ); $i++) {
        $this->extraArgumentList .=  "\$".$this->optionalArgumentNames[$i].", ";
      }
    }

    $this->extraArgumentList= $this->extraArgumentList. "\$extra_arg";
  }
   

  /**
   * Return the list of arguments as it appears in the function call
   *
   * @return string - list of arguments
   */
  public function getExtraArgumentList() {
    return $this->extraArgumentList;
  }


  /**
   * Set the list of function arguments to be one less that the number of mandatory arguments
   *
   */
  public function setShortArgumentList() {

    if(count ($this->mandatoryArgumentNames) > 0) {
      for( $i = 0; $i < count( $this->mandatoryArgumentNames ) - 1; $i++) {
        $this->shortArgumentList .= "\$".$this->mandatoryArgumentNames[$i].", ";
      }
      $this->shortArgumentList = substr($this->shortArgumentList, 0, -2);
    }
  }


  /**
   * Return the short list of arguments
   *
   * @return string - list of arguments
   */
  public function getShortArgumentList() {
    return $this->shortArgumentList;
  }


  /**
   * Construct the list of all possible ways to call the subject (function or method)
   *
   */
  public function setValidArgumentLists() {
    $this->allowedArgumentLists[0] = '';
    if(count ($this->mandatoryArgumentNames) > 0) {
      for( $i = 0; $i < count( $this->mandatoryArgumentNames ); $i++) {
        $this->allowedArgumentLists[0] .= "\$".$this->mandatoryArgumentNames[$i].", ";
      }
    }
     
    if(count ($this->optionalArgumentNames) > 0) {
      for( $i = 0; $i < count( $this->optionalArgumentNames ); $i++) {
        $this->allowedArgumentLists[] = $this->allowedArgumentLists[$i]."\$".$this->optionalArgumentNames[$i].", ";
        $this->allowedArgumentLists[$i] = substr ($this->allowedArgumentLists[$i], 0, -2);
      }
    }

    $this->allowedArgumentLists[count($this->allowedArgumentLists) -1 ] = substr($this->allowedArgumentLists[count($this->allowedArgumentLists) -1 ], 0, -2);
  }


  /**
   * Return the array of all possible sets of method/function arguments
   *
   * @return unknown
   */
  public function getValidArgumentLists() {
    return $this->allowedArgumentLists;
  }


  /**
   * Returns the argument list with the greatest possible number of arguments.
   *
   * @return string
   */
  public function getMaximumArgumentList() {
    return end($this->allowedArgumentLists);
  }


  /**
   * Write initialisation statemenst for all the variables that might be used
   *
   */
  public function setInitialisationStatements() {
    if(count ($this->mandatoryArgumentNames) > 0) {
      foreach( $this->mandatoryArgumentNames as $name) {
        $this->initialisationStatements[] = "\$".$name." = ";
      }
    }
    if(count ($this->optionalArgumentNames) > 0) {
      foreach( $this->optionalArgumentNames as $name) {
        $this->initialisationStatements[] = "\$".$name." = ";
      }
    }
  }
  
  /**
   * Return the initialisation statements
   *
   * @return unknown
   */
  public function getInitialisationStatements() {
    return $this->initialisationStatements;
  }
}
?>