2 namespace callnotifier;
4 class CallMonitorTest extends \PHPUnit_Framework_TestCase implements Logger
9 public function setUp()
11 $this->calls = array();
13 $config = new Config();
16 $log->addLogger($this, array('startingCall', 'finishedCall'));
18 $cm = new CallMonitor($config, $log);
19 $this->handler = new MessageHandler($config, $log, $cm);
22 protected function loadDump($file)
24 $this->handler->config->replayFile = __DIR__ . '/../dumps/' . $file;
25 $source = new Source_File($this->handler->config, $this->handler);
30 public function log($type, $arData)
32 $this->calls[$type][] = $arData['call'];
36 public function testIntCallToInt()
38 $this->loadDump('intern-22-zu-41.bin');
39 $this->assertCallCount(1, 1);
41 $this->assertOutgoing($this->calls['startingCall'][0]);
42 $this->assertFrom('22', $this->calls['startingCall'][0]);
43 $this->assertTo('**41', $this->calls['startingCall'][0]);
45 $this->assertOutgoing($this->calls['finishedCall'][0]);
46 $this->assertFrom('22', $this->calls['finishedCall'][0]);
47 $this->assertTo('**41', $this->calls['finishedCall'][0]);
50 public function testIntCallToExternal()
52 $this->loadDump('intern-analog-zu-handy.bin');
53 $this->assertCallCount(1, 1);
55 $this->assertOutgoing($this->calls['startingCall'][0]);
56 $this->assertFrom('40862', $this->calls['startingCall'][0]);
57 $this->assertTo('01634779878', $this->calls['startingCall'][0]);
59 $this->assertOutgoing($this->calls['finishedCall'][0]);
60 $this->assertFrom('40862', $this->calls['finishedCall'][0]);
61 $this->assertTo('01634779878', $this->calls['finishedCall'][0]);
64 public function testExtCallToIntGroup()
66 $this->loadDump('handy-zu-gruppe.bin');
67 $this->assertCallCount(1, 1);
69 $this->assertIncoming($this->calls['startingCall'][0]);
70 $this->assertFrom('01634779878', $this->calls['startingCall'][0]);
71 $this->assertTo('40862', $this->calls['startingCall'][0]);
73 $this->assertIncoming($this->calls['finishedCall'][0]);
74 $this->assertFrom('01634779878', $this->calls['finishedCall'][0]);
75 $this->assertTo('40862', $this->calls['finishedCall'][0]);
78 protected function assertCallCount($starting, $finished)
81 $starting, $this->calls['startingCall'],
82 'Number of starting calls does not match'
85 $finished, $this->calls['finishedCall'],
86 'Number of finished calls does not match'
90 protected function assertFrom($number, CallMonitor_Call $call)
94 'Call "from" number does not match'
98 protected function assertTo($number, CallMonitor_Call $call)
102 'Call "to" number does not match'
106 protected function assertIncoming(CallMonitor_Call $call)
109 CallMonitor_Call::INCOMING, $call->type,
110 'Call should be "incoming"'
114 protected function assertOutgoing(CallMonitor_Call $call)
117 CallMonitor_Call::OUTGOING, $call->type,
118 'Call should be "outgoing"'