Example #1
0
 /**
  * Implements check fixture
  *
  * Check aMethod aValue - Invoke aMethod with no arguments.
  * Compare the returned value with aValue. This is similar to reading
  * values from a GUI screen.
  *
  */
 public function check()
 {
     $aMethod = $this->camel($this->cells->more->text());
     $aValue = $this->cells->more->more;
     $adapter = PHPFIT_TypeAdapter::on(self::$actor, $aMethod, self::$actor, 'method');
     $this->checkCell($aValue, $adapter);
 }
 public function testTypeAdapter()
 {
     $f = new TestFixture();
     $a = PHPFIT_TypeAdapter::on($f, "sampleInt", $f, 'field');
     $a->set($a->parse("123456"));
     $this->assertTrue(is_int($a->parse("123456")));
     $this->assertEqual(123456, $f->sampleInt);
     $this->assertEqual("-234567", strval($a->parse("-234567")));
     $a = PHPFIT_TypeAdapter::on($f, "sampleFloat", $f, 'field');
     $a->set($a->parse("2.34"));
     $this->assertTrue(is_float($a->parse("2.34")));
     $this->assertTrue(abs(2.34 - $f->sampleFloat) < 1.0E-5);
     $a = PHPFIT_TypeAdapter::on($f, "pi", $f, 'method');
     $this->assertTrue(is_float($a->invoke()));
     $this->assertTrue(abs(3.14159 - $a->invoke()) < 1.0E-5);
     $a = PHPFIT_TypeAdapter::on($f, "name", $f, 'field');
     $a->set($a->parse("xyzzy"));
     $this->assertTrue(is_string($a->parse("xyzzy")));
     $this->assertEqual("xyzzy", $f->name);
     $a = PHPFIT_TypeAdapter::on($f, "sampleBoolean", $f, 'field');
     $a->set($a->parse("true"));
     $this->assertTrue(is_bool($a->parse("true")));
     $this->assertEqual(true, $f->name);
     // TODO: Arrays and Dates
 }
Example #3
0
 function execute()
 {
     $adapter = PHPFIT_TypeAdapter::on($this, 'validateAndSave', $this->getSystemUnderTest(), 'method');
     return $adapter->validateAndSave($this->columnBindings);
 }
Example #4
0
 /** Call a method with parameters
  * @param DoCells $doCells holding action name and params
  * @param PHPFIT_TypeAdapter $adapter 
  * 		If no adapter is supplied, this method will create one on the  systemUnderTest. 
  * 		This allows tests call a non-existent method. Risk is that a fatal error may occur. 
  * @return mixed the result of the method call
  */
 function call($doCells, $adapter = null)
 {
     if (!$adapter) {
         $adapter = \PHPFIT_TypeAdapter::on($this, $doCells->getName(), $this->getSystemUnderTest(), 'method');
     }
     $doCells->setAdapter($adapter);
     //result-adapter
     $arguments = $this->parseArgumentsForMethod($adapter->target, $doCells->getName(), $doCells->getParams(), $adapter);
     return call_user_func_array(array($adapter->target, $doCells->getName()), $arguments);
 }
Example #5
0
 /**
  * check whether the value of a cell matches
  *
  * @param PHPFIT_Parse $cell,
  * @param PHPFIT_TypeAdapter $adapter
  */
 public function checkCell($cell, $adapter)
 {
     $text = $cell->text();
     if ($text == '') {
         try {
             $this->info($cell, $adapter->toString());
         } catch (Exception $e) {
             $this->info($cell, 'error');
         }
     } else {
         if ($adapter == null) {
             $this->ignore($cell);
         } else {
             if (strncmp($text, 'error', 5) == 0) {
                 try {
                     $result = $adapter->invoke();
                     $this->wrong($cell, $adapter->valueToString($result));
                 } catch (Exception $e) {
                     $this->right($cell);
                 }
             } else {
                 try {
                     $value = $adapter->get();
                     if ($adapter->valueEquals($value, $text)) {
                         $this->right($cell);
                     } else {
                         $this->wrong($cell, $adapter->valueToString($value));
                     }
                 } catch (Exception $e) {
                     $this->exception($cell, $e);
                 }
             }
         }
     }
 }
Example #6
0
 /** @return PHPFIT_TypeAdapter for the supplied type
  * @param string type
  * @throws Exception */
 function getAdapterForType($type)
 {
     $adapter = PHPFIT_TypeAdapter::adapterFor($type);
     $adapter->init($this->fixture, $type);
     $adapter->target = $this->target;
     $property = $this->getProperty();
     $adapter->{$property} = $this->getName();
     return $adapter;
 }
Example #7
0
 /**
  * @param String $name
  * @return PHPFIT_TypeAdapter
  */
 protected function bindField($name)
 {
     return PHPFIT_TypeAdapter::on($this, $name, $this->getTargetClass(), 'field');
 }