Skip to content

Commit

Permalink
added test for advanced machine detection
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Sep 12, 2024
1 parent 1167fa4 commit 6d5a7dd
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions test/Voice/VoiceObjects/AdvancedMachineDetectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace VonageTest\Voice\VoiceObjects;

use InvalidArgumentException;
use OutOfBoundsException;
use PHPUnit\Framework\TestCase;
use Vonage\Voice\VoiceObjects\AdvancedMachineDetection;

class AdvancedMachineDetectionTest extends TestCase
{
public function testValidConstructor()
{
$amd = new AdvancedMachineDetection('continue', 60, 'detect');
$this->assertInstanceOf(AdvancedMachineDetection::class, $amd);
}

public function testInvalidBehaviour()
{
$this->expectException(InvalidArgumentException::class);
new AdvancedMachineDetection('invalid_behaviour', 60, 'detect');
}

public function testInvalidMode()
{
$this->expectException(InvalidArgumentException::class);
new AdvancedMachineDetection('continue', 60, 'invalid_mode');
}

public function testInvalidBeepTimeout()
{
$this->expectException(OutOfBoundsException::class);
new AdvancedMachineDetection('continue', 150, 'detect');
}

public function testValidBeepTimeoutRange()
{
$amd = new AdvancedMachineDetection('hangup', 100, 'detect_beep');
$this->assertEquals(100, $amd->toArray()['beep_timeout']);
}

public function testWillRenderDefault()
{
$amd = new AdvancedMachineDetection('hangup', 100, 'default');
$this->assertEquals('default', $amd->toArray()['default']);

Check failure on line 45 in test/Voice/VoiceObjects/AdvancedMachineDetectionTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 Test

Failed asserting that null matches expected 'default'.

Check failure on line 45 in test/Voice/VoiceObjects/AdvancedMachineDetectionTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 Test

Failed asserting that null matches expected 'default'.

Check failure on line 45 in test/Voice/VoiceObjects/AdvancedMachineDetectionTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test

Failed asserting that null matches expected 'default'.
}

public function testToArray()
{
$amd = new AdvancedMachineDetection('continue', 45, 'detect');
$expected = [
'behavior' => 'continue',
'mode' => 'detect',
'beep_timeout' => 45
];

$this->assertEquals($expected, $amd->toArray());
}

public function testFromArrayValid()
{
$data = [
'behaviour' => 'hangup',
'mode' => 'detect_beep',
'beep_timeout' => 60
];

$amd = (new AdvancedMachineDetection('continue', 45))->fromArray($data);
$this->assertEquals('hangup', $amd->toArray()['behavior']);
$this->assertEquals('detect_beep', $amd->toArray()['mode']);
$this->assertEquals(60, $amd->toArray()['beep_timeout']);
}

public function testFromArrayInvalidData()
{
$this->expectException(InvalidArgumentException::class);

$data = [
'behaviour' => 'invalid_behaviour',
'mode' => 'detect',
'beep_timeout' => 60
];

(new AdvancedMachineDetection('continue', 45))->fromArray($data);
}
}

0 comments on commit 6d5a7dd

Please sign in to comment.