Pheasant\Database\Mysqli\Transaction::callback PHP Method

callback() public method

Adds a callback that gets passed any extra varargs as a arguments
public callback ( $callback )
    public function callback($callback)
    {
        $t = $this;
        $args = array_slice(func_get_args(), 1);
        // use an event handler to dispatch to the callback
        $this->_events->register('startTransaction', function ($event, $connection) use($t, $callback, $args) {
            $t->results[] = call_user_func_array($callback, $args);
        });
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testDeferEventsFireOnRollback()
 {
     $connection = \Mockery::mock('\\Pheasant\\Database\\Mysqli\\Connection');
     $connection->shouldReceive('execute')->with('BEGIN')->once();
     $connection->shouldReceive('execute')->with('ROLLBACK')->once();
     $events = \Mockery::mock();
     $events->shouldReceive('cork')->once()->andReturn($events);
     $events->shouldReceive('discard')->once()->andReturn($events);
     $events->shouldReceive('uncork')->once()->andReturn($events);
     $transaction = new Transaction($connection);
     $transaction->deferEvents($events);
     $transaction->callback(function () {
         throw new \Exception("Llamas :( :)");
     });
     $this->setExpectedException('\\Exception');
     $transaction->execute();
 }