Pheasant\Database\FilterChain::onError PHP Method

onError() public method

Attach an error handler, gets called with the exception, return ignored
public onError ( $callback )
    public function onError($callback)
    {
        $this->_onerror[] = $callback;
        return $this;
    }

Usage Example

Esempio n. 1
0
 public function testCatchingErrors()
 {
     $connection = \Mockery::mock('\\Pheasant\\Database\\Mysqli\\Connection');
     $filter = new FilterChain();
     $exceptions = array();
     $filter->onError(function ($e) use(&$exceptions) {
         $exceptions[] = $e;
     });
     $connection->shouldReceive('execute')->andThrow(new \Exception('Eeeeek!'));
     try {
         $filter->execute('SELECT 1', function ($sql) use($connection) {
             $connection->execute($sql);
         });
         $this->fail('Exception expected');
     } catch (\Exception $e) {
         $this->assertEquals($e->getMessage(), 'Eeeeek!');
     }
     $this->assertEquals(count($exceptions), 1);
     $this->assertEquals($exceptions[0]->getMessage(), 'Eeeeek!');
 }