Skip to content

Commit

Permalink
fix trunk configuration setters/getters bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fivell authored and gigorok committed Jan 4, 2019
1 parent 1310ad7 commit 4dbdac8
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Item/Configuration/Base.php
Expand Up @@ -4,7 +4,7 @@

abstract class Base implements \Swis\JsonApi\Client\Interfaces\DataInterface
{
private $attributes = [];
protected $attributes = [];

abstract protected function getType();

Expand Down
2 changes: 1 addition & 1 deletion src/Item/Configuration/H323.php
Expand Up @@ -16,7 +16,7 @@ public function getHost()

public function getPort()
{
return $this->attributes['host'];
return $this->attributes['port'];
}

public function getCodecIds()
Expand Down
2 changes: 1 addition & 1 deletion src/Item/Configuration/Iax2.php
Expand Up @@ -16,7 +16,7 @@ public function getHost()

public function getPort()
{
return $this->attributes['host'];
return $this->attributes['port'];
}

public function getCodecIds()
Expand Down
2 changes: 1 addition & 1 deletion src/Item/Configuration/Pstn.php
Expand Up @@ -6,7 +6,7 @@ class Pstn extends Base
{
public function getDst()
{
$this->attributes['dst'] = $newDst;
return $this->attributes['dst'];
}

public function setDst($newDst)
Expand Down
20 changes: 15 additions & 5 deletions src/Item/Configuration/Sip.php
Expand Up @@ -135,8 +135,18 @@ public function getMax30xRedirects()
return $this->attributes['max_30x_redirects'];
}

public function getHost()
{
return $this->attributes['host'];
}

//##

public function setHost($newHost)
{
$this->attributes['host'] = $newHost;
}

public function setUsername($newUserName)
{
$this->attributes['username'] = $newUserName;
Expand Down Expand Up @@ -197,6 +207,11 @@ public function setSstEnabled($newSstEnabled)
$this->attributes['sst_enabled'] = $newSstEnabled;
}

public function setSstRefreshMethodId($newSstRefreshMethodId)
{
$this->attributes['sst_refresh_method_id'] = $newSstRefreshMethodId;
}

public function setSstMinTimer($newSstMinTimer)
{
$this->attributes['sst_min_timer'] = $newSstMinTimer;
Expand Down Expand Up @@ -242,11 +257,6 @@ public function setSstSessionExpires($newSstSessionExpires)
$this->attributes['sst_session_expires'] = $newSstSessionExpires;
}

public function setSstRefreshMethodId($newSstRefreshMethodId)
{
$this->attributes['sst_refresh_method_id'] = $newSstRefreshMethodId;
}

public function setTransportProtocolId($newTransportProtocolId)
{
$this->attributes['transport_protocol_id'] = $newTransportProtocolId;
Expand Down
86 changes: 60 additions & 26 deletions tests/TrunkTest.php
Expand Up @@ -43,11 +43,23 @@ public function testCreateH323Trunk()
$trunk = new \Didww\Item\Trunk($attributes);
$trunkDocument = $trunk->save();
$trunk = $trunkDocument->getData();

$h323Configuration = $trunk->getConfiguration();
$this->assertInstanceOf('Didww\Item\Configuration\H323', $h323Configuration);

$this->assertEquals($attributes['configuration']->getAttributes(), $h323Configuration->getAttributes());

$this->assertEquals(4569, $h323Configuration->getPort());

$this->assertEquals('558540420024', $h323Configuration->getDst());
$this->assertEquals('example.com', $h323Configuration->getHost());
$this->assertEquals(\Didww\Item\Configuration\Base::getDefaultCodecIds(), $h323Configuration->getCodecIds());

$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\H323', $trunk->getConfiguration());
$this->assertEquals('78146511-7648-45ba-9b26-a4b2cf87db06', $trunk->getId());
$this->assertEquals($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$this->assertEquals($attributes['name'], $trunk->getName());
$this->stopVCR();
}

Expand All @@ -67,7 +79,7 @@ public function testUpdateH323Trunk()
$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\H323', $trunk->getConfiguration());
$this->assertArraySubset($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$this->assertEquals($attributes['name'], $trunk->getName());
$this->stopVCR();
}

Expand All @@ -89,10 +101,21 @@ public function testCreateIax2Trunk()
$trunkDocument = $trunk->save();
$trunk = $trunkDocument->getData();
$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\Iax2', $trunk->getConfiguration());
$this->assertEquals('2021b895-52c9-4f65-990b-e57a1abf858d', $trunk->getId());
$this->assertEquals($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$this->assertEquals($attributes['name'], $trunk->getName());

$iaxConfiguration = $trunk->getConfiguration();
$this->assertInstanceOf('Didww\Item\Configuration\Iax2', $iaxConfiguration);

$this->assertEquals($attributes['configuration']->getAttributes(), $iaxConfiguration->getAttributes());

$this->assertEquals(4569, $iaxConfiguration->getPort());
$this->assertEquals('auth_user', $iaxConfiguration->getAuthUser());
$this->assertEquals('auth_password', $iaxConfiguration->getAuthPassword());
$this->assertEquals('558540420024', $iaxConfiguration->getDst());
$this->assertEquals('example.com', $iaxConfiguration->getHost());
$this->assertEquals(\Didww\Item\Configuration\Base::getDefaultCodecIds(), $iaxConfiguration->getCodecIds());

$this->stopVCR();
}

Expand All @@ -111,9 +134,10 @@ public function testUpdateIaxTrunk()
$trunkDocument = $trunk->save();
$trunk = $trunkDocument->getData();
$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\Iax2', $trunk->getConfiguration());
$this->assertArraySubset($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$iaxConfiguration = $trunk->getConfiguration();
$this->assertInstanceOf('Didww\Item\Configuration\Iax2', $iaxConfiguration);
$this->assertArraySubset($attributes['configuration']->getAttributes(), $iaxConfiguration->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getName());
$this->stopVCR();
}

Expand All @@ -133,7 +157,7 @@ public function testCreatePstnTrunk()
$this->assertInstanceOf('Didww\Item\Configuration\Pstn', $trunk->getConfiguration());
$this->assertEquals('41b94706-325e-4704-a433-d65105758836', $trunk->getId());
$this->assertEquals($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$this->assertEquals($attributes['name'], $trunk->getName());
$this->stopVCR();
}

Expand All @@ -151,32 +175,42 @@ public function testUpdatePstnTrunk()
$trunk = $trunkDocument->getData();
$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\Pstn', $trunk->getConfiguration());
$this->assertEquals($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$this->assertEquals('558540420025', $trunk->getConfiguration()->getDst());
$this->assertEquals($attributes['name'], $trunk->getName());
$this->stopVCR();
}

public function testCreateSipTrunk()
{
$this->startVCR('trunks.yml');
$attributes = [
'configuration' => new \Didww\Item\Configuration\Sip([
'username' => 'username',
'host' => '216.58.215.110',
'sst_refresh_method_id' => 1,
'port' => 5060,
'codec_ids' => \Didww\Item\Configuration\Base::getDefaultCodecIds(),
'rerouting_disconnect_code_ids' => \Didww\Item\Configuration\Base::getDefaultReroutingDisconnectCodeIds(),
]),
'name' => 'hello, test sip trunk',
];
'configuration' => new \Didww\Item\Configuration\Sip([
'username' => 'username',
'host' => '216.58.215.110',
'sst_refresh_method_id' => 1,
'port' => 5060,
'codec_ids' => \Didww\Item\Configuration\Base::getDefaultCodecIds(),
'rerouting_disconnect_code_ids' => \Didww\Item\Configuration\Base::getDefaultReroutingDisconnectCodeIds(),
]),
'name' => 'hello, test sip trunk',
];
$trunk = new \Didww\Item\Trunk($attributes);
$trunkDocument = $trunk->save();
$trunk = $trunkDocument->getData();
$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\Sip', $trunk->getConfiguration());
$this->assertArraySubset($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);

$sipConfiguration = $trunk->getConfiguration();

$this->assertInstanceOf('Didww\Item\Configuration\Sip', $sipConfiguration);
$this->assertArraySubset($attributes['configuration']->getAttributes(), $sipConfiguration->getAttributes());

$this->assertEquals('216.58.215.110', $sipConfiguration->getHost());
$this->assertEquals(1, $sipConfiguration->getSstRefreshMethodId());
$this->assertEquals(5060, $sipConfiguration->getPort());
$this->assertEquals(\Didww\Item\Configuration\Base::getDefaultCodecIds(), $sipConfiguration->getCodecIds());
$this->assertEquals(\Didww\Item\Configuration\Base::getDefaultReroutingDisconnectCodeIds(), $sipConfiguration->getReroutingDisconnectCodeIds());
$this->assertEquals('username', $sipConfiguration->getUsername());
$this->assertEquals($attributes['name'], $trunk->getName());
$this->stopVCR();
}

Expand All @@ -197,8 +231,8 @@ public function testUpdateSipTrunk()
$this->assertInstanceOf('Didww\Item\Trunk', $trunk);
$this->assertInstanceOf('Didww\Item\Configuration\Sip', $trunk->getConfiguration());
$this->assertArraySubset($attributes['configuration']->getAttributes(), $trunk->getConfiguration()->getAttributes());
$this->assertEquals($attributes['name'], $trunk->getAttributes()['name']);
$this->assertEquals($attributes['description'], $trunk->getAttributes()['description']);
$this->assertEquals($attributes['name'], $trunk->getName());
$this->assertEquals($attributes['description'], $trunk->getDescription());
$this->stopVCR();
}

Expand Down

0 comments on commit 4dbdac8

Please sign in to comment.