Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding channel variables support on mocked client #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/PAGI/Client/Impl/MockedClientImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,17 @@ public function __construct(array $options = array())
{
$this->_logger = new NullLogger;
if (isset($options['variables'])) {
$this->_variables = $options['variables'];
$this->variables = $options['variables'];
foreach ($this->variables as $variableName => $variableValue) {
if (strpos($variableName, 'arg_') !== 0) {
continue;
}
$number = substr($variableName, 4);
if (! is_numeric($number)) {
continue;
}
$this->arguments[$number] = $variableValue;
}
}
if (isset($options['resultStrings'])) {
$this->mockedResultStrings = $options['resultStrings'];
Expand Down
36 changes: 36 additions & 0 deletions test/mock/Test_Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,42 @@ public function can_get_knownmocked_node()
$mock = new PAGI\Client\Impl\MockedClientImpl($this->_properties);
$mock->onCreateNode('test')->runWithInput('*');
$this->assertTrue($mock->createNode('test') instanceof MockedNode);
}

/**
* @test
*/
public function can_get_channel_variables()
{
$mock = new PAGI\Client\Impl\MockedClientImpl([
'variables' => [
'request' => 'request.php',
'channel' => 'SIP/blah-00803890',
'language' => 'ar',
'type' => 'SIP',
'uniqueid' => '1330012581.77',
'version' => '1.6.0.9',
'callerid' => '40',
'calleridname' => 'Admin',
'callingpres' => '1',
'callingani2' => '0',
'callington' => '0',
'callingtns' => '0',
'dnid' => '55555555',
'rdnis' => 'unknown',
'context' => 'default',
'extension' => '55555555',
'priority' => '1',
'enhanced' => '0.0',
'accountcode' => '',
'threadid' => '1095317840',
'arg_1' => 'First',
'arg_2' => 'Second',
]
]);
$channelVariables = $mock->getChannelVariables();
$this->assertEquals('SIP/blah-00803890', $channelVariables->getChannel());
$this->assertEquals('First', $channelVariables->getArgument(1));
$this->assertEquals('Second', $channelVariables->getArgument(2));
}
}