コード例 #1
0
 public function testShouldDispatchEventFromOtherSubscription()
 {
     $logger = new Logger();
     $this->app->subscribe('payment.failure', 'logger', function (Application $app) use($logger) {
         $logger->log('Payment failure');
         $app->dispatch('payment.attempt');
     });
     $counter = new Counter();
     $this->app->subscribe('payment.attempt', 'paymentCounter', function () use($counter) {
         $counter->increment();
     });
     $this->app->dispatch('payment.failure');
     $this->assertEquals(1, $counter->total());
 }
コード例 #2
0
ファイル: DispatcherTest.php プロジェクト: php-lab/event
 public function testShouldNotifyListenersByPriorities()
 {
     $logger = new Logger();
     $this->app->subscribe('payment.failure', 'logger', function () use($logger) {
         $logger->log('Payment failure');
         return ['stop' => true];
     }, 10);
     $counter = new Counter();
     $this->app->subscribe('payment.failure', 'errorCounter', function () use($counter) {
         $counter->increment();
     }, 20);
     $this->app->dispatch('payment.failure');
     $this->assertEquals(1, $counter->total());
 }