1<?php 2 3namespace Sabre\Event; 4 5class ContinueCallbackTest extends \PHPUnit_Framework_TestCase { 6 7 function testContinueCallBack() { 8 9 $ee = new EventEmitter(); 10 11 $handlerCounter = 0; 12 $bla = function() use (&$handlerCounter) { 13 $handlerCounter++; 14 }; 15 $ee->on('foo', $bla); 16 $ee->on('foo', $bla); 17 $ee->on('foo', $bla); 18 19 $continueCounter = 0; 20 $r = $ee->emit('foo', [], function() use (&$continueCounter) { 21 $continueCounter++; 22 return true; 23 }); 24 $this->assertTrue($r); 25 $this->assertEquals(3, $handlerCounter); 26 $this->assertEquals(2, $continueCounter); 27 28 } 29 30 function testContinueCallBackBreak() { 31 32 $ee = new EventEmitter(); 33 34 $handlerCounter = 0; 35 $bla = function() use (&$handlerCounter) { 36 $handlerCounter++; 37 }; 38 $ee->on('foo', $bla); 39 $ee->on('foo', $bla); 40 $ee->on('foo', $bla); 41 42 $continueCounter = 0; 43 $r = $ee->emit('foo', [], function() use (&$continueCounter) { 44 $continueCounter++; 45 return false; 46 }); 47 $this->assertTrue($r); 48 $this->assertEquals(1, $handlerCounter); 49 $this->assertEquals(1, $continueCounter); 50 51 } 52 53 function testContinueCallBackBreakByHandler() { 54 55 $ee = new EventEmitter(); 56 57 $handlerCounter = 0; 58 $bla = function() use (&$handlerCounter) { 59 $handlerCounter++; 60 return false; 61 }; 62 $ee->on('foo', $bla); 63 $ee->on('foo', $bla); 64 $ee->on('foo', $bla); 65 66 $continueCounter = 0; 67 $r = $ee->emit('foo', [], function() use (&$continueCounter) { 68 $continueCounter++; 69 return false; 70 }); 71 $this->assertFalse($r); 72 $this->assertEquals(1, $handlerCounter); 73 $this->assertEquals(0, $continueCounter); 74 75 } 76} 77