|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace VonageTest\Voice\VoiceObjects; |
| 4 | + |
| 5 | +use InvalidArgumentException; |
| 6 | +use OutOfBoundsException; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Vonage\Voice\VoiceObjects\AdvancedMachineDetection; |
| 9 | + |
| 10 | +class AdvancedMachineDetectionTest extends TestCase |
| 11 | +{ |
| 12 | + public function testValidConstructor() |
| 13 | + { |
| 14 | + $amd = new AdvancedMachineDetection('continue', 60, 'detect'); |
| 15 | + $this->assertInstanceOf(AdvancedMachineDetection::class, $amd); |
| 16 | + } |
| 17 | + |
| 18 | + public function testInvalidBehaviour() |
| 19 | + { |
| 20 | + $this->expectException(InvalidArgumentException::class); |
| 21 | + new AdvancedMachineDetection('invalid_behaviour', 60, 'detect'); |
| 22 | + } |
| 23 | + |
| 24 | + public function testInvalidMode() |
| 25 | + { |
| 26 | + $this->expectException(InvalidArgumentException::class); |
| 27 | + new AdvancedMachineDetection('continue', 60, 'invalid_mode'); |
| 28 | + } |
| 29 | + |
| 30 | + public function testInvalidBeepTimeout() |
| 31 | + { |
| 32 | + $this->expectException(OutOfBoundsException::class); |
| 33 | + new AdvancedMachineDetection('continue', 150, 'detect'); |
| 34 | + } |
| 35 | + |
| 36 | + public function testValidBeepTimeoutRange() |
| 37 | + { |
| 38 | + $amd = new AdvancedMachineDetection('hangup', 100, 'detect_beep'); |
| 39 | + $this->assertEquals(100, $amd->toArray()['beep_timeout']); |
| 40 | + } |
| 41 | + |
| 42 | + public function testWillRenderDefault() |
| 43 | + { |
| 44 | + $amd = new AdvancedMachineDetection('hangup', 100, 'default'); |
| 45 | + $this->assertEquals('default', $amd->toArray()['mode']); |
| 46 | + } |
| 47 | + |
| 48 | + public function testToArray() |
| 49 | + { |
| 50 | + $amd = new AdvancedMachineDetection('continue', 45, 'detect'); |
| 51 | + $expected = [ |
| 52 | + 'behavior' => 'continue', |
| 53 | + 'mode' => 'detect', |
| 54 | + 'beep_timeout' => 45 |
| 55 | + ]; |
| 56 | + |
| 57 | + $this->assertEquals($expected, $amd->toArray()); |
| 58 | + } |
| 59 | + |
| 60 | + public function testFromArrayValid() |
| 61 | + { |
| 62 | + $data = [ |
| 63 | + 'behaviour' => 'hangup', |
| 64 | + 'mode' => 'detect_beep', |
| 65 | + 'beep_timeout' => 60 |
| 66 | + ]; |
| 67 | + |
| 68 | + $amd = (new AdvancedMachineDetection('continue', 45))->fromArray($data); |
| 69 | + $this->assertEquals('hangup', $amd->toArray()['behavior']); |
| 70 | + $this->assertEquals('detect_beep', $amd->toArray()['mode']); |
| 71 | + $this->assertEquals(60, $amd->toArray()['beep_timeout']); |
| 72 | + } |
| 73 | + |
| 74 | + public function testFromArrayInvalidData() |
| 75 | + { |
| 76 | + $this->expectException(InvalidArgumentException::class); |
| 77 | + |
| 78 | + $data = [ |
| 79 | + 'behaviour' => 'invalid_behaviour', |
| 80 | + 'mode' => 'detect', |
| 81 | + 'beep_timeout' => 60 |
| 82 | + ]; |
| 83 | + |
| 84 | + (new AdvancedMachineDetection('continue', 45))->fromArray($data); |
| 85 | + } |
| 86 | +} |
0 commit comments