Skip to content

Commit 083a962

Browse files
committed
Merge branch 'message'
2 parents 4823a0d + 5b7695a commit 083a962

6 files changed

Lines changed: 18 additions & 24 deletions

File tree

src/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ public function isBusy()
129129

130130
public function createAction($name, array $args = array())
131131
{
132-
$args = array('ActionID' => (string)++$this->actionId) + $args;
132+
$args = array('Action' => $name, 'ActionID' => (string)++$this->actionId) + $args;
133133

134-
return new Action($name, $args);
134+
return new Action($args);
135135
}
136136
}

src/Protocol/Action.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44

55
class Action extends Message
66
{
7-
private $action;
8-
9-
public function __construct($action, array $parts = array())
7+
public function __construct(array $parts = array())
108
{
11-
$this->action = $action;
129
$this->parts = $parts;
1310
}
1411

1512
public function getMessageSerialized()
1613
{
17-
$message = 'Action: ' . $this->action . "\r\n";
14+
$message = '';
1815
foreach ($this->parts as $key => $values) {
1916
if (!is_array($values)) {
2017
$values = array($values);

src/Protocol/Event.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44

55
class Event extends Message
66
{
7-
private $name;
8-
9-
public function __construct($name, array $parts)
7+
public function __construct(array $parts)
108
{
11-
$this->name = $name;
129
$this->parts = $parts;
1310
}
1411

1512
public function getName()
1613
{
17-
return $this->name;
14+
return $this->getPart('Event');
1815
}
1916
}

src/Protocol/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ private function parseMessage($message)
5757
$parts[$key] = $value;
5858
}
5959

60-
$value = reset($parts);
60+
reset($parts);
6161
$key = key($parts);
6262

6363
if ($key === 'Event') {
64-
return new Event($value, $parts);
64+
return new Event($parts);
6565
}
6666

6767
return new Response($parts);

tests/CollectorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function testCollectingSIPEvents()
1717
$client->expects($this->once())
1818
->method('createAction')
1919
->with($this->equalTo('SIPPeers'), $this->equalTo(array()))
20-
->will($this->returnValue(new Action('SIPPeers', array('ActionID' => '123'))));
20+
->will($this->returnValue(new Action(array('Action' => 'SIPPeers', 'ActionID' => '123'))));
2121

2222
$collector = new Collector($client);
2323

@@ -35,12 +35,12 @@ public function testCollectingSIPEvents()
3535
$response = new Response(array('Response' => 'Success', 'ActionID' => '123'));
3636

3737
$client->handleMessage($response);
38-
$client->handleMessage(new Event('PeerEntry', array('ActionID' => '123')));
39-
$client->handleMessage(new Event('PeerEntry', array('ActionID' => '123')));
38+
$client->handleMessage(new Event(array('Event' => 'PeerEntry', 'ActionID' => '123')));
39+
$client->handleMessage(new Event(array('Event' => 'PeerEntry', 'ActionID' => '123')));
4040

4141
$this->assertNull($resolved);
4242

43-
$client->handleMessage(new Event('PeerlistComplete', array('EventList' => 'complete', 'ListItems' => '2', 'ActionID' => '123')));
43+
$client->handleMessage(new Event(array('Event' => 'PeerlistComplete', 'EventList' => 'complete', 'ListItems' => '2', 'ActionID' => '123')));
4444

4545
$this->assertNotNull($resolved);
4646

tests/Protocol/ActionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ class ActionTest extends TestCase
66
{
77
public function testIdDefaultsToNull()
88
{
9-
$action = new Action('name');
9+
$action = new Action();
1010

1111
$this->assertNull($action->getActionId());
1212
}
1313

1414
public function testIdCanBeSet()
1515
{
16-
$action = new Action('name', array('ActionID' => '123'));
16+
$action = new Action(array('ActionID' => '123'));
1717

1818
$this->assertEquals('123', $action->getActionId());
1919
}
2020

2121
public function testSerializeSimple()
2222
{
23-
$action = new Action('name');
23+
$action = new Action(array('Action' => 'name'));
2424

2525
$this->assertEquals("Action: name\r\n\r\n", $action->getMessageSerialized());
2626
}
2727

2828
public function testSerializeKeySingle()
2929
{
30-
$action = new Action('name', array('Key' => 'Value'));
30+
$action = new Action(array('Action' => 'name', 'Key' => 'Value'));
3131

3232
$this->assertEquals("Action: name\r\nKey: Value\r\n\r\n", $action->getMessageSerialized());
3333
}
3434

3535
public function testSerializeKeyMultipleValues()
3636
{
37-
$action = new Action('name', array('Key' => array('Value1', 'Value2')));
37+
$action = new Action(array('Action' => 'name', 'Key' => array('Value1', 'Value2')));
3838

3939
$this->assertEquals("Action: name\r\nKey: Value1\r\nKey: Value2\r\n\r\n", $action->getMessageSerialized());
4040
}
4141

4242
public function testSerializeKeyMultipleKeyValues()
4343
{
44-
$action = new Action('name', array('Variables' => array('first' => 'on', 'second' => 'off')));
44+
$action = new Action(array('Action' => 'name', 'Variables' => array('first' => 'on', 'second' => 'off')));
4545

4646
$this->assertEquals("Action: name\r\nVariables: first=on\r\nVariables: second=off\r\n\r\n", $action->getMessageSerialized());
4747
}

0 commit comments

Comments
 (0)