I'm looking for something like break for loops.
Here's some example code (using Symfony's lime) where stop() would not let the class continue and I_DONT_WANT_THIS_TO_RUN() would not be executed.
$browser->isStatusCode(200)
  ->isRequestParameter('module', 'home')
  ->isRequestParameter('action', 'index')
  ->click('Register')
  ->stop()
  ->I_DONT_WANT_THIS_TO_RUN();
$browser->thenThisRunsOkay();
Calling $this->__deconstruct(); from within stop() doesn't seem to do the trick. Is there a function I can call within stop() that would make that happen?
You could use PHP exceptions:
// This function would of course be declared in the class
function stop() {
    throw new Exception('Stopped.');
}
try {
    $browser->isStatusCode(200)
      ->isRequestParameter('module', 'home')
      ->isRequestParameter('action', 'index')
      ->click('Register')
      ->stop()
      ->I_DONT_WANT_THIS_TO_RUN();
} catch (Exception $e) {
    // when stop() throws the exception, control will go on from here.
}
$browser->thenThisRunsOkay();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With