Development

Changeset 2980

You must first sign up to be able to contribute.

Changeset 2980

Show
Ignore:
Timestamp:
12/08/06 21:02:11 (2 years ago)
Author:
fabien
Message:

added a new throwsException() method to the test browser

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/controller/sfFrontWebController.class.php

    r2971 r2980  
    5050    catch (sfException $e) 
    5151    { 
     52      if (sfConfig::get('sf_test')) 
     53      { 
     54        throw $e; 
     55      } 
     56 
    5257      $e->printStackTrace(); 
    5358    } 
    5459    catch (Exception $e) 
    5560    { 
     61      if (sfConfig::get('sf_test')) 
     62      { 
     63        throw $e; 
     64      } 
     65 
    5666      // wrap non symfony exceptions 
    5767      $sfException = new sfException(); 
  • trunk/lib/test/sfTestBrowser.class.php

    r2794 r2980  
    179179  } 
    180180 
     181  public function throwsException($class = null, $message = null) 
     182  { 
     183    $e = $this->getCurrentException(); 
     184 
     185    if (null === $e) 
     186    { 
     187      $this->test->fail('response returns an exception'); 
     188    } 
     189    else 
     190    { 
     191      if (null !== $class) 
     192      { 
     193        $this->test->ok($e instanceof $class, sprintf('response returns an exception of class "%s"', $class)); 
     194      } 
     195 
     196      if (null !== $message && preg_match('/^(!)?([^a-zA-Z0-9\\\\]).+?\\2[ims]?$/', $message, $match)) 
     197      { 
     198        if ($match[1] == '!') 
     199        { 
     200          $this->test->unlike($e->getMessage(), substr($message, 1), sprintf('response exception message does not match regex "%s"', $message)); 
     201        } 
     202        else 
     203        { 
     204          $this->test->like($e->getMessage(), $message, sprintf('response exception message matches regex "%s"', $message)); 
     205        } 
     206      } 
     207      else if (null !== $message) 
     208      { 
     209        $this->test->is($e->getMessage(), $message, sprintf('response exception message matches regex "%s"', $message)); 
     210      } 
     211    } 
     212 
     213    return $this; 
     214  } 
     215 
    181216  public function isCached($boolean, $with_layout = false) 
    182217  { 
  • trunk/lib/util/sfBrowser.class.php

    r2971 r2980  
    2020{ 
    2121  protected 
    22     $context       = null, 
    23     $hostname      = null, 
    24     $remote        = null, 
    25     $dom           = null, 
    26     $stack         = array(), 
    27     $stackPosition = -1, 
    28     $cookieJar     = array(), 
    29     $fields        = array(); 
     22    $context          = null, 
     23    $hostname         = null, 
     24    $remote           = null, 
     25    $dom              = null, 
     26    $stack            = array(), 
     27    $stackPosition    = -1, 
     28    $cookieJar        = array(), 
     29    $fields           = array(), 
     30    $currentException = null; 
    3031 
    3132  public function initialize($hostname = null, $remote = null, $options = array()) 
     
    129130    sfConfig::set('sf_rendering_filter', array('sfFakeRenderingFilter', null)); 
    130131 
     132    $this->currentException = null; 
     133 
    131134    // dispatch our request 
    132135    ob_start(); 
    133     $controller->dispatch(); 
     136    try 
     137    { 
     138      $controller->dispatch(); 
     139    } 
     140    catch (sfException $e) 
     141    { 
     142      $this->currentException = $e; 
     143 
     144      $e->printStackTrace(); 
     145    } 
     146    catch (Exception $e) 
     147    { 
     148      $this->currentException = $e; 
     149 
     150      $sfException = new sfException(); 
     151      $sfException->printStackTrace($e); 
     152    } 
    134153    $retval = ob_get_clean(); 
     154 
     155    if ($this->currentException instanceof sfStopException) 
     156    { 
     157      $this->currentException = null; 
     158    } 
    135159 
    136160    // append retval to the response content 
     
    216240  { 
    217241    return $this->context->getRequest(); 
     242  } 
     243 
     244  public function getCurrentException() 
     245  { 
     246    return $this->currentException; 
    218247  } 
    219248 
  • trunk/test/functional/backend/browseTest.php

    r2935 r2980  
    2525  isRequestParameter('module', 'error')-> 
    2626  isRequestParameter('action', 'index')-> 
    27   responseContains('sfInitializationException')-> 
    28   responseContains('Unable to scaffold unexistant model') 
     27  throwsException('sfInitializationException', '/Unable to scaffold unexistant model/') 
    2928; 
    3029 
  • trunk/test/functional/crudTest.php

    r2935 r2980  
    2424  isRequestParameter('module', 'error')-> 
    2525  isRequestParameter('action', 'index')-> 
    26   responseContains('sfInitializationException')-> 
    27   responseContains('Unable to scaffold unexistant model') 
     26  throwsException('sfInitializationException', '/Unable to scaffold unexistant model/') 
    2827; 
    2928