902a6c207875a1037d2bce6bf898b6dc18145a70
[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 testIntCallToExternal()
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 testExtCallToIntGroup()
65     {
66         $this->loadDump('handy-zu-gruppe.bin');
67         $this->assertCallCount(1, 1);
68
69         $this->assertIncoming($this->calls['startingCall'][0]);
70         $this->assertFrom('01634779878', $this->calls['startingCall'][0]);
71         $this->assertTo('40862', $this->calls['startingCall'][0]);
72
73         $this->assertIncoming($this->calls['finishedCall'][0]);
74         $this->assertFrom('01634779878', $this->calls['finishedCall'][0]);
75         $this->assertTo('40862', $this->calls['finishedCall'][0]);
76     }
77
78     protected function assertCallCount($starting, $finished)
79     {
80         $this->assertCount(
81             $starting, $this->calls['startingCall'],
82             'Number of starting calls does not match'
83         );
84         $this->assertCount(
85             $finished, $this->calls['finishedCall'],
86             'Number of finished calls does not match'
87         );
88     }
89
90     protected function assertFrom($number, CallMonitor_Call $call)
91     {
92         $this->assertSame(
93             $number, $call->from,
94             'Call "from" number does not match'
95         );
96     }
97
98     protected function assertTo($number, CallMonitor_Call $call)
99     {
100         $this->assertSame(
101             $number, $call->to,
102             'Call "to" number does not match'
103         );
104     }
105
106     protected function assertIncoming(CallMonitor_Call $call)
107     {
108         $this->assertSame(
109             CallMonitor_Call::INCOMING, $call->type,
110             'Call should be "incoming"'
111         );
112     }
113
114     protected function assertOutgoing(CallMonitor_Call $call)
115     {
116         $this->assertSame(
117             CallMonitor_Call::OUTGOING, $call->type,
118             'Call should be "outgoing"'
119         );
120     }
121
122 }
123
124 ?>