events() public method

Returns the domain objects event collection, optionally registering any passed events
public events ( $events = [] ) : Events
return Events
Beispiel #1
0
 public function testEventsBoundToObject()
 {
     $this->mapper->shouldReceive('save')->times(2);
     $events = array();
     $this->initialize('Pheasant\\DomainObject', function ($builder) {
         $builder->properties(array('test' => new Types\StringType()));
     });
     $do1 = new DomainObject();
     $do2 = new DomainObject();
     $do1->events(array('afterSave' => function ($e) use(&$events) {
         $events[] = "do1.{$e}";
     }));
     $do2->events(array('afterSave' => function ($e) use(&$events) {
         $events[] = "do2.{$e}";
     }));
     $do1->save();
     $do2->save();
     $this->assertEquals($events, array('do1.afterSave', 'do2.afterSave'));
 }