test another scenario
[auerswald-callnotifier.git] / tests / callnotifier / CallMonitorTest.php
1 <?php
2 namespace callnotifier;
3
4 class CallMonitorTest extends \PHPUnit_Framework_TestCase implements Logger
5 {
6     protected $handler;
7     protected $calls;
8
9     public function setUp()
10     {
11         $this->calls = array();
12
13         $config = new Config();
14
15         $log = new Log();
16         $log->addLogger($this, array('startingCall', 'finishedCall'));
17
18         $cm = new CallMonitor($config, $log);
19         $this->handler = new MessageHandler($config, $log, $cm);
20     }
21
22     protected function loadDump($file)
23     {
24         $this->handler->config->replayFile = __DIR__ . '/../dumps/' . $file;
25         $source = new Source_File($this->handler->config, $this->handler);
26         $source->run();
27     }
28
29
30     public function log($type, $arData)
31     {
32         $this->calls[$type][] = $arData['call'];
33     }
34
35
36     public function testIntCallToInt()
37     {
38         $this->loadDump('intern-22-zu-41.bin');
39         $this->assertCallCount(1, 1);
40
41         $this->assertOutgoing($this->calls['startingCall'][0]);
42         $this->assertFrom('22', $this->calls['startingCall'][0]);
43         $this->assertTo('**41', $this->calls['startingCall'][0]);
44
45         $this->assertOutgoing($this->calls['finishedCall'][0]);
46         $this->assertFrom('22', $this->calls['finishedCall'][0]);
47         $this->assertTo('**41', $this->calls['finishedCall'][0]);
48     }
49
50     public function testAnalogIntCallToExternal()
51     {
52         $this->loadDump('intern-analog-zu-handy.bin');
53         $this->assertCallCount(1, 1);
54
55         $this->assertOutgoing($this->calls['startingCall'][0]);
56         $this->assertFrom('40862', $this->calls['startingCall'][0]);
57         $this->assertTo('01634779878', $this->calls['startingCall'][0]);
58
59         $this->assertOutgoing($this->calls['finishedCall'][0]);
60         $this->assertFrom('40862', $this->calls['finishedCall'][0]);
61         $this->assertTo('01634779878', $this->calls['finishedCall'][0]);
62     }
63
64     public function testIsdnIntCallToExternal()
65     {
66         $this->loadDump('intern-22-zu-handy.bin');
67         $this->assertCallCount(1, 1);
68
69         $this->assertOutgoing($this->calls['startingCall'][0]);
70         $this->assertFrom('40862', $this->calls['startingCall'][0]);
71         $this->assertTo('01634779878', $this->calls['startingCall'][0]);
72
73         $this->assertOutgoing($this->calls['finishedCall'][0]);
74         $this->assertFrom('40862', $this->calls['finishedCall'][0]);
75         $this->assertTo('01634779878', $this->calls['finishedCall'][0]);
76     }
77
78     public function testExtCallToIntGroup()
79     {
80         $this->loadDump('handy-zu-gruppe.bin');
81         $this->assertCallCount(1, 1);
82
83         $this->assertIncoming($this->calls['startingCall'][0]);
84         $this->assertFrom('01634779878', $this->calls['startingCall'][0]);
85         $this->assertTo('40862', $this->calls['startingCall'][0]);
86
87         $this->assertIncoming($this->calls['finishedCall'][0]);
88         $this->assertFrom('01634779878', $this->calls['finishedCall'][0]);
89         $this->assertTo('40862', $this->calls['finishedCall'][0]);
90     }
91
92     protected function assertCallCount($starting, $finished)
93     {
94         $this->assertCount(
95             $starting, $this->calls['startingCall'],
96             'Number of starting calls does not match'
97         );
98         $this->assertCount(
99             $finished, $this->calls['finishedCall'],
100             'Number of finished calls does not match'
101         );
102     }
103
104     protected function assertFrom($number, CallMonitor_Call $call)
105     {
106         $this->assertSame(
107             $number, $call->from,
108             'Call "from" number does not match'
109         );
110     }
111
112     protected function assertTo($number, CallMonitor_Call $call)
113     {
114         $this->assertSame(
115             $number, $call->to,
116             'Call "to" number does not match'
117         );
118     }
119
120     protected function assertIncoming(CallMonitor_Call $call)
121     {
122         $this->assertSame(
123             CallMonitor_Call::INCOMING, $call->type,
124             'Call should be "incoming"'
125         );
126     }
127
128     protected function assertOutgoing(CallMonitor_Call $call)
129     {
130         $this->assertSame(
131             CallMonitor_Call::OUTGOING, $call->type,
132             'Call should be "outgoing"'
133         );
134     }
135
136 }
137
138 ?>