309a5e6d7a6564c64522c6af40bcd20addfb284e
[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->assertFrom('22', $this->calls['startingCall'][0]);
42         $this->assertTo('**41', $this->calls['startingCall'][0]);
43
44         $this->assertFrom('22', $this->calls['finishedCall'][0]);
45         $this->assertTo('**41', $this->calls['finishedCall'][0]);
46     }
47
48     public function testIntCallToExternal()
49     {
50         $this->loadDump('intern-analog-zu-handy.bin');
51         $this->assertCallCount(1, 1);
52
53         $this->assertFrom('40862', $this->calls['startingCall'][0]);
54         $this->assertTo('01634779878', $this->calls['startingCall'][0]);
55
56         $this->assertFrom('40862', $this->calls['finishedCall'][0]);
57         $this->assertTo('01634779878', $this->calls['finishedCall'][0]);
58     }
59
60     public function testExtCallToIntGroup()
61     {
62         $this->loadDump('handy-zu-gruppe.bin');
63         $this->assertCallCount(1, 1);
64
65         $this->assertFrom('01634779878', $this->calls['startingCall'][0]);
66         $this->assertTo('40862', $this->calls['startingCall'][0]);
67
68         $this->assertFrom('01634779878', $this->calls['finishedCall'][0]);
69         $this->assertTo('40862', $this->calls['finishedCall'][0]);
70     }
71
72     protected function assertCallCount($starting, $finished)
73     {
74         $this->assertCount(
75             $starting, $this->calls['startingCall'],
76             'Number of starting calls does not match'
77         );
78         $this->assertCount(
79             $finished, $this->calls['finishedCall'],
80             'Number of finished calls does not match'
81         );
82     }
83
84     protected function assertFrom($number, CallMonitor_Call $call)
85     {
86         $this->assertSame(
87             $number, $call->from,
88             'Call "from" number does not match'
89         );
90     }
91
92     protected function assertTo($number, CallMonitor_Call $call)
93     {
94         $this->assertSame(
95             $number, $call->to,
96             'Call "to" number does not match'
97         );
98     }
99
100 }
101
102 ?>