Exemplo n.º 1
0
 public function testEvents()
 {
     $that = $this;
     $that->sequence = [];
     $model = new TestSchema();
     $model->on('beforeInsert', function ($event) use($that, $model) {
         $that->assertInstanceOf('\\Reach\\Event', $event);
         $that->assertEquals($model->_id, $event->model->_id);
         $that->sequence[] = 0;
     });
     $model->on('afterInsert', function ($event) use($that, $model) {
         $that->assertInstanceOf('\\Reach\\Event', $event);
         $that->assertEquals($model->_id, $event->model->_id);
         $that->sequence[] = 1;
     });
     $model->on('beforeUpdate', function ($event) use($that, $model) {
         $that->assertInstanceOf('\\Reach\\Event', $event);
         $that->assertEquals($model->_id, $event->model->_id);
         $that->sequence[] = 2;
     });
     $model->on('afterUpdate', function ($event) use($that, $model) {
         $that->assertInstanceOf('\\Reach\\Event', $event);
         $that->assertEquals($model->_id, $event->model->_id);
         $that->sequence[] = 3;
     });
     $model->on('beforeDelete', function ($event) use($that, $model) {
         $that->assertInstanceOf('\\Reach\\Event', $event);
         $that->assertEquals($model->_id, $event->model->_id);
         $that->sequence[] = 4;
     });
     $model->on('afterDelete', function ($event) use($that, $model) {
         $that->assertInstanceOf('\\Reach\\Event', $event);
         $that->assertEquals($model->_id, $event->model->_id);
         $that->sequence[] = 5;
         $that->assertEquals([0, 1, 2, 3, 2, 4, 5], $that->sequence);
     });
     $model->save();
     $model->title = '123';
     $model->save();
     $model->save();
     $model->delete();
 }