Source for file ActionFixture.php

Documentation is available at ActionFixture.php

  1. <?php
  2. /**
  3. * FIT Fixture: ActionFixture
  4. *
  5. * $Id$
  6. *
  7. * @author Luis A. Floreani <luis.floreani@gmail.com>
  8. * @author gERD Schaufelberger <gerd@php-tools.net>
  9. * @package FIT
  10. * @subpackage Fixture
  11. * @license LGPL http://www.gnu.org/copyleft/lesser.html
  12. * @copyright Copyright (c) 2002-2005 Cunningham & Cunningham, Inc.
  13. */
  14.  
  15. /**
  16. * load class Fixture
  17. */
  18. include_once dirname( __FILE__ ) . '/Fixture.php';
  19.  
  20. /**
  21. * load class TypeAdapter
  22. */
  23. include_once dirname( __FILE__ ) . '/TypeAdapter.php';
  24.  
  25. /**
  26. * FIT Fixture: ActionFixture
  27. *
  28. * An action fixture interprets rows as a sequence of commands to be performed
  29. * in order. It interprets tables for which the first column contains one of a
  30. * small number of commands. Subsequent columns contain values interpreted by
  31. * the particular command. The generic action fixture offers only four commands,
  32. * but subclasses may extend this set.
  33. *
  34. * @version 0.1.0
  35. * @package FIT
  36. * @subpackage Fixture
  37. */
  38. class ActionFixture extends Fixture {
  39.  
  40. /**
  41. * dictionary of variable types
  42. * @var int
  43. * @see getType()
  44. */
  45. protected $typeDict = array();
  46. /**
  47. * @var Parse
  48. */
  49. protected $cells;
  50.  
  51. /**
  52. * actor that has been startet
  53. * @var Fixture
  54. * @see start()
  55. */
  56. private $actor = null;
  57. /**
  58. * Implements start fixture
  59. *
  60. * Start aClass - Subsequent commands are directed to an instance of
  61. * aClass. This is similar to navigating to a particular GUI screen.
  62. *
  63. * @return void
  64. */
  65. public function start() {
  66. $aClass = $this->cells->more->text();
  67. $this->actor = $this->loadFixture( $aClass );
  68. }
  69. /**
  70. * Implements enter fixture
  71. *
  72. * Enter aMethod anArgument - Invoke aMethod with anArgument (of type
  73. * determined by aMethod.) This is similar to entering values into GUI fields.
  74. *
  75. * @return void
  76. */
  77. public function enter() {
  78. $aMethod = $this->camel( $this->cells->more->text() );
  79. $anArgument = $this->cells->more->more->text();
  80. $this->actor->$aMethod( $anArgument );
  81. }
  82. /**
  83. * Implements press fixture
  84. *
  85. * Press aMethod - Invoke aMethod with no arguments. This is
  86. * similar to pressing a GUI button.
  87. *
  88. * @return void
  89. */
  90. public function press() {
  91. $aMethod = $this->camel( $this->cells->more->text() );
  92. $this->actor->$aMethod();
  93. }
  94.  
  95. /**
  96. * Implements check fixture
  97. *
  98. * Check aMethod aValue - Invoke aMethod with no arguments.
  99. * Compare the returned value with aValue. This is similar to reading
  100. * values from a GUI screen.
  101. *
  102. * @return void
  103. */
  104. public function check() {
  105. $aMethod = $this->camel( $this->cells->more->text() );
  106. $aValue = $this->cells->more->more;
  107. $adapter = TypeAdapter::onMethod( $this->actor, $aMethod );
  108. parent::check( $aValue, $adapter );
  109. }
  110. /**
  111. * process cells
  112. *
  113. * In case of ActionFixture each row has to be interpreted as a command
  114. * Processing cells means to execute one command.
  115. *
  116. * An action fixture interprets tables for which the first column contains
  117. * one of a small number of commands. Subsequent columns contain values
  118. * interpreted by the particular command. The generic action fixture offers
  119. * only four commands, but subclasses may extend this set.
  120. *
  121. * @param object $cells A parse object
  122. * @return void
  123. */
  124. public function doCells( $cells ) {
  125. try {
  126. $this->cells = $cells;
  127. $method = $cells->text();
  128. if( !method_exists( $this, $method ) ) {
  129. throw new Exception( 'Action fixture cannot call the request command. Method '
  130. . __CLASS__ . '->' . $method . ' does not exist' );
  131. }
  132. $this->$method();
  133. }
  134. catch( Exception $e ) {
  135. $this->exception( $cells, $e );
  136. }
  137. }
  138. }
  139. ?>

Documentation generated on Sun, 02 Apr 2006 16:01:02 +0200 by phpDocumentor 1.3.0RC5