From f14dad332e5e097c591d254973a8890fe77542f4 Mon Sep 17 00:00:00 2001 From: Jeferson Daniel Date: Thu, 16 Nov 2017 10:23:14 -0200 Subject: [PATCH] Adding channel variables support on mocked client --- src/PAGI/Client/Impl/MockedClientImpl.php | 12 +++++++- test/mock/Test_Mock.php | 36 +++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/PAGI/Client/Impl/MockedClientImpl.php b/src/PAGI/Client/Impl/MockedClientImpl.php index d0a7ece..07852b8 100644 --- a/src/PAGI/Client/Impl/MockedClientImpl.php +++ b/src/PAGI/Client/Impl/MockedClientImpl.php @@ -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']; diff --git a/test/mock/Test_Mock.php b/test/mock/Test_Mock.php index cc61d1c..8f086b5 100644 --- a/test/mock/Test_Mock.php +++ b/test/mock/Test_Mock.php @@ -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)); } } \ No newline at end of file