gtTestSubject.php 4.3 KB

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