Skip to content

Commit

Permalink
tests: updated unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Dec 13, 2024
1 parent 2c3fc4f commit 9a1e3a8
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace spec\Ivoz\Provider\Domain\Service\MediaRelaySet;

use Ivoz\Core\Domain\Service\LifecycleEventHandlerInterface;
use Ivoz\Kam\Domain\Service\TrunksClientInterface;
use Ivoz\Provider\Domain\Model\MediaRelaySet\MediaRelaySet;
use Ivoz\Provider\Domain\Model\MediaRelaySet\MediaRelaySetInterface;
use Ivoz\Provider\Domain\Service\MediaRelaySet\MediaRelaySetEventHandlerInterface;
use Ivoz\Provider\Domain\Service\MediaRelaySet\SendTrunksRtpengineReloadRequest;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\ObjectBehavior;
use spec\HelperTrait;

class SendTrunksRtpengineReloadRequestSpec extends ObjectBehavior
{
use HelperTrait;

protected $trunksCient;

public function let()
{
$this->trunksCient = $this->getTestDouble(TrunksClientInterface::class);

$this->beConstructedWith(
$this->trunksCient
);
}

function it_is_initializable()
{
$this->shouldHaveType(SendTrunksRtpengineReloadRequest::class);
}

function it_should_be_on_commit_lifecycle_service()
{
$this->shouldBeAnInstanceOf(
MediaRelaySetEventHandlerInterface::class
);

$binding = SendTrunksRtpengineReloadRequest::getSubscribedEvents();

if ($binding != [LifecycleEventHandlerInterface::EVENT_ON_COMMIT => 300]) {
throw new FailureException('On commit binding expected');
}
}

function it_sends_rtpengine_reload_request()
{
$mediaRelaySet = $this->getTestDouble(MediaRelaySetInterface::class);
$this->prepareExecution($mediaRelaySet);

$this
->trunksCient
->reloadRtpengine()
->will(function () {
})
->shouldBeCalled();

$this->execute($mediaRelaySet->reveal());
}

function it_requires_hasBeenDeleted_to_be_true()
{
$mediaRelaySet = $this->getTestDouble(MediaRelaySetInterface::class);
$this->prepareExecution($mediaRelaySet);

$this
->trunksCient
->reloadRtpengine()
->will(function () {
})
->shouldBeCalled();

$this->execute($mediaRelaySet->reveal());
}

private function prepareExecution($mediaRelaySet)
{
$this->getterProphecy(
$mediaRelaySet,
[
'getId' => 1,
'hasBeenDeleted' => true
],
false
);

$this->fluentSetterProphecy(
$this->trunksCient,
[
],
false
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace spec\Ivoz\Provider\Domain\Service\MediaRelaySet;

use Ivoz\Core\Domain\Service\LifecycleEventHandlerInterface;
use Ivoz\Kam\Domain\Service\UsersClientInterface;
use Ivoz\Provider\Domain\Model\MediaRelaySet\MediaRelaySetInterface;
use Ivoz\Provider\Domain\Service\MediaRelaySet\MediaRelaySetEventHandlerInterface;
use Ivoz\Provider\Domain\Service\MediaRelaySet\SendUsersRtpengineReloadRequest;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\ObjectBehavior;
use spec\HelperTrait;

class SendUsersRtpengineReloadRequestSpec extends ObjectBehavior
{
use HelperTrait;

protected $usersClient;

public function let()
{
$this->usersClient = $this->getTestDouble(UsersClientInterface::class);

$this->beConstructedWith(
$this->usersClient
);
}

function it_is_initializable()
{
$this->shouldHaveType(SendUsersRtpengineReloadRequest::class);
}

function it_should_be_on_commit_lifecycle_service()
{
$this->shouldBeAnInstanceOf(
MediaRelaySetEventHandlerInterface::class
);

$binding = SendUsersRtpengineReloadRequest::getSubscribedEvents();

if ($binding != [LifecycleEventHandlerInterface::EVENT_ON_COMMIT => 300]) {
throw new FailureException('On commit binding expected');
}
}

function it_sends_rtpengine_reload_request()
{
$mediaRelaySet = $this->getTestDouble(MediaRelaySetInterface::class);
$this->prepareExecution($mediaRelaySet);

$this
->usersClient
->reloadRtpengine()
->will(function () {
})
->shouldBeCalled();

$this->execute($mediaRelaySet->reveal());
}

function it_requires_hasBeenDeleted_to_be_true()
{
$mediaRelaySet = $this->getTestDouble(MediaRelaySetInterface::class);
$this->prepareExecution($mediaRelaySet);

$this
->usersClient
->reloadRtpengine()
->will(function () {
})
->shouldBeCalled();

$this->execute($mediaRelaySet->reveal());
}

private function prepareExecution($mediaRelaySet)
{
$this->getterProphecy(
$mediaRelaySet,
[
'getId' => 1,
'hasBeenDeleted' => true
],
false
);

$this->fluentSetterProphecy(
$this->usersClient,
[
],
false
);
}
}

0 comments on commit 9a1e3a8

Please sign in to comment.